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

Use functional dependencies to optimize unnecessary order key column #16148

Closed
kwannoel opened this issue Apr 4, 2024 · 0 comments · Fixed by #16204
Closed

Use functional dependencies to optimize unnecessary order key column #16148

kwannoel opened this issue Apr 4, 2024 · 0 comments · Fixed by #16204
Assignees
Milestone

Comments

@kwannoel
Copy link
Contributor

kwannoel commented Apr 4, 2024

The query:

create table t1(id bigint primary key, i bigint);
create materialized view mv1 as select id, i from t1 order by id, i;

Has the plan:

 StreamMaterialize {
   columns: [id, i],
   stream_key: [id],
   pk_columns: [id, i],
   pk_conflict: NoCheck 
 }
 └─StreamTableScan { table: t1, columns: [id, i] }

But there's a functional dependency because id is the stream key:

id -> i

So this means we won't have such cases:

id i
1 2
1 3

This means in the sql above, we actually just need to have id as the pk columns, since i won't affect the sorting:

 StreamMaterialize {
   columns: [id, i],
   stream_key: [id],
   pk_columns: [id],
   pk_conflict: NoCheck 
 }
 └─StreamTableScan { table: t1, columns: [id, i] }

Specifically, in cases where there is a functional dependency between the prefix and the next column, we can prune the next column.

@github-actions github-actions bot added this to the release-1.8 milestone Apr 4, 2024
@kwannoel kwannoel changed the title Use functional dependencies to optimize unnecessary order key Use functional dependencies to optimize unnecessary order key column Apr 4, 2024
@kwannoel kwannoel self-assigned this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant