Optimizing SQL queries through 1C-Bitrix EXPLAIN analysis

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

SQL Query Optimization via EXPLAIN Analysis in 1C-Bitrix

EXPLAIN is a MySQL command that shows the query execution plan: which tables are scanned, whether indexes are used, how many rows are processed. It's the primary tool after discovering a slow query in slow query log.

How to Read EXPLAIN

EXPLAIN SELECT * FROM b_iblock_element
WHERE IBLOCK_ID = 5 AND ACTIVE = 'Y'
ORDER BY SORT;

Key output columns:

Column What to Look For
type ALL = full scan (bad), ref/range/const = uses index
key Which index optimizer chose, NULL = no index
rows Estimate of rows to examine. 100,000+ on simple selection — problem
Extra Using filesort = memory/disk sort. Using temporary = temporary table

EXPLAIN ANALYZE (MySQL 8.0+, MariaDB 10.9+) executes the query and shows real time:

EXPLAIN ANALYZE SELECT ...;

Characteristic Bitrix Problems

Using filesort on b_iblock_element. Query sorts by SORT, but index doesn't cover combination (IBLOCK_ID, ACTIVE, SORT). Solution: composite index:

ALTER TABLE b_iblock_element
ADD INDEX ix_iblock_active_sort (IBLOCK_ID, ACTIVE, SORT);

rows = 500,000 on query to b_iblock_element_property. Filtering by property value without index on (IBLOCK_PROPERTY_ID, VALUE). For VARCHAR field VALUE — index by prefix VALUE(64).

Using temporary on GROUP BY. Occurs in faceted filter queries. Bitrix facet builds optimized tables b_iblock_find_* — if not rebuilt after adding properties, queries bypass them.

Workflow

  1. Get slow query from slow query log or Bitrix SQL tracker
  2. Run EXPLAIN — find type=ALL or rows > 10,000 on point selection
  3. Identify missing index or inefficient JOIN
  4. Add index, repeat EXPLAIN — ensure type changed
  5. Check real time on production data

After adding index, MySQL might not use it — if table statistics are stale, run ANALYZE TABLE b_iblock_element to recalculate.