Skip to content

Conversation

@dmitriibugakov
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 Changes to the physical-expr crates 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

@alamb
Copy link
Contributor

alamb commented Nov 18, 2024

Thanks @demetribu and @duongcongtoai ❤️

@alamb alamb merged commit 189536b into apache:main Nov 18, 2024
@dmitriibugakov
Copy link
Contributor Author

Thanks for review @alamb and @duongcongtoai

@dmitriibugakov dmitriibugakov deleted the fix-unnest-repeat-columns branch November 18, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates 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