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 benchmark for planning sorted unions #14157

Merged
merged 1 commit into from
Jan 19, 2025

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jan 16, 2025

Which issue does this PR close?

Rationale for this change

#13748 is a planning speed problem, so as I increase the performance I want a benchmark that shows the improvements

What changes are included in this PR?

Add bechmark to the sql_planner suite

cargo bench  --bench sql_planner -- sorted
...
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.0s, or reduce sample count to 80.
physical_sorted_union_orderby
                        time:   [60.126 ms 60.213 ms 60.320 ms]
Found 9 outliers among 100 measurements (9.00%)
  6 (6.00%) high mild
  3 (3.00%) high severe

Are these changes tested?

Clippy / compilation is tested via CI

Are there any user-facing changes?

A new benchmark

Are there any user-facing changes?

Check out the flamegraph:

Screenshot 2025-01-16 at 1 39 04 PM

Whole flamegraph:
flamegraph

@github-actions github-actions bot added the core Core DataFusion crate label Jan 16, 2025
@@ -289,6 +362,17 @@ fn criterion_benchmark(c: &mut Criterion) {
});
});

// -- Sorted Queries --
register_union_order_table(&ctx, 100, 1000);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The table has 100 columns

/// UNION ALL
/// select null as c1, c2, ... null as cn from t ORDER BY c2
/// ...
/// select null as c1, null as c2, ... cn from t ORDER BY cn
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need inner ORDER BY if the query got the outer one? 🤔 Shouldn't be inner sorting ignored?

Copy link
Contributor

Choose a reason for hiding this comment

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

I probably get it, the problem is with the planning of such query not the execution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I probably get it, the problem is with the planning of such query not the execution

Yes, exactly

do we really need inner ORDER BY if the query got the outer one? 🤔 Shouldn't be inner sorting ignored?

Yes, indeed. I think the way it is ignored is that the sort equivalence code determines that the inner sorts aren't needed (or in this case they are all equivalent, so the top order by can a merge rather than sort)

The sort equivalence code (OrderEquivalenceProperties in particular) is what is consuming all this time

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 @alamb

@comphead comphead merged commit 3a65be0 into apache:main Jan 19, 2025
26 checks passed
@alamb alamb deleted the alamb/planning_bench branch January 22, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants