Repository navigation
fix(query-builder): nest child joins only when outer join semantics require it - #12793
Conversation
Code Review by Qodo
1.
|
commit: |
| }), | ||
| )) | ||
|
|
||
| it("should not nest a child left join inside its left joined parent", () => { |
There was a problem hiding this comment.
Nit: worth adding a three level LEFT -> LEFT -> INNER case, since nestChildJoins only inspects direct children and that is the chain a future refactor would silently regress.
| .leftJoinAndSelect("categories.images", "images") | ||
| .getQuery() | ||
|
|
||
| expect(query).to.not.contain("JOIN (") |
There was a problem hiding this comment.
Nit: this only checks that a paren is absent, so asserting the full SQL string (as the neighbouring query-builder-select tests do) would also catch a wrong join order or a dropped ON.
Fixes #12792
Description of change
Since 1.1.0 a join gets wrapped in parentheses together with its children whenever it has any, so
leftJoinAndSelect("u.profile", "p").leftJoinAndSelect("p.country", "c")now emitsLEFT JOIN ("profile" "p" LEFT JOIN "country" "c" ON ...) ON ...instead of two flatLEFT JOINs. The nesting was added in #11137 to keep an inner child join from filtering out rows that its outer parent preserves, but it is applied to every combination, including left under left, where flat emission returns exactly the same rows. The parentheses pin the join order, and the reporter saw a seven-table query regress to ~19s averages on PostgreSQL 18 after upgrading.So the parentheses are now gated on the case they were introduced for: an inner child join under a left joined parent. Every other combination goes back to the flat form 1.0.0 emitted. The behaviour tests from #11137 pass unchanged, and the two SQL string assertions that were updated in that PR for a left-under-left chain move back to the flat expectation.
Pull-Request Checklist
masterbranchFixes #NNNN,Closes #NNNN, orResolves #NNNNtests/**.test.ts)docs/docs/**.md) — N/A (no documented behaviour changes, only the emitted SQL shape)