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

Performance degradation in Layered navigation using Yes/No attribute #21771

Closed
stkec opened this issue Mar 15, 2019 · 3 comments
Closed

Performance degradation in Layered navigation using Yes/No attribute #21771

stkec opened this issue Mar 15, 2019 · 3 comments
Assignees
Labels
Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@stkec
Copy link
Contributor

stkec commented Mar 15, 2019

Relates to #20969 and #3283

Preconditions

  1. Magento 2.3.0 (2.3.1? any 2.x.x?)
  2. Percona SQL Server >= 5.6
  3. About 65 000 of products with about 50 attributes in 15 attribute sets
  4. Lots of filterable attributes for layered navigation
  5. Applied patch from [FEATURE] [issue-3283] Added Filter Support for Yes/No (boolean) attr… #17823
  6. Using Yes/No attribute in Layered navigation.
  7. Using MySql Search Engine (set in admin panel)

Steps to reproduce

  1. Set Yes/No Product attribute 'Filterable'
  2. Go to Anchor Category Page on frontend
  3. Try to apply filter by Yes/No attribute

Expected result

  1. Filter applied in reasonable time

Actual result (

  1. Request lasts for several hours.
  2. MySql eats lot of CPU freezing the site

Root of a problem

After #3283 merged it is possible to use Yes/No attributes in Layered Navigation. But when MySql engine assembles the SQL query there are 2 more places where FrontendInput of the Layered Navigation Attribute is hardcoded as ['select', 'multiselect']. As a result, Yes/No attribute processed not as a 'Term' condition as it suppose to be for Layered Attribute but as a default unknown condition. In the end search query assembled as following:

SELECT `main_select`.`entity_id`, SUM(score) AS `relevance` FROM (SELECT DISTINCT  `search_index`.`entity_id`, (((0) + (0) + (0)) * 1) AS `score` FROM `catalog_product_index_eav` AS `search_index`
 INNER JOIN `catalog_product_index_eav` AS `delivery_active_filter` ON `search_index`.`entity_id` = `delivery_active_filter`.`entity_id` AND `delivery_active_filter`.`attribute_id` = 549 AND `delivery_active_filter`.`store_id` = 1
 INNER JOIN `catalog_product_entity` AS `product` ON product.entity_id = search_index.entity_id AND (product.created_in <= '1522659288' AND product.updated_in > '1522659288')
 INNER JOIN `inventory_stock_44` AS `stock_index` ON stock_index.sku = product.sku
 INNER JOIN `catalog_product_entity` AS `sub_product` ON sub_product.entity_id = search_index.source_id AND (sub_product.created_in <= '1522659288' AND sub_product.updated_in > '1522659288')
 INNER JOIN `inventory_stock_44` AS `sub_product_stock_index` ON sub_product_stock_index.sku = sub_product.sku
 INNER JOIN `catalog_product_index_eav` AS `visibility_filter` ON search_index.entity_id = visibility_filter.entity_id AND `visibility_filter`.`attribute_id` = 99 AND `visibility_filter`.`value` in ('2', '4') AND `visibility_filter`.`store_id` = '1'
 INNER JOIN `catalog_category_product_index_store1` AS `category_ids_index` ON search_index.entity_id = category_ids_index.product_id AND category_ids_index.store_id = '1' WHERE (search_index.store_id = '1') AND (`search_index`.`attribute_id` = 549) AND (`search_index`.`value` in ('1')) AND (category_ids_index.category_id = 36799) AND (search_index.entity_id IN (
                select entity_id from  (SELECT `e`.`entity_id`, IFNULL(current_store.value, main_table.value) AS `delivery_active` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_entity_int` AS `main_table` ON main_table.row_id = e.row_id
 LEFT JOIN `catalog_product_entity_int` AS `current_store` ON current_store.attribute_id = main_table.attribute_id AND current_store.store_id = 1 WHERE ((main_table.attribute_id = '549') AND (main_table.store_id = 0)) AND (e.created_in <= '1522659288') AND (e.updated_in > '1522659288') HAVING (`delivery_active` IN ('1'))) as filter
            ))) AS `main_select` GROUP BY `entity_id` ORDER BY `relevance` DESC, `entity_id` DESC

Notice following in the 'WHERE' condition:

search_index.entity_id IN (
                select entity_id from  (SELECT `e`.`entity_id`, IFNULL(current_store.value, main_table.value) AS `delivery_active` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalog_product_entity_int` AS `main_table` ON main_table.row_id = e.row_id
 LEFT JOIN `catalog_product_entity_int` AS `current_store` ON current_store.attribute_id = main_table.attribute_id AND current_store.store_id = 1 WHERE ((main_table.attribute_id = '549') AND (main_table.store_id = 0)) AND (e.created_in <= '1522659288') AND (e.updated_in > '1522659288') HAVING (`delivery_active` IN ('1'))) as filter

The catalog_product_entity_int joined twice with 'HAVING' condition making this request vary hard to optimize for MySql.

The Fix

In Magento\CatalogSearch\Model\Adapter\Mysql\Filter\Preprocessor.php and Magento\CatalogSearch\Model\Search\CustomAttributeFilterCheck.php add 'boolean' to the Frontend Input array.
This will guide engine to handle Yes/No attributes same as select or multiselect - joining from catalog_product_index_eav table.
No double join with having - no performance struggling.

@magento-engcom-team
Copy link
Contributor

Hi @stkec. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

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

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@stkec do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Mar 15, 2019
@sivaschenko sivaschenko self-assigned this Mar 16, 2019
@magento-engcom-team
Copy link
Contributor

Hi @sivaschenko. 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.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.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. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • Next steps are available in case you are a member of Community Maintainers.

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

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

@sivaschenko sivaschenko removed their assignment Mar 16, 2019
@ghost ghost assigned stkec Mar 27, 2019
@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Apr 23, 2019
@magento-engcom-team
Copy link
Contributor

Hi @stkec. Thank you for your report.
The issue has been fixed in #21772 by @stkec in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.2 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests

3 participants