Query optimize

From IngvarConsulting/unica · View interactive version

Query optimize is an AI agent skill from the GitHub repository IngvarConsulting/unica. Оптимизация запросов 1С и СКД. Используй когда нужно написать, проверить или ускорить запрос, СКД query, временные таблицы, виртуальные таблицы, отборы, соединения или проблемный SQL/DBMS trace.

How to use this skill

Skill file

Query Optimize

MCP routing

контракт каждой — argsSchema, execution, previewRequired,

dryRunRequired. Контракт вызова бери оттуда, а не из этого текста;

используй опубликованную argsSchema; при support.state: limited

разрешено только подмножество support.supportedArgs. Недоступной операции

в словаре нет. Для плановой операции сначала проверь результат

dryRun: true, затем исполняй запрос с dryRun: false. Preview

не фиксирует входы между вызовами. Не обходи контракт прямым runner-ом.

Workflow

  1. Extract the exact query text with unica.search or unica.view on the schema node.
  2. Inspect the execution context with unica.view on the module node (its Method branch lists the methods): module, exported entry point, region, temporary table chain, and caller loop.
  3. Find callers with unica.view at <method>.Caller when the query is inside reusable API, background jobs, event handlers, or suspected query-in-loop flow; unica.search by the method name adds literal mentions.
  4. Run unica.check {at} on the containing module when analyzer diagnostics can reveal unreachable code, unresolved calls, or type issues around the query. Do not pass a DCS TemplatePath as a diagnostic target; locate the BSL module that executes the query.
  5. Inspect unica.view on the object node for both related modules, subscriptions, roles, functional options and the local registers, dimensions, resources, реквизиты, tabular sections, and indexes implied by the platform object type.
  6. Inspect DCS with unica.view on the schema node when the query lives in a data composition schema.
  7. Search unica.docs with source: "development-standard" only for development-standard query rules. Exact platform query semantics require unica.docs with source: "platform-help" before a platform-dependent rewrite.
  8. Read ../../references/platform/db-performance.md when performance depends on DBMS behavior, locks, indexes, temp storage, WAL, TEMPDB, or large table statistics.
  9. Optimize one cause at a time: filters before joins, virtual table parameters, temporary table materialization, repeated queries in loops, dot dereference expansion, unbounded selections, and unnecessary totals.
  10. Check syntax with unica.check; require real trace/log evidence when performance depends on data volume.

DB-aware diagnostics

Query syntax guards

Если ТипЗнч(Количество) <> Тип("Число") Тогда
	ВызватьИсключение "Количество должно иметь тип Число";
КонецЕсли;

Если Количество <= 0 Или Цел(Количество) <> Количество Тогда
	ВызватьИсключение "Количество должно быть положительным целым числом";
КонецЕсли;

МаркерОграничения = "ПЕРВЫЕ 1" + Символы.ПС;

Если СтрЧислоВхождений(Запрос.Текст, МаркерОграничения) <> 1 Тогда
	ВызватьИсключение "В тексте запроса ожидается один маркер ограничения";
КонецЕсли;

Запрос.Текст = СтрЗаменить(
	Запрос.Текст,
	МаркерОграничения,
	"ПЕРВЫЕ " + Формат(Количество, "ЧГ=0") + Символы.ПС);

Review checklist

MCP examples

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "unica.view",
    "arguments": {
      "at": "main:Report.Продажи.Template.ОсновнаяСхемаКомпоновкиДанных.DataSet"
    }
  }
}
{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "unica.docs",
    "arguments": {
      "query": "оптимизация запросов 1С виртуальные таблицы",
      "source": "development-standard"
    }
  }
}
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.