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

[SPARK-46446][SQL] Disable subqueries with correlated OFFSET to fix correctness bug #44401

Closed
wants to merge 2 commits into from

Conversation

jchen5
Copy link
Contributor

@jchen5 jchen5 commented Dec 18, 2023

What changes were proposed in this pull request?

Subqueries with correlation under LIMIT with OFFSET have a correctness bug, introduced recently when support for correlation under OFFSET was enabled but were not handled correctly. (So we went from unsupported, query throws error -> wrong results.) This is in master branch, not yet released.

This PR first disables correlated OFFSET by adding a feature flag for it, which is disabled. Next PR will add support for it and re-enable it. This PR also adds a feature flag for the related LIMIT support (which is enabled).

It’s a bug in all types of correlated subqueries: scalar, lateral, IN, EXISTS

Example repro:

create table x(x1 int, x2 int);
insert into x values (1, 1), (2, 2);
create table y(y1 int, y2 int);
insert into y values (1, 1), (1, 2), (2, 4);

select * from x where exists (select * from y where x1 = y1 limit 1 offset 2)

Correct result: empty set
Spark result: Array([2,2])

Why are the changes needed?

Correctness bug

Does this PR introduce any user-facing change?

Disables correlated OFFSET query shape which was not handled correctly. (This was enabled on master branch but not yet released.)

How was this patch tested?

Add tests

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the SQL label Dec 18, 2023
@jchen5
Copy link
Contributor Author

jchen5 commented Dec 18, 2023

@agubichev @cloud-fan

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

Could you make the CI happy, @jchen5 ?

@cloud-fan
Copy link
Contributor

The docker and pyspark test failures are unrelated, thanks, merging to master!

@jchen5
Copy link
Contributor Author

jchen5 commented Dec 19, 2023

I had some small test fixes that missed this PR, follow-up PR to fix the tests here: #44415

cloud-fan pushed a commit that referenced this pull request Dec 20, 2023
…lated OFFSET

### What changes were proposed in this pull request?
Follow-up PR for #44401, I had some small test fixes that didn't get included in that PR.

### Why are the changes needed?
Fix tests

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Tests themselves

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #44415 from jchen5/offset-tests.

Authored-by: Jack Chen <jack.chen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants