bench: discover ClickBench query files in sql_planner instead of hardcoding ranges - #25027
Open
adriangb wants to merge 2 commits into
Open
bench: discover ClickBench query files in sql_planner instead of hardcoding ranges#25027adriangb wants to merge 2 commits into
adriangb wants to merge 2 commits into
Conversation
…coding ranges
`sql_planner` built its ClickBench planning set from hardcoded ranges:
`(0..=42)` for `queries/` and `(0..=7)` for `extended/`. The extended
directory now holds q0..q13, so extended q8..q13 were never planned.
Replace both ranges with `read_numbered_queries`, which reads `q{N}.sql`
starting at `q0.sql` and stops at the first missing file — the same
discovery scheme `dfbench clickbench` uses (`get_query_sql` /
`get_query_path` in `benchmarks/src/clickbench.rs`). Newly added query
files are now picked up without a code change.
A missing file previously panicked via `read_to_string().unwrap()`; the
helper treats `NotFound` as the end of the sequence, still panics on any
other IO error, and asserts the directory was not empty so a wrong
`benchmarks_path` fails loudly rather than silently registering nothing.
`cargo bench -p datafusion --bench sql_planner -- --list` now enumerates
57 `physical_plan_clickbench_q*` benchmarks (43 standard + 14 extended),
up from 51, and the six newly covered queries plan successfully.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
kumarUjjawal
reviewed
Sep 7, 2026
Review feedback: stopping at the first missing file means a gap silently
truncates the set. If `q8.sql` disappeared while q9..q13 remained, the
benchmark would quietly plan only q0..q7 and the non-empty assertion
would still pass.
Discover the queries by listing the directory instead, keeping only
entries matching `q{N}.sql` (which also skips the `sorted_data`
directory alongside the standard ClickBench queries), sort them
numerically, and assert the numbering is contiguous from `q0.sql`.
Verified by temporarily removing `extended/q8.sql`: the bench now panics
with `left: [0..7, 9..13]` / `right: [0..12]`, naming the directory and
making the gap obvious, rather than silently dropping six queries.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
adriangb
enabled auto-merge
September 7, 2026 15:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
datafusion/core/benches/sql_planner.rsbuilds its ClickBench planning benchmarkset from two hardcoded ranges:
benchmarks/queries/clickbench/extended/has grown since that(0..=7)waswritten and now contains
q0.sqlthroughq13.sql, so extended queries q8–q13were never planned by this benchmark — six queries silently outside coverage.
The ranges are also a maintenance trap in both directions: adding a query file
requires remembering to bump an unrelated literal, and because the read is
std::fs::read_to_string(...).unwrap(), a range that runs past the end of thedirectory panics the whole bench rather than stopping.
The
dfbench clickbenchrunner does not have this problem — it discovers queryfiles by walking
0..and stopping at the first missing one (get_query_sql/get_query_pathinbenchmarks/src/clickbench.rs). This PR makes the planningbenchmark use the same scheme.
What changes are included in this PR?
read_numbered_queries(dir)helper tosql_planner.rsthat readsq{N}.sqlstarting atq0.sqland stops at the first missing file.(0..=42)and extended(0..=7)—with calls to it. New query files are now picked up without a code change.
Two details on error handling, since the previous
.unwrap()was load-bearing:ErrorKind::NotFoundends the sequence. Any other IO error still panics,now with the offending path in the message.
assert!(!queries.is_empty(), ...)guards the case wherebenchmarks_pathresolves somewhere wrong: without it, discovery would silently register zero
ClickBench benchmarks, which is a worse failure than the old panic.
I also grepped for other places that hardcode a ClickBench extended query count;
there are none.
benchmarks/bench.shpasses--queries-pathto thedfbenchrunner, which already discovers.
What is the testing strategy for this PR?
This is benchmark-only code with no unit tests; verified by running the bench
target locally against a real ClickBench
hits_partitioneddataset:cargo bench -p datafusion --bench sql_planner -- --listnow enumerates 57physical_plan_clickbench_q*benchmarks (43 standard + 14 extended), up from51, and does not panic.
cargo bench -p datafusion --bench sql_planner -- --quick 'physical_plan_clickbench_q5[2-7]$'— the six newly covered extended queries — all plan successfully
(6.4–10.7 ms each, unoptimized build).
cargo fmt --allandcargo clippy -p datafusion --benches -- -D warningsareclean.
Note that benchmark IDs are positional (
q{index + 1}), so the extended querieskeep their existing IDs and the six new ones append as q52–q57; no existing
benchmark is renumbered.
Are there any user-facing changes?
No. Benchmark harness only — no library code, no public API.
🤖 Generated with Claude Code