Guest mode. You can read posts without signing up. Comments, ratings, job contacts and your own posts open after you sign up and accept the rules. What is Kommit →

📚 Guide1С: практика разработчикаПроизводительность · часть 2 из 3
Guide contents
Производительность
  1. 1С на практике: как ускорить запросы — 10 правил и как найти медленный запрос
Редакция КоммитРедакция портала
commit 58528c9 · 19 days ago

1C in practice: how to speed up queries — 10 rules and how to find a slow query

🌐 Machine-translated from Russian. Show original

In this part:

First, find what is holding you back#

Do not optimize blindly. Tools:

  • Performance measurement (Configurator → Debugging → Performance measurement) — which lines of code consume time.
  • Technological log with DBPOSTGRS / DBMSSQL events and duration threshold — which DBMS requests are long.
  • Query plan in DBMS (EXPLAIN in PostgreSQL, execution plan in MS SQL) — why the query is slow.

10 rules for quick queries#

  1. Do not run a query in a loop. Collect all keys and get data with a single query.
  2. Do not access details through a dot in the code (Документ.Контрагент.ИНН) in the loop — each request can be a separate query. Get the required fields in the query.
  3. Use virtual table parameters: the selection condition is in the Остатки(&Дата, Номенклатура В (&Список))parameters, not ГДЕ after the table.
  4. Temporary tables with an index instead of subqueries in joins: ПОМЕСТИТЬ ВТТовары ... ИНДЕКСИРОВАТЬ ПО Номенклатура.
  5. Do not connect to subqueries — the DBMS optimizer often builds a poor plan for such designs.
  6. Avoid OR in connection conditions and in WHERE by different fields — break it down into COMBINE ALL.
  7. Conditions for indexed fields: selection by attribute that is not indexed — full table view. Add an index to the attribute if the selection is frequent.
  8. EXPRESS for composite types: accessing a composite type field without EXPRESSING generates joins with all possible tables.
  9. Select only the required fields and limit sampling (ПЕРВЫЕ N) where possible.
  10. ALLOWED and RLS: record-level access restrictions complicate queries. Test performance under the user with restrictions, not just under the administrator.

Example: a query in a loop → a single query#

Was — query for each line:

Для Каждого Строка Из Товары Цикл
    Запрос = Новый Запрос("ВЫБРАТЬ Цена ИЗ РегистрСведений.Цены.СрезПоследних(, Номенклатура = &Н)");
    Запрос.УстановитьПараметр("Н", Строка.Номенклатура);
    // ...
КонецЦикла;

It became — one query for all lines:

Запрос = Новый Запрос(
"ВЫБРАТЬ
|   Цены.Номенклатура,
|   Цены.Цена
|ИЗ
|   РегистрСведений.Цены.СрезПоследних(, Номенклатура В (&Список)) КАК Цены");
Запрос.УстановитьПараметр("Список", Товары.ВыгрузитьКолонку("Номенклатура"));
Цены = Запрос.Выполнить().Выгрузить();
Цены.Индексы.Добавить("Номенклатура");

When it's not about the query#

  • Locks: long transactions hold locks, others wait. Look for events TLOCK, TTIMEOUT, TDEADLOCKin the TJ.
  • DBMS statistics are outdated — the query plan is becoming poor. Regular statistics updates are part of the regulations.
  • Server disk and memory — see the section about maintenance in the "1C Server" series.
Comments 01 участник · 0 гостей🔒 Rate and discuss after signing up

Comments · 0

No comments yet.Sign in to comment, rate and see all comments.