Skip to content
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

Add support for functional dependency for ROW_NUMBER window function. #8737

Merged
merged 4 commits into from
Jan 4, 2024
Merged

Add support for functional dependency for ROW_NUMBER window function. #8737

merged 4 commits into from
Jan 4, 2024

Conversation

mustafasrepo
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

For window queries in the form ROW_NUMBER() OVER(PARTITION BY <empty> ORDER BY <expr>), we know that row numbers generated will consists of consecutive numbers across table. Hence result of this expression can be treated as PRIMARY_KEY. This enables us to execute queries in the form below

SELECT *
FROM (SELECT c1, c2, ROW_NUMBER() OVER() as rn
    FROM aggregate_test_100
    LIMIT 5)
GROUP BY rn
ORDER BY rn;

without this support query above should be re-written as

SELECT *
FROM (SELECT c1, c2, ROW_NUMBER() OVER() as rn
    FROM aggregate_test_100
    LIMIT 5)
GROUP BY rn, c1, c2 -- this line is the difference
ORDER BY rn;

to be able to execute.

What changes are included in this PR?

This PR adds ROW_NUMBER result as functional dependencies when it known that its result will be unique across rows (when partition by expression is empty).

Are these changes tested?

Yes

Are there any user-facing changes?

@github-actions github-actions bot added logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Jan 3, 2024
Copy link
Contributor

@ozankabak ozankabak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple and straightforward, LGTM

@ozankabak ozankabak changed the title Add support for PRIMARY KEY for ROW_NUMBER window function. Add support for functional dependency for ROW_NUMBER window function. Jan 4, 2024
@ozankabak
Copy link
Contributor

I will go ahead and merge this since it is a very simple change. In case I'm not seeing some possible issue related to this, we will promptly fix with a follow-on.

@ozankabak ozankabak merged commit 819d357 into apache:main Jan 4, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants