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

Fix redundant data copying in unnest #13441

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

demetribu
Copy link
Contributor

Which issue does this PR close?

Closes #13237.

Rationale for this change

In the current implementation, during the process where we align all columns to match the length of the longest unnest operation, it can result in excessive data copying and lead to unexpected errors for queries such as:

select * from (select unnest(range(0, 100000)) id) t inner join (select unnest(range(0, 100000)) id) t1 on t.id = t1.id;

This can trigger errors like attempt to add with overflow

What changes are included in this PR?

Introduced repeat_mask to determine which columns need to be repeated or replaced with nulls based on:

  1. Whether the column is required in future unnesting levels.
  2. Whether the column is involved in unnesting at all.

Ensures only necessary columns are repeated, reducing unnecessary data copying.

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added the physical-expr Physical Expressions label Nov 15, 2024
@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Nov 15, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @demetribu -- this looks very cool

@duongcongtoai , as the author of #12836 do you think you might be able to review this PR as well?

@duongcongtoai
Copy link
Contributor

nice, i will take a look

Copy link
Contributor

@duongcongtoai duongcongtoai left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overflow in repeat_arrs_from_indices
3 participants