-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Type IN (subquery) over LowCardinality consistently in the old analyzer
#114856
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
18 changes: 18 additions & 0 deletions
18
tests/queries/0_stateless/04894_in_subquery_lowcardinality_type_old_analyzer.reference
This file contains hidden or 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,18 @@ | ||
| -- old analyzer | ||
| LowCardinality(UInt8) LowCardinality(UInt8) | ||
| LowCardinality(UInt8) | ||
| ('a',1) | ||
| ('b',0) | ||
| ['a'] | ||
| [] | ||
| 1 | ||
| 1 | ||
| -- the analyzer | ||
| LowCardinality(UInt8) LowCardinality(UInt8) | ||
| LowCardinality(UInt8) | ||
| ('a',1) | ||
| ('b',0) | ||
| ['a'] | ||
| [] | ||
| 1 | ||
| 1 |
35 changes: 35 additions & 0 deletions
35
tests/queries/0_stateless/04894_in_subquery_lowcardinality_type_old_analyzer.sql
This file contains hidden or 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,35 @@ | ||
| -- The result type of `IN` over a full `LowCardinality` column must not depend on the form of the | ||
| -- right-hand side, and must be the same during analysis and during execution. The old analyzer | ||
| -- replaces `in` with `inIgnoreSet` while it only needs the types, and used to pass the left operand | ||
| -- as the stand-in for the set that is not built yet: two full `LowCardinality` arguments type as | ||
| -- plain `UInt8`, while executing the real `in` against a constant set yields `LowCardinality(UInt8)`. | ||
| -- Reading such a column across a subquery boundary then failed the type check in | ||
| -- `ActionsDAG::updateHeader` with `Unexpected return type from tuple` (`LOGICAL_ERROR`). | ||
| -- The `arrayFilter` queries cover the same rewrite inside a lambda, whose captured arguments | ||
| -- must not gain columns that later analysis passes never create. | ||
|
|
||
| DROP TABLE IF EXISTS t_in_lc_type; | ||
| CREATE TABLE t_in_lc_type (s LowCardinality(String)) ENGINE = MergeTree ORDER BY s; | ||
| INSERT INTO t_in_lc_type VALUES ('a'), ('b'); | ||
|
|
||
| SELECT '-- old analyzer'; | ||
| SET enable_analyzer = 0; | ||
|
|
||
| SELECT DISTINCT toTypeName(s IN ('a')) AS literal_set, toTypeName(s IN (SELECT 'a')) AS subquery_set FROM t_in_lc_type; | ||
| SELECT DISTINCT toTypeName(f) FROM (SELECT s IN (SELECT 'a') AS f FROM t_in_lc_type); | ||
| SELECT tuple(*) AS t FROM (SELECT s, s IN (SELECT 'a') AS f FROM t_in_lc_type) ORDER BY t; | ||
| SELECT arrayFilter(x -> (x IN (SELECT 'a')), [s, 'b']) FROM t_in_lc_type ORDER BY s; | ||
| SELECT count() FROM t_in_lc_type WHERE s IN (SELECT 'a'); | ||
| SELECT count() FROM t_in_lc_type WHERE s NOT IN (SELECT 'a'); | ||
|
|
||
| SELECT '-- the analyzer'; | ||
| SET enable_analyzer = 1; | ||
|
|
||
| SELECT DISTINCT toTypeName(s IN ('a')) AS literal_set, toTypeName(s IN (SELECT 'a')) AS subquery_set FROM t_in_lc_type; | ||
| SELECT DISTINCT toTypeName(f) FROM (SELECT s IN (SELECT 'a') AS f FROM t_in_lc_type); | ||
| SELECT tuple(*) AS t FROM (SELECT s, s IN (SELECT 'a') AS f FROM t_in_lc_type) ORDER BY t; | ||
| SELECT arrayFilter(x -> (x IN (SELECT 'a')), [s, 'b']) FROM t_in_lc_type ORDER BY s; | ||
| SELECT count() FROM t_in_lc_type WHERE s IN (SELECT 'a'); | ||
| SELECT count() FROM t_in_lc_type WHERE s NOT IN (SELECT 'a'); | ||
|
|
||
| DROP TABLE t_in_lc_type; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appendWindowFunctionsArguments()executes theno_makesetDAG beforeWindowStep, so thisin*IgnoreSetnode is not limited to type inference.FunctionIn::executeImplstill returns an all-zeroUInt8column wheneverignore_setis true (src/Functions/in.cpp:101-102), which meansenable_analyzer = 0queries such asSELECT row_number() OVER (PARTITION BY s IN (SELECT 'a') ORDER BY s) ...still collapse every row into the same partition instead of evaluating the realINkey. The one-argument placeholder fixes theLowCardinalitytype mismatch, but it does not make the executed window path semantically correct. This path needs either a real key computation or a way to keepIgnoreSetout of executable window-expression DAGs.