Repository navigation
fix: error instead of wrong result for LATERAL DISTINCT with a non-equality correlated filter #27133
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
Draft
CuteChuanChuan
wants to merge
3
commits into
apache:main
Choose a base branch
from
CuteChuanChuan:issue-25808/lateral-distinct-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+117
−6
Draft
fix: error instead of wrong result for LATERAL DISTINCT with a non-equality correlated filter #27133
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
71e58ad
fix: error instead of wrong result for LATERAL DISTINCT with a non-eq…
CuteChuanChuan 5eed032
fix: only error when the pull up adds a DISTINCT key
CuteChuanChuan 89532b1
fix: treat a key pinned by a correlated equality as not splitting a g…
CuteChuanChuan 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
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -839,6 +839,31 @@ SELECT t1_id FROM t1 WHERE EXISTS (SELECT DISTINCT s.t2_id FROM (SELECT t2_id FR | |||||||||||||||||
| 22 | ||||||||||||||||||
| 44 | ||||||||||||||||||
|
|
||||||||||||||||||
| #exists_subquery_with_non_equality_filter_below_distinct | ||||||||||||||||||
| #de-correlated, the pulled up `t2_id` becomes an extra DISTINCT key, which only | ||||||||||||||||||
| #adds duplicate rows, and EXISTS ignores duplicates. See #25808. | ||||||||||||||||||
| query I rowsort | ||||||||||||||||||
| SELECT t1_id FROM t1 WHERE EXISTS (SELECT DISTINCT t2_int FROM t2 WHERE t2_id < t1_id) | ||||||||||||||||||
| ---- | ||||||||||||||||||
| 22 | ||||||||||||||||||
| 33 | ||||||||||||||||||
| 44 | ||||||||||||||||||
|
|
||||||||||||||||||
| #in_subquery_with_non_equality_filter_below_distinct | ||||||||||||||||||
| #de-correlated, IN ignores duplicates as well. For t1_id = 33, both | ||||||||||||||||||
| #(44, 3) and (55, 3) match, yet 33 is returned once. | ||||||||||||||||||
| query I rowsort | ||||||||||||||||||
| SELECT t1_id FROM t1 WHERE t1_int IN (SELECT DISTINCT t2_int FROM t2 WHERE t2_id > t1_id) | ||||||||||||||||||
| ---- | ||||||||||||||||||
| 11 | ||||||||||||||||||
| 33 | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: no test covers the
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| #in_subquery_with_non_equality_filter_below_group_by | ||||||||||||||||||
| #not de-correlated: an extra group key would change the counts. | ||||||||||||||||||
| #Expected result once supported: 11, 22. | ||||||||||||||||||
| statement error InSubquery | ||||||||||||||||||
| SELECT t1_id FROM t1 WHERE t1_int IN (SELECT count(*) FROM t2 WHERE t2_id > t1_id GROUP BY t2_int) | ||||||||||||||||||
|
|
||||||||||||||||||
| #exists_subquery_with_limit_below_group_by | ||||||||||||||||||
| #de-correlated, a grouping has rows exactly when its input has rows | ||||||||||||||||||
| query I rowsort | ||||||||||||||||||
|
|
||||||||||||||||||
Oops, something went wrong.
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.
Optional: two more shapes returned duplicates on main and now error,
GROUP BYwithout aggregates andLEFT JOIN LATERAL. Astatement errorfor each would pin them: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.
Added in 5eed032.