Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalog fulltext search performance #36408

Open
1 of 5 tasks
p24-max opened this issue Nov 2, 2022 · 4 comments
Open
1 of 5 tasks

Catalog fulltext search performance #36408

p24-max opened this issue Nov 2, 2022 · 4 comments

Comments

@p24-max
Copy link

p24-max commented Nov 2, 2022

Preconditions and environment

  • Magento version: 2.4.3-p3
  • MariaDB 10.3.34

Steps to reproduce

  • Enable mysql slow query log
  • Create or import a large number of products (~50.000) into your catalog
  • Open magento admin, navigate to catalog > Products
  • Type a phrase into the full text search field and press enter
  • Check slow query log, this query is logged:
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 phrase%')
                           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 (IFNULL(t2.value, t1.value) LIKE '%my search phrase%')
                           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 (IFNULL(t2.value, t1.value) LIKE '%my search phrase%')))

At my machine this query takes 663ms to execute

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

create fulltext index catalog_product_entity_varchar_value_index
             on catalog_product_entity_varchar (value);
create fulltext index catalog_product_entity_text_value_index
             on catalog_product_entity_text (value);
create fulltext index catalog_product_entity_sku_index
    on catalog_product_entity (sku);

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

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Nov 2, 2022

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

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

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.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 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.

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

@m2-assistant
Copy link

m2-assistant bot commented Nov 15, 2022

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: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-November
Copy link
Contributor

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
Copy link
Author

p24-max commented Dec 28, 2023

@engcom-November any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Feature Requests Backlog
  
Ready for Grooming
Development

No branches or pull requests

2 participants