-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql/tests: TestRandomSyntaxSQLSmith failed [inner-join RelExpr children have intersecting columns] #114703
Comments
Reduced reproduction: CREATE TABLE t (
k INT PRIMARY KEY,
a INT
);
SELECT NULL
FROM t AS t1
JOIN t AS t2 ON t1.a = t2.a
WHERE t2.a = (SELECT 0:::OID FROM t); |
This reproduces on the |
This was introduced in #100881. It can be reproduced in v23.1.x versions by setting The problem is that the filter with the subquery is pushed into both sides of the join, then, later, both pushed subqueries are hoisted and after several more normalization rules apply, the children of a join produce columns with the same ID. It is similar to the problem described in #100915, but this is a new path to achieve the same issue. I'm not yet sure what the implications of this are, but its not uncommon for overlapping column IDs to cause incorrect query plans: cockroach/pkg/sql/opt/metadata.go Lines 65 to 81 in a9cf65b
So it's definitely not something to take lightly. I have a few possible mitigations in mind:
|
I don't think this should block the beta, but I do think there is some risk for the GA release here, so I'm labelling a GA blocker. |
115142: opt: hoist uncorrelated subqueries at most once r=mgartner a=mgartner 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 IDs 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 Co-authored-by: Marcus Gartner <[email protected]>
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 IDs 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
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 IDs 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
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 IDs 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
sql/tests.TestRandomSyntaxSQLSmith failed with artifacts on release-23.2 @ c9f6f30496fe34af8d17410e5307f359458aaf52:
Random syntax error:
Query:
Schema:
Help
See also: How To Investigate a Go Test Failure (internal)
This test on roachdash | Improve this report!
Jira issue: CRDB-33641
The text was updated successfully, but these errors were encountered: