-
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.
sql: propagate result types to inputs in set ops with nulls and tuples
The physical planning for set operations is special because it allows for the result types from its inputs to be of different type family in some cases. Namely, it is ok if one input has `types.Unknown` whereas the other input is of some "known" type. In order to handle such case the execbuilder plans casts; however, currently it is not possible to plan casts to `Tuple` type. As a result, the vectorized engine is not able to execute the query because it expects the data coming from both inputs to be of the same type. This commit modifies the logic of reconciling the result types from both inputs to additionally update unknown types on the inputs if the other input is of a Tuple type. Such behavior is acceptable because in the original plan we only expected to have NULL values, and the Tuple type is able to handle such case too. The problem can also be reproduced in a logic test with the row-by-row engine in the `fakedist` setting. This bug was introduced in a76ee31, and before that change we had the following behavior: overwrite `plan.ResultTypes` to the merged types and then plan a stage of distinct processors if we have UNION. This resulted in the input spec for the input stream to distinct having correctly set types. After the change, that was no longer the case. Before that change the vectorized engine couldn't handle such queries due to type mismatch during `SupportsVectorized` check, so we fell back to the row-by-row engine. However, this commit makes it so that the vectorized engine is able to execute such queries. Release note (bug fix): CockroachDB previously could encounter an internal error when performing UNION operation when the first input resulted only in NULL values and consequent inputs produce tuples, and this is now fixed. Only 21.1 alpha versions are affected.
- Loading branch information
1 parent
3fc46fb
commit 4208a25
Showing
4 changed files
with
84 additions
and
14 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