-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: hoist uncorrelated subqueries at most once
Since #100881, the optimizer has hoisted uncorrelated subqueries used in an equality expression (only when the `optimizer_hoist_uncorrelated_equality_subqueries` session setting is enabled). This can cause problems when the hoisted subquery has been duplicated in the expression tree, e.g., when pushing a filter into both sides of a join. A subquery is a scalar expression, so the columns of its child expression are never emitted from the subquery. This makes it safe duplicate a subquery in an expression tree. However, when a subquery is hoisted, it is transformed into a join which can produce the columns of the child expression. Hoisting the same subquery multiple times can produce query plans with duplicate column IDs in two logically different expressions. This can lead to incorrect query plans (see the comment for `opt.Metadata`), as well as produce expressions with children that have intersecting column IDs (after additional normalization rules fire). To avoid these dangers, this commit ensures that each unique subquery is hoisted at most once. This will prevent bad plans, but it may not inhibit the optimizer from finding optimal plans. In the future, it may be possible to lift this restriction by generating new column ideas for uncorrelated subqueries each time they are hoisted. Fixes #114703 There is no release note because the session setting enabling this bug is disabled by default, and because the possible correctness bug is theoretical - we have not found a reproduction of a correctness bug, but it could exist in theory. Release note: None
- Loading branch information
Showing
3 changed files
with
216 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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