forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt, sql: fix type inference of TypeCheck for subqueries
Prior to this commit, the optimizer was not correctly inferring the types of columns in subqueries for expressions of the form `scalar IN (subquery)`. This was due to two problems which have now been fixed: 1. The subquery was built as a relational expression before the desired types were known. Now the subquery build is delayed until TypeCheck is called for the first time. 2. For subqueries on the right side of an IN expression, the desired type passed into TypeCheck was FamTuple. This resulted in an error later on in typeCheckSubqueryWithIn, which checks to make sure the type of the subquery is tuple{T} where T is the type of the left expression. Now the desired type passed into TypeCheck is tuple{T}. Note that this commit only fixes type inference for the optimizer. It is still broken in the heuristic planner. Fixes cockroachdb#37263 Fixes cockroachdb#14554 Release note (bug fix): Fixed type inference of columns in subqueries for some expressions of the form `scalar IN (subquery)`.
- Loading branch information
Showing
10 changed files
with
257 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# LogicTest: local-opt fakedist-opt | ||
|
||
# Regression test for #37263. This test is broken in the heuristic planner | ||
# because it does not correctly type check subqueries. | ||
query B | ||
SELECT 3::decimal IN (SELECT 1) | ||
---- | ||
false | ||
|
||
query error unsupported comparison operator | ||
SELECT 3::decimal IN (SELECT 1::int) | ||
|
||
query B | ||
SELECT 1 IN (SELECT '1'); | ||
---- | ||
true | ||
|
||
# Regression test for #14554. | ||
query ITIIIII | ||
SELECT t.oid, t.typname, t.typsend, t.typreceive, t.typoutput, t.typinput, t.typelem | ||
FROM pg_type AS t | ||
WHERE t.oid NOT IN ( | ||
SELECT (ARRAY[704,11676,10005,3912,11765,59410,11397])[i] | ||
FROM generate_series(1, 376) AS i | ||
) | ||
---- |
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
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.