Skip to content

Commit 19f2e85

Browse files
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` subcommand
1 parent 303ff78 commit 19f2e85

3 files changed

Lines changed: 807 additions & 1 deletion

File tree

‎benchmarks/src/bin/dfbench.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
3232
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
3333

3434
use datafusion_benchmarks::{
35-
cancellation, clickbench, dict, h2o, hj, imdb, nlj, smj, sort_tpch, tpcds, tpch,
35+
cancellation, clickbench, dict, h2o, hj, imdb, nlj, smj, sort_tpch, statistics,
36+
tpcds, tpch,
3637
};
3738

3839
#[derive(Debug, Parser)]
@@ -52,6 +53,7 @@ enum Options {
5253
Imdb(imdb::RunOpt),
5354
Nlj(nlj::RunOpt),
5455
Smj(smj::RunOpt),
56+
Statistics(statistics::RunOpt),
5557
SortPushdown(sort_pushdown::RunOpt),
5658
SortTpch(sort_tpch::RunOpt),
5759
Tpch(tpch::RunOpt),
@@ -73,6 +75,7 @@ pub async fn main() -> Result<()> {
7375
Options::Imdb(opt) => Box::pin(opt.run()).await,
7476
Options::Nlj(opt) => opt.run().await,
7577
Options::Smj(opt) => opt.run().await,
78+
Options::Statistics(opt) => opt.run().await,
7679
Options::SortPushdown(opt) => opt.run().await,
7780
Options::SortTpch(opt) => opt.run().await,
7881
Options::Tpch(opt) => Box::pin(opt.run()).await,

‎benchmarks/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub mod sort_tpch;
2929
pub mod sql_benchmark;
3030
pub mod sql_benchmark_runner;
3131
pub mod sql_benchmark_suite;
32+
pub mod statistics;
3233
pub mod tpcds;
3334
pub mod tpch;
3435
pub mod util;

0 commit comments

Comments
 (0)