framework_eng/skills/bsl-practices/query-optimize/SKILL.md
For optimizing slow 1C queries and DCS datasets
npx skillsauth add steelmorgan/1c-agent-based-dev-framework query-optimizeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A skill for optimizing existing queries and data composition schemas. For writing queries from scratch, use query-patterns. For DBMS diagnostics (plan, locks, evidence), use db-performance.
db-performance ← lower evidence layer (DBMS evidence, plan, locks)
↓ passes query + reason
query-optimize ← rewriting (this skill)
↓ uses writing rules
query-patterns ← basic patterns (parameterization, NULL, loops)
Without db-performance evidence, optimization is a guess. If the reason is unknown, start with db-performance.
rg "Запрос.Текст\s*=" --type-add "bsl:*.bsl" -t bsl.xml via code-navigation, determine the datasetBefore rewriting, check the metadata object structure:
Tool: code-navigation → object structure.
Choose from the categories (one per iteration):
| Reason | Sign |
|---------|---------|
| Broad virtual table read | Остатки() / Обороты() without period or dimension parameters |
| Query-in-loop | Query inside Для Каждого / Пока / recursion |
| Dot-dereference without ВЫРАЗИТЬ | Движения.Регистратор.Контрагент for a composite type |
| Excess temporary tables | Intermediate tables with the full field set instead of the minimum |
| Extra totals | ИТОГИ in a query when a flat result set is needed |
| Filtering after join | ГДЕ conditions on fields of a large table instead of virtual table parameters |
| Implicit row multiplication via JOIN | LEFT JOIN without aggregation duplicates rows |
| DISTINCT masks the problem | ВЫБРАТЬ РАЗЛИЧНЫЕ hides an extra JOIN instead of fixing it |
For each cause, use a specific rule (see the “Rules” section below).
v8-runner after any changeРАЗРЕШЕННЫЕ filters; security rules must remain intactIf the change affects the DBMS plan (index, virtual table parameters, join type), ask the user for EXPLAIN / ТЖ before and after. Without measurement, record it as “expected effect, requires verification”.
The concrete “how to write it correctly” rules are canonical in query-patterns. Here is the mapping from the cause (step 3) to the rule from query-patterns; apply the rule from there, do not duplicate query patterns in this skill.
| Cause (step 3) | query-patterns rule |
|---|---|
| Broad virtual table read | Rule 5 — put period/dimension parameters inside the virtual table, not in ГДЕ |
| Query-in-loop | Rule 1 — one query + Соответствие for access |
| Dot-dereference without ВЫРАЗИТЬ | Rule 12 — ВЫРАЗИТЬ(… КАК …) + ССЫЛКА for a composite type |
| Excessive temp tables / no join index | Rules 2, 8 — minimal fields, ИНДЕКСИРОВАТЬ ПО only on the join field |
| Redundant totals | Rule 16 — ИТОГИ only for Выбрать(ПоГруппировкам), otherwise СГРУППИРОВАТЬ ПО |
| Filtering after join | Rules 5, 13 — VT parameters / ПО vs ГДЕ |
| РАЗЛИЧНЫЕ masks an extra JOIN | Rule 11 — subquery В (…) instead of JOIN + РАЗЛИЧНЫЕ |
Optimization specifics (beyond the general query-patterns rules):
WHERE)INDEX BY)CAST before dot dereferenceLEFT JOIN does not turn into INNER JOIN because of a condition in WHEREDISTINCT does not mask an extra JOINALLOWED and other rights filters are preservedALLOWED without explicit security approval.db-performance.depends_on:
development
1C server maintenance webhooks: container restart and external component cache cleanup
development
Interactive DAP debugging of a single BSL procedure
tools
Rules for using RLM tools for project search and navigation in 1C/BSL
development
Creates web applications and routes on Winow (a web server on OneScript and Autumn). Use when working with a web server on OneScript, routing, or Winow controllers.