cockroach
cockroach copied to clipboard
release-21.2: xform: hoist projection from join only for canonical scans/selects
Backport 1/1 commits from #80212.
/cc @cockroachdb/release
Fixes #79943
Previously, HoistProjectFromInnerJoin would explore joins with the right input projection pulled up to the parent of the join, no matter the type of relation underneath the projection.
This was inadequate because queries involving many joins may invoke the ReorderJoins rule many times, which creates many new join expressions (orders of magnitude greater than the number of joins in the query), which need to be explored. Each of those may trigger projection pull-up, adding a new join expression to a memo group, further increasing the search space. Each of those added join expressions may themselves have a subtree of joins below them involving projections which may fire the rule again, leading to an explosion of rule firings and a query which never completes optimization (hangs).
To address this, this patch alters the conditions required to fire HoistProjectFromInnerJoin so that when the right input of the join is a projection, the input to the projection must be a canonical scan or a select from a canonical scan.
HoistProjectFromInnerJoin, added through #59780, is meant to enable more lookup joins because converting a projection on the right side of a join into a canonical scan allows GenerateLookupJoins to fire. Likewise, other join transformations such as SplitDisjunctionOfJoinTerms may require either a canonical scan or a select from a canonical scan as join inputs in order to fire. Other cases are unlikely to cause any new join transformations to fire since those rules check for canonical scans as input, so skipping their exploration will not result in any missed optimizations.
Release note (bug fix): Prior to this fix, queries with many joins and projections of multicolumn expressions, e.g. col1 + col2, either present in the query or within a virtual column definition, could experience very long optimization times or hangs, where the query is never sent for execution.
sql: Add disable_hoist_projection_in_join_limitation session flag
This commit adds the disable_hoist_projection_in_join_limitation session flag.
Release note: none
opttester: support session settings in opt tests
This commit adds the set opttest flag which can be used to set session flags via "set=flagname=value".
Release note: none
Release justification: Low risk fix for lengthy exploration time on complex queries.
Thanks for opening a backport.
Please check the backport criteria before merging:
- [x] Patches should only be created for serious issues or test-only changes.
- [x] Patches should not break backwards-compatibility.
- [x] Patches should change as little code as possible.
- [x] Patches should not change on-disk formats or node communication protocols.
- [x] Patches should not add new functionality.
- [x] Patches must not add, edit, or otherwise modify cluster versions; or add version gates.
If some of the basic criteria cannot be satisfied, ensure that the exceptional criteria are satisfied within.
- [ ] There is a high priority need for the functionality that cannot wait until the next release and is difficult to address in another way.
- [ ] The new functionality is additive-only and only runs for clusters which have specifically “opted in” to it (e.g. by a cluster setting).
- [ ] New code is protected by a conditional check that is trivial to verify and ensures that it only runs for opt-in clusters.
- [ ] The PM and TL on the team that owns the changed code have signed off that the change obeys the above rules.
Add a brief release justification to the body of your PR to justify this backport.
Some other things to consider:
- What did we do to ensure that a user that doesn’t know & care about this backport, has no idea that it happened?
- Will this work in a cluster of mixed patch versions? Did we test that?
- If a user upgrades a patch version, uses this feature, and then downgrades, what happens?
Are you still looking for approval on this PR, or was there another one opened in its place?