Add index on catalog_product_entity.type_id (#37431) - #41223
Open
lbajsarowicz wants to merge 1 commit into
Open
Conversation
Core code filters catalog_product_entity by type_id in several places (export RowCustomizers, widget Chooser, Lowstock collection, frontend action Synchronizer) with no supporting index, forcing a full scan. Declarative schema has no index prefix-length support, so this adds a full-column btree index. Line wrapping in db_schema.xml satisfies the Static Tests build for the touched file.
|
Hi @lbajsarowicz. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
Contributor
Author
|
@magento run all tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description (*)
catalog_product_entity.type_idhas no index. Core filters on it in the configurable and downloadable export row customizers, the admin widget product chooser, the low-stock report collection and the product frontend action synchronizer, and every one of those is a full table scan.This adds a btree index on
type_idand whitelists it. Declarative schema has no prefix-length support (index.xsdonly knows a columnname), so this is a full-column index.Measured on a copy of the table grown to 307,200 rows (4,096 configurable, 303,104 simple), MySQL 8.0, medians of 3 from
SHOW PROFILES:COUNT(*) WHERE type_id='configurable'entity_id, sku WHERE type_id='configurable' ORDER BY entity_id LIMIT 200COUNT(*) WHERE type_id='simple'The last row is the trade-off: for the dominant value the optimizer prefers the 130-byte key over the clustered scan and gets slower. Core never filters on
type_id='simple'alone, and a prefix index that would shrink that cost is not expressible in declarative schema.Line wrapping elsewhere in
db_schema.xmlis there because the Static Tests build fails on pre-existing line-length warnings in any touched file.Local gates: unit and static pass. In the Catalog integration suite,
SortingTest::testProductListOutOfStockSortOrderWithMysqlfails identically on a clean2.4-developcheckout in the same environment, so it is not related to this change.Fixed Issues (if relevant)
Manual testing scenarios (*)
bin/magento setup:upgradeon an existing install, thenSHOW INDEX FROM catalog_product_entityshowsCATALOG_PRODUCT_ENTITY_TYPE_ID.bin/magento setup:db-declaration:generate-whitelist --module-name=Magento_Catalogproduces no diff.EXPLAIN SELECT COUNT(*) FROM catalog_product_entity WHERE type_id='configurable'uses the new key.Contribution checklist (*)