Fix cartesian product when filtering on two FKs to the same target - #1708
Merged
Merged
Conversation
…rget (#1706) The filter (WHERE) side chose which of two converging relation paths got a complex alias by relation_str length, while the join builder uses depth-first order, so equal-length siblings (e.g. a_port__switch / z_port__switch) were assigned opposite aliases and the filter referenced a table the join never created. Complex aliases also linger in the globally shared alias manager, so a later, simpler query could pick one up and reference an unjoined table. Walk relation paths in the same depth-first order as the join (first occurrence keeps the basic alias, later ones go complex) and only reroute filters whose key is a duplicate registered for the current query.
Merging this PR will degrade performance by 11.66%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| 👁 | WallTime | test_get_or_create_when_create[40] |
417.6 ms | 472.8 ms | -11.66% |
Comparing fix/1706-cartesian-product-multi-fk (de81cbb) with master (e6f68fb)
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.
When two relation chains converge on the same target via the same final relation (e.g.
a_port__switchandz_port__switch), the filter side chose which path got a complex alias byrelation_strlength while the join builder uses depth-first order — so equal-length siblings were aliased inconsistently and the WHERE clause referenced a table the join never created, producing a cartesian product. Complex aliases also linger in the globally shared alias manager, letting a later simpler query pick one up.The filter now walks relation paths in the same depth-first order as the join (first occurrence keeps the basic alias, later ones go complex) and only reroutes filters whose key is a duplicate registered for the current query. Added regression tests covering the no-cartesian case, cross-query state isolation, and correct row results.
Closes #1706