fix: window in scalar subquery returns wrong results #16567
Merged
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.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Because we introduced single to inner join optimization, so we don't need to maintain the method
rewrite_uncorrelated_scalar_subquery
instead of rewriting to single join directly.Then we can solve the issue15977.
Note:
select count(distinct a) over (partition by 1) from t1;
PARTITION BY 1
is a special syntax that actually means no partitioning, i.e., all rows are treated as a partition. Sopartition by (select b from t2)
is not semantic if it returns more than one row but if returns only one row, it's valid, meaning no partitioning.Tests
Type of change
This change is