ACSD-62577: Storefront search performance optimization
The ACSD-62577 patch fixes the issue with slow performance of storefront search queries by optimizing both query and table indexes. This patch is available with the Quality Patches Tool (QPT) 1.1.56. The patch ID is ACSD-62577. Please note that the issue was is scheduled to be fixed in Adobe Commerce 2.4.8.
Affected products and versions
The patch is created for Adobe Commerce version:
Adobe Commerce (all deployment methods) 2.4.6, 2.4.7-p2
Compatible with Adobe Commerce versions:
Adobe Commerce (all deployment methods) 2.4.4 - 2.4.7-p3
magento/quality-patches
package to the latest version and check the compatibility on the Quality Patches Tool: Search for patches page. Use the patch ID as a search keyword to locate the patch.Issue
Large search_query
tables significantly slow down storefront searches, increasing frontend response times due to inefficient queries and lack of optimized table indexes.
Steps to reproduce:
-
Set up Adobe Commerce Develop using the performance toolkit
small.xml
. -
Access the SQL command line and delete the
search_query
table using the following commands:code language-none SET FOREIGN_KEY_CHECKS = 0; DROP TABLE search_query; SET FOREIGN_KEY_CHECKS = 1;
-
Populate the
search_query
table with a large number of records, ex: 4 million records. -
Trigger reindexing and flush caches.
code language-none bin/magento indexer:reindex bin/magento c:c bin/magento c:f
-
Enable database debug logs:
code language-none bin/magento dev:query-log:enable
-
Search a term in the storefront search bar, e.g.,
http://your_magento_instance/default/catalogsearch/result/?q=test.
-
Check the
db.log
for the query execution time for the following SQL:code language-none SELECT COUNT(*) FROM ( SELECT DISTINCT `main_table`.`query_text` FROM `search_query` AS `main_table` WHERE (main_table.store_id IN (1)) AND (main_table.num_results > 0) ORDER BY `main_table`.`popularity` DESC LIMIT 100 ) AS `result` WHERE (result.query_text = 'test')
Expected results:
The query execution time is optimized, resulting in a less significant increase in response time when processing large search_query
tables.
Actual results:
The query execution time increases significantly due to inefficient handling of the large search_query
table:
TIME: 10.8520 seconds
Apply the patch
To apply individual patches, use the following links depending on your deployment method:
- Adobe Commerce or Magento Open Source on-premises: Quality Patches Tool > Usage in the Quality Patches Tool guide.
- Adobe Commerce on cloud infrastructure: Upgrades and Patches > Apply Patches in the Commerce on Cloud Infrastructure guide.
Related reading
To learn more about Quality Patches Tool, refer to:
- Quality Patches Tool: A self-service tool for quality patches in the Tools guide.