simonvandel opened a new pull request, #9020: URL: https://github.com/apache/arrow-datafusion/pull/9020
## 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 #123` indicates that this PR will close issue #123. --> Relates to https://github.com/apache/arrow-datafusion/issues/5637 ## 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. --> Planning time of Datafusion is slow. ## 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. --> 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? <details> <summary>Benchmark results</summary> ``` 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 ``` </details> ## Are these changes tested? <!-- 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 If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Should be in existing tests. ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> Faster planning. <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
