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

Add support for correlated subqueries & fix all related TPC-H benchmark issues #2885

Merged
merged 139 commits into from
Jul 22, 2022

Conversation

avantgardnerio
Copy link
Contributor

@avantgardnerio avantgardnerio commented Jul 12, 2022

Which issue does this PR close?

Closes #159
Closes #160
Closes #163
Closes #168
Closes #171
Closes #172
Closes #175

Rationale for this change

Getting the TPC-H queries to work allows Datafusion users and potential users to compare standard benchmarks to decide if Datafusion is the correct choice for their use case.

What changes are included in this PR?

3 new query optimizers:

  1. decorrelate_scalar_subquery
  2. decorrelate_where_exists
  3. decorrelate_where_in

pros

  • all TPC-H queries pass but 15 (create view, multiple statements) and 21 (error in filter push down)
  • it appears to be a generaliz(ed/able) approach to de-correlating subqueries
  • it handles things like multiple subqueries per filter, recusive subqueries, correlated and uncorrelated, etc
  • with the date stuff merged, it now largely works out of the box

cons

  • there is insufficient unit testing - update: I've added a bunch of unit tests, but fuzzing may be required to merge something like this
  • the code is verbose, and duplicated - update: it's definitely less verbose, and less duplicated, thoughts on the new methods?
  • variables names are hard to understand
  • it overlaps with filter_to_join

Are there any user-facing changes?

Correlated subqueries should work , but likely some will break or return incorrect results (thus the "draft" status).

@github-actions github-actions bot added core Core DataFusion crate optimizer Optimizer rules labels Jul 12, 2022
@andygrove andygrove changed the title Add support for correlated subqueries & fix all related TCP-H benchmark issues Add support for correlated subqueries & fix all related TPC-H benchmark issues Jul 12, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2022

Codecov Report

Merging #2885 (e341570) into master (b49093c) will increase coverage by 0.19%.
The diff coverage is 93.29%.

@@            Coverage Diff             @@
##           master    #2885      +/-   ##
==========================================
+ Coverage   85.43%   85.62%   +0.19%     
==========================================
  Files         275      279       +4     
  Lines       49739    50872    +1133     
==========================================
+ Hits        42495    43561    +1066     
- Misses       7244     7311      +67     
Impacted Files Coverage Δ
...tafusion/core/src/physical_plan/file_format/mod.rs 97.36% <ø> (ø)
datafusion/optimizer/src/utils.rs 89.07% <89.28%> (+0.50%) ⬆️
datafusion/optimizer/src/test/mod.rs 94.23% <92.10%> (-5.77%) ⬇️
...usion/optimizer/src/decorrelate_scalar_subquery.rs 92.75% <92.75%> (ø)
...tafusion/optimizer/src/decorrelate_where_exists.rs 93.44% <93.44%> (ø)
datafusion/expr/src/logical_plan/plan.rs 77.43% <93.75%> (+0.10%) ⬆️
datafusion/core/tests/sql/mod.rs 98.26% <94.02%> (-0.56%) ⬇️
datafusion/optimizer/src/decorrelate_where_in.rs 94.13% <94.13%> (ø)
datafusion/core/tests/sql/subqueries.rs 94.32% <94.32%> (ø)
datafusion/common/src/error.rs 80.45% <100.00%> (+0.45%) ⬆️
... and 11 more

@avantgardnerio avantgardnerio force-pushed the bg_correlated_subqueries branch 4 times, most recently from df214b4 to 9f802d0 Compare July 17, 2022 19:40
@github-actions github-actions bot added the logical-expr Logical plan and expressions label Jul 17, 2022
@avantgardnerio avantgardnerio force-pushed the bg_correlated_subqueries branch from 367cb56 to 440a4ae Compare July 18, 2022 20:34
@avantgardnerio
Copy link
Contributor Author

I think this is converging on a version I believe would be a good start on decorrelating sub-queries (it doesn't have to support all cases, as long as it fails instead of returning invalid plans). I've spent about 3 weeks on it so far, and I really would appreciate a thorough review before going too much farther. The longer I stare at it without external input, the more blind I will be as to what I missed or could do differently.

@andygrove @Dandandan @alamb I'd really appreciate your input (especially failing test case suggestions and readability improvements, but also thoughts on general approach, relationship with other work, and what should be in/out of scope).

@avantgardnerio avantgardnerio marked this pull request as ready for review July 18, 2022 21:13
@avantgardnerio avantgardnerio force-pushed the bg_correlated_subqueries branch from 9fedbb7 to ee91f24 Compare July 20, 2022 20:01
@alamb
Copy link
Contributor

alamb commented Jul 21, 2022

Any last thoughts @Dandandan @andygrove ?

@Dandandan
Copy link
Contributor

Thanks for the implementation @avantgardnerio awesome addition to DataFusion 😎

@avantgardnerio
Copy link
Contributor Author

I think all the items listed as critical are now resolved.

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.

Unless there are any other comments, I'll plan to merge this PR tomorrow

pub fn verify_not_disjunction(predicates: &[&Expr]) -> Result<()> {
struct DisjunctionVisitor {}

impl ExpressionVisitor for DisjunctionVisitor {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@alamb alamb merged commit 7b0f2f8 into apache:master Jul 22, 2022
@alamb
Copy link
Contributor

alamb commented Jul 22, 2022

Thanks again @avantgardnerio

@ursabot
Copy link

ursabot commented Jul 22, 2022

Benchmark runs are scheduled for baseline = 117df4d and contender = 7b0f2f8. 7b0f2f8 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@avantgardnerio avantgardnerio deleted the bg_correlated_subqueries branch July 28, 2022 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TPC-H Query 20 TPC-H Query 17 TPC-H Query 11 TPC-H Query 4 TPC-H Query 2
6 participants