Bound admin product grid keyword search to the paged query (#36408) - #41225
Open
lbajsarowicz wants to merge 1 commit into
Open
Bound admin product grid keyword search to the paged query (#36408)#41225lbajsarowicz wants to merge 1 commit into
lbajsarowicz wants to merge 1 commit into
Conversation
…6408) The grid fulltext filter loaded the whole match set as product models, re-queried every id, and passed them back to MySQL as a literal IN list, so paging was applied only after all the work was done. Attach the id select to the grid collection as a derived-table join instead, so one paged query runs and no ids are materialized in PHP.
|
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 (*)
The admin product grid keyword filter (
AddFulltextFilterToCollection) ran the LIKE-based search collection withload(), instantiating a product model for every match, thengetAllIds()ran the same unlimited query a second time, and the resulting id array was passed back to MySQL as a literalIN (...)list on the grid query. Paging applied only after all of that. At 50k products that is around 600 ms per keystroke (#36408); at millions of products it is a timeout and a memory blowup (#38867).This attaches the id select to the grid collection as an
INNER JOINon aSELECT DISTINCTderived table instead, so one paged query runs and no ids are materialized in PHP. The derived table is materialized once (it containsUNION ALLandDISTINCT, so the optimizer cannot merge it or rewrite it into a correlated subquery).Search\Collection::getBackendSearchEntityIdsSelect()is a new public method that reuses_getSearchEntityIdsSql()unchanged, so the attributes searched, theLIKEpattern, thestore_id = 0scope and theIFNULL(t2.value, t1.value)fallback are the same asaddBackendSearchFilter(). TheDISTINCTis what theUNION ALLrequires so a product matching in sku and name is one grid row.What this does not change: the
LIKE '%q%'scan over the searchable EAV rows is still linear in catalog size. It removes the multiplier on top of it. A FULLTEXT index or routing the grid through the search engine would change the scaling law and is a separate decision.Before, three statements plus model hydration:
After, one:
SVC:
getBackendSearchEntityIdsSelect()is an additive public method on an@apiclass (MINOR).Fixed Issues (if relevant)
Manual testing scenarios (*)
IN (id, id, ...)list.Contribution checklist (*)