magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.44k stars 9.29k forks source link

Catalog fulltext search performance #36408

Open p24-max opened 1 year ago

p24-max commented 1 year ago

Preconditions and environment

Steps to reproduce

Expected result

Backend product catalog fulltext search is faster when working with more products

Actual result

Fulltext search in catalog > products executes for ~3 seconds which is annoying when working with it whole day

Additional information

Example of improved query (lacks match of joined t2.value, this should be extracted into single query or UNION without join for performance reasons. Multiple MATCH AGAINST in single query slows down a lot):

SELECT DISTINCT `e`.`entity_id`
FROM `catalog_product_entity` AS `e`
WHERE (`e`.`entity_id` IN (SELECT `catalog_product_entity`.`entity_id`
                           FROM `catalog_product_entity`
                           WHERE (`sku` LIKE '%my search string%')
                           UNION ALL
                           SELECT `t1`.`entity_id`
                           FROM `catalog_product_entity_varchar` AS `t1`
                                    LEFT JOIN `catalog_product_entity_varchar` AS `t2`
                                              ON t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id
                           WHERE (t1.attribute_id IN (151, 187, 84, 73))
                             AND (t1.store_id = 0)
                             AND MATCH (t1.value) AGAINST ('my search string')
                           UNION ALL
                           SELECT `t1`.`entity_id`
                           FROM `catalog_product_entity_text` AS `t1`
                                    LEFT JOIN `catalog_product_entity_text` AS `t2`
                                              ON t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id
                           WHERE (t1.attribute_id IN (75, 85))
                             AND (t1.store_id = 0)
                             AND MATCH (t1.value) AGAINST ('my search string')));

Execution time: 90ms (vs. 663ms current implementation)

Release note

Improved catalog products fulltext search performance

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @p24-max. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 1 year ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 1 year ago

Hi @p24-max , Thank you for reporting and collaboration. Verified the behavior on Magento 2.4-develop instance with 30k products and mysql slow query log enabled. The Fulltext search in catalog > products executes for 2 to 3 seconds. We are considering this as feature request to improve the performance as this is existing behavior of Magento. Thank you.

p24-max commented 8 months ago

@engcom-November any news?