-
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: propagate set operation output types to input columns
This commit updates the optbuilder logic for set operations in which the types of the input columns do not match the types of the output columns. This can happen if a column on one side has type Unknown, but the corresponding column on the other side has a known type such as Int. The known type must be propagated to the side with the unknown type to prevent errors in the execution engine related to decoding types. If there are any column types on either side that don't match the output, then the optbuilder propagates the output types of the set operation down to the input columns by wrapping the side with mismatched types in a Project operation. The Project operation passes through columns that already have the correct type, and creates cast expressions for those that don't. Fixes #34524 Release note (bug fix): Fixed an error that happened when executing some set operations containing only nulls in one of the input columns.
- Loading branch information
Showing
10 changed files
with
410 additions
and
147 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# ============================================================================= | ||
# set.opt contains normalization rules for set operators. | ||
# ============================================================================= | ||
|
||
# EliminateUnionAllLeft replaces a union all with a right side having a | ||
# cardinality of zero, with just the left side operand. | ||
[EliminateUnionAllLeft, Normalize] | ||
(UnionAll | ||
$left:* | ||
$right:* & (HasZeroRows $right) | ||
$colmap:* | ||
) | ||
=> | ||
(Project | ||
$left | ||
(ProjectColMapLeft $colmap) | ||
(MakeEmptyColSet) | ||
) | ||
|
||
# EliminateUnionAllRight replaces a union all with a left side having a | ||
# cardinality of zero, with just the right side operand. | ||
[EliminateUnionAllRight, Normalize] | ||
(UnionAll | ||
$left:* & (HasZeroRows $left) | ||
$right:* | ||
$colmap:* | ||
) | ||
=> | ||
(Project | ||
$right | ||
(ProjectColMapRight $colmap) | ||
(MakeEmptyColSet) | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
exec-ddl | ||
CREATE TABLE b (k INT PRIMARY KEY, i INT, f FLOAT, s STRING NOT NULL, j JSON) | ||
---- | ||
TABLE b | ||
├── k int not null | ||
├── i int | ||
├── f float | ||
├── s string not null | ||
├── j jsonb | ||
└── INDEX primary | ||
└── k int not null | ||
|
||
# -------------------------------------------------- | ||
# EliminateUnionAllLeft | ||
# -------------------------------------------------- | ||
|
||
opt expect=EliminateUnionAllLeft | ||
SELECT k FROM | ||
(SELECT k FROM b) | ||
UNION ALL | ||
(SELECT k FROM b WHERE k IN ()) | ||
---- | ||
project | ||
├── columns: k:11(int) | ||
├── scan b | ||
│ ├── columns: b.k:1(int!null) | ||
│ └── key: (1) | ||
└── projections | ||
└── variable: b.k [type=int, outer=(1)] | ||
|
||
# -------------------------------------------------- | ||
# EliminateUnionAllRight | ||
# -------------------------------------------------- | ||
|
||
opt expect=EliminateUnionAllRight | ||
SELECT k FROM | ||
(SELECT k FROM b WHERE Null) | ||
UNION ALL | ||
(SELECT k FROM b) | ||
---- | ||
project | ||
├── columns: k:11(int) | ||
├── scan b | ||
│ ├── columns: b.k:6(int!null) | ||
│ └── key: (6) | ||
└── projections | ||
└── variable: b.k [type=int, outer=(6)] | ||
|
||
opt | ||
SELECT k FROM | ||
(SELECT k FROM b WHERE False) | ||
UNION ALL | ||
(SELECT k FROM b WHERE i IN ()) | ||
---- | ||
values | ||
├── columns: k:11(int) | ||
├── cardinality: [0 - 0] | ||
├── key: () | ||
└── fd: ()-->(11) |
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
Oops, something went wrong.