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

Speedup DFSchema::merge using HashSet indices #9020

Merged
merged 4 commits into from
Jan 30, 2024

Conversation

simonvandel
Copy link
Contributor

@simonvandel simonvandel commented Jan 27, 2024

Which issue does this PR close?

Relates to #5637

Rationale for this change

Planning time of Datafusion is slow.

What changes are included in this PR?

Profiling shows that a large part of planning is spent in DFSchema::merge.
Before this PR, merging was complexity O(N * M), where N and M are number of fields in the two schemas.
With this PR, merging is complexity O(N + M) using a HashSet as an index.

Speeds up benchmarks in sql_planner.rs by 18-75%. However, physical planning benchmarks seem to regress by 1.8%. I wonder if that is an acceptable trade?

CC @matthewmturner who seems interested in planning performance

Benchmark results
Gnuplot not found, using plotters backend
Benchmarking logical_select_one_from_700: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.8s, enable flat sampling, or reduce sample count to 60.
logical_select_one_from_700
                        time:   [1.3324 ms 1.3359 ms 1.3396 ms]
                        change: [-54.725% -54.348% -53.914%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 14 outliers among 100 measurements (14.00%)
  6 (6.00%) low mild
  3 (3.00%) high mild
  5 (5.00%) high severe

physical_select_one_from_700
                        time:   [4.6236 ms 4.6485 ms 4.6795 ms]
                        change: [-75.159% -74.941% -74.735%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
  3 (3.00%) high mild
  5 (5.00%) high severe

Benchmarking logical_trivial_join_low_numbered_columns: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.8s, enable flat sampling, or reduce sample count to 60.
logical_trivial_join_low_numbered_columns
                        time:   [1.3504 ms 1.3546 ms 1.3592 ms]
                        change: [-22.854% -22.042% -21.199%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  1 (1.00%) low mild
  4 (4.00%) high mild
  6 (6.00%) high severe

Benchmarking logical_trivial_join_high_numbered_columns: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.1s, enable flat sampling, or reduce sample count to 50.
logical_trivial_join_high_numbered_columns
                        time:   [1.3961 ms 1.4003 ms 1.4051 ms]
                        change: [-21.654% -21.238% -20.848%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
  2 (2.00%) low mild
  8 (8.00%) high mild
  2 (2.00%) high severe

Benchmarking logical_aggregate_with_join: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 9.3s, enable flat sampling, or reduce sample count to 50.
logical_aggregate_with_join
                        time:   [1.8286 ms 1.8331 ms 1.8381 ms]
                        change: [-18.973% -18.543% -18.126%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) low mild
  6 (6.00%) high mild
  1 (1.00%) high severe

physical_plan_tpch      time:   [5.6537 ms 5.6803 ms 5.7095 ms]
                        change: [+1.1125% +1.7618% +2.3821%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 9 outliers among 100 measurements (9.00%)
  6 (6.00%) high mild
  3 (3.00%) high severe

Are these changes tested?

Should be in existing tests.

Are there any user-facing changes?

Faster planning.

@matthewmturner
Copy link
Contributor

Nice 😀

Trade off seems worth it.

I'm curious what's going on in that TPCH benchmark though as the other physical select benchmark showed solid improvement so not sure it's all physical planning.

simonvandel and others added 2 commits January 27, 2024 22:55
Co-authored-by: comphead <[email protected]>
Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

lgtm thanks @simonvandel

@alamb
Copy link
Contributor

alamb commented Jan 29, 2024

Speeds up benchmarks in sql_planner.rs by 18-75%. However, physical planning benchmarks seem to regress by 1.8%. I wonder if that is an acceptable trade?

I think this is an acceptable trade

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.

Thank you very much @simonvandel 🙏

@simonvandel
Copy link
Contributor Author

Anything I need to do before we can merge this?

@comphead comphead merged commit d6f7c16 into apache:main Jan 30, 2024
22 checks passed
@alamb
Copy link
Contributor

alamb commented Jan 30, 2024

Thanks again @simonvandel and @matthewmturner and @comphead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants