magento2-40867: N+1 product queries for bundle options in GraphQL products queries
Community fix magento2-40867 merged into magento/magento2 on 2026-08-31, not in a release yet; applies cleanly to 7 releases from 2.4.8 to 2.4.9.
Fixes N+1 product queries for bundle options in GraphQL products queries edited
- Pull request title
- BundleGraphQL Resolvers Create Separate Deferred Product Instances, Defeating Query Batching (N+1)
- Pull request
- magento/magento2#40867
- Issues
- #40595 human
- Author
- @aasim110
- Merged
- 2026-08-31
- Fixed in
- no release yet
- Reported on
- 2.4.7-p9
- Categories
- Catalog/Product, GraphQL
- Components
- magento/module-bundle-graph-ql, magento/module-catalog-graph-ql
Labels
- Area
- Product
- Component
- GraphQL
- Priority
- P2
- Severity
- —
- Reported on (labels)
- —
Issue
Title and steps come from the upstream issue and pull request.
Description
COUNT(DISTINCT e.entity_id) + full product SELECT query pair. On a page with 20 bundle products averaging 6 selections each, this produces ~120 extra COUNT queries and ~120 extra SELECT queries — 240 unnecessary queries per request.Steps to reproduce
bin/magento dev:query-log:enable2. Send a GraphQL
products query for a category containing Bundle Products (e.g. requesting items { ... magentoBundledProduct } with child product fields like label)3. Inspect
var/debug/db.logExpected result
Deferred\Product batches all child product SKUs and loads them in a single query.Actual result
COUNT(DISTINCT e.entity_id) + full product SELECT query pair. On a page with 20 bundle products averaging 6 selections each, this produces ~120 extra COUNT queries and ~120 extra SELECT queries — 240 unnecessary queries per request.Taken from the upstream issue.
Code match per tag
Each tag was checked with git apply --check against that tag's files. A clean match means the change applies; it is not a test result. Tags that already contain the fix are marked.
| Line | Code match per tag | Tests |
|---|---|---|
| 2.4.6 | 2.4.6 conflict 2.4.6-p1 conflict 2.4.6-p2 conflict 2.4.6-p3 conflict 2.4.6-p4 conflict 2.4.6-p5 conflict 2.4.6-p6 conflict 2.4.6-p7 conflict 2.4.6-p8 conflict 2.4.6-p9 conflict 2.4.6-p10 conflict 2.4.6-p11 conflict 2.4.6-p12 conflict 2.4.6-p13 conflict 2.4.6-p14 conflict 2.4.6-p15 conflict | 2.4.6: no test data 2.4.6-p1: no test data 2.4.6-p2: no test data 2.4.6-p3: no test data 2.4.6-p4: no test data 2.4.6-p5: no test data 2.4.6-p6: no test data 2.4.6-p7: no test data 2.4.6-p8: no test data 2.4.6-p9: no test data 2.4.6-p10: no test data 2.4.6-p11: no test data 2.4.6-p12: no test data 2.4.6-p13: no test data 2.4.6-p14: no test data 2.4.6-p15: no test data |
| 2.4.7 | 2.4.7 conflict 2.4.7-p1 conflict 2.4.7-p2 conflict 2.4.7-p3 conflict 2.4.7-p4 conflict 2.4.7-p5 conflict 2.4.7-p6 conflict 2.4.7-p7 conflict 2.4.7-p8 conflict 2.4.7-p9 conflict 2.4.7-p10 conflict | 2.4.7: no test data 2.4.7-p1: no test data 2.4.7-p2: no test data 2.4.7-p3: no test data 2.4.7-p4: no test data 2.4.7-p5: no test data 2.4.7-p6: no test data 2.4.7-p7: no test data 2.4.7-p8: no test data 2.4.7-p9: no test data 2.4.7-p10: no test data |
| 2.4.8 | 2.4.8 clean 2.4.8-p1 clean 2.4.8-p2 clean 2.4.8-p3 clean 2.4.8-p4 clean 2.4.8-p5 clean | 2.4.8: no test data 2.4.8-p1: no test data 2.4.8-p2: no test data 2.4.8-p3: no test data 2.4.8-p4: no test data 2.4.8-p5: test files do not apply to this releaseunit: could not run before, could not run after |
| 2.4.9 | 2.4.9 clean | 2.4.9: test could not run before the patch, passes afterunit: could not run before, passes after |
Triage
Model @cf/cloudflare/clef. Probability this is a bug fix: 96.7%. Probability it is security relevant: 0.7%.
Show the model's answers and probabilities
| Question | Answer | Probabilities | Confidence |
|---|---|---|---|
| Change kind | bugfix | bugfix 88.4%, refactor 7.2%, tests_only 1.7%, feature 1.1%, dependency 1.0%, docs_only 0.6% | 74.5% |
| Area | graphql_api | graphql_api 85.8%, catalog 9.9%, framework 1.6% | 71.0% |
| Reported version | 2.4.7-p9 | 2.4.7-p9 60.1%, 2.4.7 11.1%, 2.4.7-p8 1.7% | 36.7% |
| Scope | 1.05 of 2 | 1 46.9%, 2 29.2%, 0 24.0% | 4.3% |
| Risk | 0.71 of 2 | 1 43.1%, 0 42.8%, 2 14.0% | 8.4% |
| Worth backporting | 1.54 of 2 | 2 64.5%, 1 24.7%, 0 10.8% | 23.3% |
Download
For cweagans/composer-patches, choose a version below and download the bundle. Copy its magento2-40867/ folder into patches/composer/, merge composer.patches.json into composer.json, then run composer install. Test files are always removed; paths are relative to each package root, using the default -p1 level.
Bundle README (what the ZIP ships)
# magento2-40867 Community fix merged upstream into magento/magento2, adapted by magento.watch. This is not a patch published by Adobe. Pull request: https://github.com/magento/magento2/pull/40867 Issue: https://github.com/magento/magento2/issues/40595 Author: @aasim110 Source commit: 27a62abf579d4e88f63738d0672859b586f80600 Modifications: test files and documentation removed, paths rewritten relative to each Composer package. Licence: OSL-3.0 / AFL-3.0, as the original Magento Open Source code. Maintainer: Łukasz Bajsarowicz (@lbajsarowicz)
Licence: Magento Open Source code under OSL-3.0 and AFL-3.0. The bundle carries the original author, source commit and the list of modifications.
