Skip to content

Commit 708eb43

Browse files
zhuqi-lucasclaude
authored andcommitted
feat: add sort pushdown benchmark and SLT tests (apache#21213)
- Related to apache#17348 - Precursor to apache#21182 Add benchmark and integration tests for sort pushdown optimization, split out from apache#21182 per [reviewer request](apache#21182 (comment)). This allows comparing benchmark results before and after the optimization lands, and the SLT diff in apache#21182 will clearly show which test expectations changed due to the optimization. New `sort-pushdown` benchmark subcommand with 4 queries testing sort elimination: | Query | Description | |-------|-------------| | Q1 | `ORDER BY l_orderkey ASC` (full scan) | | Q2 | `ORDER BY l_orderkey ASC LIMIT 100` | | Q3 | `SELECT * ORDER BY l_orderkey ASC` (wide) | | Q4 | `SELECT * ORDER BY l_orderkey ASC LIMIT 100` (wide) | Usage: \`\`\`bash ./bench.sh data sort_pushdown ./bench.sh run sort_pushdown # baseline ./bench.sh run sort_pushdown_sorted # with sort elimination \`\`\` - **Test A**: Non-overlapping files + WITH ORDER → Sort eliminated (single partition) - **Test B**: Overlapping files → SortExec retained (baseline, files in original order) - **Test C**: LIMIT queries (ASC sort elimination + DESC reverse scan) - **Test D**: \`target_partitions=2\` → SPM + per-partition sort elimination - **Test E**: Inferred ordering from Parquet metadata (no WITH ORDER) — single and multi partition | File | Change | |------|--------| | \`benchmarks/src/sort_pushdown.rs\` | New benchmark module | | \`benchmarks/src/lib.rs\` | Register module | | \`benchmarks/src/bin/dfbench.rs\` | Register subcommand | | \`benchmarks/bench.sh\` | Add data/run entries | | \`datafusion/sqllogictest/test_files/sort_pushdown.slt\` | 5 new SLT test groups | - [x] \`cargo clippy -p datafusion-benchmarks\` — 0 warnings - [x] \`cargo test -p datafusion-sqllogictest -- sort_pushdown\` — all tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 00fc840 commit 708eb43

9 files changed

Lines changed: 811 additions & 3 deletions

File tree

‎benchmarks/bench.sh‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ clickbench_partitioned: ClickBench queries against partitioned (100 files) parqu
102102
clickbench_pushdown: ClickBench queries against partitioned (100 files) parquet w/ filter_pushdown enabled
103103
clickbench_extended: ClickBench \"inspired\" queries against a single parquet (DataFusion specific)
104104
105+
# Sort Pushdown Benchmarks
106+
sort_pushdown: Sort pushdown baseline (no WITH ORDER) on TPC-H data (SF=1)
107+
sort_pushdown_sorted: Sort pushdown with WITH ORDER — tests sort elimination on non-overlapping files
108+
105109
# Sorted Data Benchmarks (ORDER BY Optimization)
106110
clickbench_sorted: ClickBench queries on pre-sorted data using prefer_existing_sort (tests sort elimination optimization)
107111
@@ -305,6 +309,10 @@ main() {
305309
# same data as for tpch
306310
data_tpch "1" "parquet"
307311
;;
312+
sort_pushdown|sort_pushdown_sorted)
313+
# same data as for tpch
314+
data_tpch "1" "parquet"
315+
;;
308316
sort_tpch)
309317
# same data as for tpch
310318
data_tpch "1" "parquet"
@@ -505,6 +513,12 @@ main() {
505513
external_aggr)
506514
run_external_aggr
507515
;;
516+
sort_pushdown)
517+
run_sort_pushdown
518+
;;
519+
sort_pushdown_sorted)
520+
run_sort_pushdown_sorted
521+
;;
508522
sort_tpch)
509523
run_sort_tpch "1"
510524
;;
@@ -1193,6 +1207,22 @@ run_external_aggr() {
11931207
debug_run $CARGO_COMMAND --bin external_aggr -- benchmark --partitions 4 --iterations 5 --path "${TPCH_DIR}" -o "${RESULTS_FILE}" ${QUERY_ARG}
11941208
}
11951209

1210+
# Runs the sort pushdown benchmark (without WITH ORDER)
1211+
run_sort_pushdown() {
1212+
TPCH_DIR="${DATA_DIR}/tpch_sf1"
1213+
RESULTS_FILE="${RESULTS_DIR}/sort_pushdown.json"
1214+
echo "Running sort pushdown benchmark (no WITH ORDER)..."
1215+
debug_run $CARGO_COMMAND --bin dfbench -- sort-pushdown --iterations 5 --path "${TPCH_DIR}" -o "${RESULTS_FILE}" ${QUERY_ARG} ${LATENCY_ARG}
1216+
}
1217+
1218+
# Runs the sort pushdown benchmark with WITH ORDER (enables sort elimination)
1219+
run_sort_pushdown_sorted() {
1220+
TPCH_DIR="${DATA_DIR}/tpch_sf1"
1221+
RESULTS_FILE="${RESULTS_DIR}/sort_pushdown_sorted.json"
1222+
echo "Running sort pushdown benchmark (with WITH ORDER)..."
1223+
debug_run $CARGO_COMMAND --bin dfbench -- sort-pushdown --sorted --iterations 5 --path "${TPCH_DIR}" -o "${RESULTS_FILE}" ${QUERY_ARG} ${LATENCY_ARG}
1224+
}
1225+
11961226
# Runs the sort integration benchmark
11971227
run_sort_tpch() {
11981228
SCALE_FACTOR=$1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Sort elimination: ORDER BY sort key ASC (full scan)
2+
-- With --sorted: SortExec removed, sequential scan in file order
3+
-- Without --sorted: full SortExec required
4+
SELECT l_orderkey, l_partkey, l_suppkey
5+
FROM lineitem
6+
ORDER BY l_orderkey
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Sort elimination + limit pushdown
2+
-- With --sorted: SortExec removed + limit pushed to DataSourceExec
3+
-- Without --sorted: TopK sort over all data
4+
SELECT l_orderkey, l_partkey, l_suppkey
5+
FROM lineitem
6+
ORDER BY l_orderkey
7+
LIMIT 100
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Sort elimination: wide projection (all columns)
2+
-- Tests sort elimination benefit with larger row payload
3+
SELECT *
4+
FROM lineitem
5+
ORDER BY l_orderkey
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Sort elimination + limit: wide projection
2+
SELECT *
3+
FROM lineitem
4+
ORDER BY l_orderkey
5+
LIMIT 100

‎benchmarks/src/bin/dfbench.rs‎

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

3636
use datafusion_benchmarks::{
37-
cancellation, clickbench, h2o, hj, imdb, nlj, smj, sort_tpch, tpcds, tpch,
37+
cancellation, clickbench, h2o, hj, imdb, nlj, smj, sort_pushdown, sort_tpch, tpcds,
38+
tpch,
3839
};
3940

4041
#[derive(Debug, Parser)]
@@ -53,6 +54,7 @@ enum Options {
5354
Imdb(imdb::RunOpt),
5455
Nlj(nlj::RunOpt),
5556
Smj(smj::RunOpt),
57+
SortPushdown(sort_pushdown::RunOpt),
5658
SortTpch(sort_tpch::RunOpt),
5759
Tpch(tpch::RunOpt),
5860
Tpcds(tpcds::RunOpt),
@@ -72,6 +74,7 @@ pub async fn main() -> Result<()> {
7274
Options::Imdb(opt) => Box::pin(opt.run()).await,
7375
Options::Nlj(opt) => opt.run().await,
7476
Options::Smj(opt) => opt.run().await,
77+
Options::SortPushdown(opt) => opt.run().await,
7578
Options::SortTpch(opt) => opt.run().await,
7679
Options::Tpch(opt) => Box::pin(opt.run()).await,
7780
Options::Tpcds(opt) => Box::pin(opt.run()).await,

‎benchmarks/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub mod hj;
2323
pub mod imdb;
2424
pub mod nlj;
2525
pub mod smj;
26+
pub mod sort_pushdown;
2627
pub mod sort_tpch;
2728
pub mod tpcds;
2829
pub mod tpch;

0 commit comments

Comments
 (0)