Repository navigation
Commit 74f841f
authored
test: add correlated subquery cases for general decorrelation (apache#26904)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes apache#123` indicates that this PR will close issue apache#123.
-->
Part of apache#5492.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
Please explain the problem you are trying to solve in terms of the
user-visible
behavior, rather than the implementation.
For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of
the
implementation. "COUNT(DISTINCT) returns wrong results when the column
contains
nulls" is the user-visible problem.
-->
Many correlated subqueries fail to plan in DataFusion today, and some
return wrong rows. apache#5492 tracks a general decorrelation rule to replace
the current rules, and the plan proposed there starts with a tests-only
PR, so every later PR has a fixed set of queries to check its fixes
against.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here, but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
`subquery_decorrelation.slt` containing 57 queries.
Includes the following:
- The 12 shapes of the shape catalog linked in
[apache#5492](apache#5492 (comment)).
Three fail at planning with a schema error, six are left in the plan and
fail at physical planning, one is a control that works today, and two
are not valid SQL, because an aggregate over outer columns only belongs
to the outer query. DuckDB rejects those two, and DataFusion should
reject them while planning.
- All 44 queries from the repros in @jayzhan211's prototype branch,
mostly one per issue, including the dbolympics shapes
([apache#26704](apache#26704),
[apache#26710](apache#26710),
[apache#14554](apache#14554),
[apache#16137](apache#16137),
[apache#15558](apache#15558)) and the
wrong-result issues
([apache#26014](apache#26014),
[apache#26032](apache#26032),
[apache#25808](apache#25808),
[apache#26503](apache#26503),
[apache#26692](apache#26692)).
- The repro for
[apache#26572](apache#26572) from the
list on
[apache#5492](apache#5492 (comment)).
[apache#26569](apache#26569) from that
list isn't included, because it only affects joins built through the
Rust API. DataFusion's own decorrelation sets the value key count
(`null_aware(value_keys=2)` for a two-column `NOT IN`), so no SQL query
shows it.
The cases @jayzhan211's fuzzer found will follow in a second PR.
Each query records what `main` returns today. The 42 that aren't right
yet have DuckDB's answer in a comment above them, so a PR that fixes one
replaces the recorded error or rows with that answer. Cases taken from
an issue link to it. Today the 57 queries break down as follows.
| Today | Queries |
|---|---|
| Fails to plan or execute | 34 |
| Returns wrong rows | 8 |
| Returns the right rows | 11 |
| Fails, as it should | 4 |
## What is the testing strategy for this PR?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
Briefly describe how this PR is tested, and point to the specific tests
you added. For example: 'This new feature is covered by the
`sqllogictest` cases added in `foo.slt`'.
If this PR does not add tests, explain why. For example, if the change
is already covered by existing tests, please mention it.
You should also check the `codecov` bot reply on this PR to confirm the
changed code is exercised.
-->
The file passes on `main`, with output recorded by `--complete`, errors
trimmed to stable patterns, and `rowsort` for queries without an `ORDER
BY`. Answers were checked against DuckDB 2.0.0, and SQLite 3.51 agrees
on 51 of the 57. @jayzhan211's harness agrees with the file on the 40 of
44 repro queries it can check.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
No, this only adds tests.
## AI Usage
_AI was used during development of this PR, primarily to help review the
test suite and verify test cases against the DB binaries._1 parent 49f64f9 commit 74f841f
1 file changed
Lines changed: 1003 additions & 0 deletions
0 commit comments