Slow query log analysis for 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Slow Query Log Analysis for 1C-Bitrix

Slow query log is a MySQL/MariaDB journal that records queries running longer than a specified threshold. It's the first diagnostic tool when a Bitrix site is slow but specific culprits are unknown.

Enabling and Configuration

In my.cnf (or my.ini on Windows):

[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 0.5
log_queries_not_using_indexes = 1
min_examined_row_limit = 100

long_query_time = 0.5 — queries over 500 ms. For active diagnostics set 0.1 or even 0. log_queries_not_using_indexes = 1 — catches queries without indexes regardless of time. min_examined_row_limit = 100 — don't log fast queries on small tables.

Enable without MySQL restart dynamically:

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 0.5;
SET GLOBAL log_queries_not_using_indexes = 1;

Analysis via mysqldumpslow and pt-query-digest

Raw logs are inconvenient to read. Use aggregation utilities:

mysqldumpslow — built into MySQL:

mysqldumpslow -s t -t 10 /var/log/mysql/slow.log

-s t — sort by total time, -t 10 — top 10 queries. Shows query template and total/average time.

pt-query-digest (Percona Toolkit) — significantly more informative: shows execution time percentiles, count of unique queries, server load.

What to Look for in Bitrix Logs

Typical slow query patterns in Bitrix:

  • SELECT ... FROM b_iblock_element WHERE IBLOCK_ID=N without index or with ORDER BY SORT without composite index
  • SELECT ... FROM b_iblock_element_property WHERE VALUE LIKE '%text%'LIKE with leading % doesn't use index
  • SELECT COUNT(*) FROM b_sale_order WHERE ... with millions of orders
  • Queries to b_search_content without FULLTEXT index during full-text search
  • Faceted index recreation (b_iblock_find_*) on every element change

After finding a specific problem query, next step is EXPLAIN, which shows which execution plan the optimizer chose and where to add an index.