Repository navigation
Commit 19f2e85
authored
Add dfbench statistics command (#23975)
## Which issue does this PR close?
- Part of #8227
## Rationale for this change
Provide a repeatable way to measure how closely planning cardinality
statistics match runtime output for benchmark query suites.
The goal is not to have an automated benchmark suite, and not something
to enforce in the CI. Instead, this is meant to be a development tool
for developers to locally iterate over stats estimation improvements.
## What changes are included in this PR?
`dfbench statistics` accepts any Parquet data directory and SQL file or
directory, so it can be used with TPC-DS, TPC-H, or another compatible
query suite. It:
- prints an indented, per-operator estimate-versus-runtime report as
each query completes;
- reports q-error per operator and finite q-error p50/p75/p95/p99 across
the run;
- stores results by branch, comparing with the previous run by default
or a named branch using `--compare`.
> About q-error calculation: https://vldb.org/pvldb/vol9/p204-leis.pdf
### Example: verify a TPC-DS Q21 improvement
1. Run TPC-DS Q21 for storing the baseline
```shell
cargo run --bin dfbench statistics \
--path benchmarks/data/tpcds_sf1 \
--query_path datafusion/core/tests/tpc-ds \
--query 21
```
2. Perform this small change in
https://github.com/apache/datafusion/blob/main/datafusion/physical-plan/src/sorts/sort.rs#L1427-L1427:
```rust
- Ok(Arc::new(stats.with_fetch(self.fetch, 0, 1)?))
+ Ok(Arc::new(stats.with_fetch(
+ self.fetch,
+ 0,
+ self.topk_emitter_count(),
+ )?))
```
3. Run again the command from step 1.
```text
=== 21 ===
SortPreservingMergeExec: rows=Inexact(100) vs 100, q-error: previous=1.00x, current=1.00x, change=0.0%
SortExec(TopK): rows=Inexact(1600) vs 1417, q-error: previous=14.40x, current=1.13x, change=✅ 92.2%
....
```
### Compare against a baseline from `main`
```shell
# Run on main first; the result is stored under main
cargo run --bin dfbench statistics \
--path benchmarks/data/tpcds_sf1 \
--query_path datafusion/core/tests/tpc-ds \
--query 21
# Then, on a feature branch
cargo run --bin dfbench statistics \
--path benchmarks/data/tpcds_sf1 \
--query_path datafusion/core/tests/tpc-ds \
--query 21 \
--compare main
```
TPC-H works with its partitioned data layout as well:
```shell
cargo run --bin dfbench statistics \
--path benchmarks/data/tpch_sf1 \
--query_path benchmarks/queries \
--query q1
```
## Are these changes tested?
No unit tests were added: this is a reporting CLI over planner
statistics and runtime metrics, exercised by the benchmark-suite smoke
runs above.
If reviewers think this type of code needs to be covered by unit tests
let me know.
## Are there any user-facing changes?
No, this is just for extending the `dfbench` command with a new `dfbench
statistics` subcommand1 parent 303ff78 commit 19f2e85
3 files changed
Lines changed: 807 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| 78 | + | |
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
0 commit comments