You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "SubhamSinghal (via GitHub)" <gi...@apache.org> on 2026/08/27 17:05:35 UTC
[PR] bench(h2o): window Top-N sweep over a declared-sorted input [datafusion]
SubhamSinghal opened a new pull request, #24732:
URL: https://github.com/apache/datafusion/pull/24732
## Which issue does this PR close?
Related to #6899 — adds benchmark coverage for the WindowTopN operators.
## Rationale for this change
The existing `h2o --subgroup window` Top-N sweep (q13–q29) registers `x` with no declared ordering, so `output_ordering()` is `None`. Any plan that depends on the input being sorted is unreachable from those queries, however the data happens to be laid out on disk. This adds a `window_sorted` subgroup that publishes the same sweep over a `WITH ORDER` table, so ordering-dependent plans can be measured.
## What changes are included in this PR?
A `window_sorted` h2o subgroup: 16 queries covering ROW_NUMBER / RANK / DENSE_RANK × 100 / 1K / 10K / 100K partitions, plus heavy-ties variants.
- Two `load` directives: the existing `load_window_${SIZE}_${FORMAT}.sql` creates `x`, then a new script writes a sorted copy via `COPY (... ORDER BY pk, ob DESC)` and registers it `WITH ORDER (pk ASC, ob DESC)`. Reusing the existing loader keeps both the `--size` and `--format` axes working with no duplication. `load` is untimed, so the sort stays out of the measurement.
- `WITH ORDER` can only name columns, so the partition key (`id3 % N`) and the tie expression are materialized as `pk` and `ob`.
- Asserts guard the three ways this could silently measure nothing: both config flags took effect, the sorted copy holds every source row, and `ob` has the cardinality the query name claims.
- `expect_plan PartitionedTopKExec` is deliberately the shared substring, so the same file validates the heap operator and any streaming variant that replaces it.
No Rust changes; benchmark files only.
## Are these changes tested?
`benchmark_runner h2o --subgroup window_sorted` runs all 16 queries green. Row counts are exact: 2 per partition for the distinct-ORDER-BY shapes, and 1,010,812 (RANK) / 2,020,722 (DENSE_RANK) for the tie shapes — the top-1 and top-2 of 10 distinct values over 10M rows.
## Are there any user-facing changes?
No.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] bench(h2o): window Top-N sweep over a declared-sorted input [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #24732:
URL: https://github.com/apache/datafusion/pull/24732#discussion_r3903974618
##########
benchmarks/sql_benchmarks/h2o/window_sorted.benchmark.template:
##########
@@ -0,0 +1,90 @@
+# Shared template for the h2o `window_sorted` subgroup: WindowTopN over an
+# input that *declares* the ordering the window requires.
+#
+# Parameters set by each qNN.benchmark:
+# QPAD zero-padded query id
+# FN window function (ROW_NUMBER, RANK, DENSE_RANK)
+# PK_MOD partition count (100, 1000, 10000, 100000)
+# OB_EXPR ORDER BY value expression (`v2` distinct, integer-cast for ties)
+# OB_BOUND SQL predicate pinning ob's cardinality, asserted below
+# NAME display name
+#
+# Why this subgroup exists: the `window` subgroup registers `x` with no declared
+# ordering, so `output_ordering()` is None and the planner cannot know the input
+# is sorted. Any operator that requires a declared ordering is therefore
+# unreachable from those queries, however the data happens to be laid out on
+# disk. This subgroup republishes the same sweep over a `WITH ORDER` table so
+# the ordering-dependent plans are reachable.
+#
+# The first `load` is the existing unsorted loader, which creates `x`; the
+# second reads `x` and writes the sorted `x_sorted`. Reusing the existing loader
+# keeps both the `--size` and `--format` axes working with no duplication.
+
+load sql_benchmarks/h2o/init/load_window_${H2O_BENCH_SIZE:-small}_${H2O_FILE_TYPE:-csv}.sql
+
+load sql_benchmarks/h2o/init/load_window_sorted.sql
+
+init sql_benchmarks/h2o/init/window_sorted_settings.sql
+
+name ${NAME}
+group h2o
+
+echo Loading ${H2O_BENCH_SIZE:-small} window ${H2O_FILE_TYPE:-csv} h2o data, sorted by (pk, ob DESC) over ${PK_MOD} partitions
+
+# Guard against a silent config no-op: with the rewrite off the plan is a plain
+# window plus filter, and the subgroup would measure something other than what
+# its name claims.
+assert I
+SELECT value = 'true' FROM information_schema.df_settings WHERE name = 'datafusion.optimizer.enable_window_topn';
+----
+true
+
+# Same guard for the setting that decides an ordering-requiring operator gets an
+# order-preserving repartition instead of a redundant SortExec.
+assert I
+SELECT value = 'true' FROM information_schema.df_settings WHERE name = 'datafusion.optimizer.prefer_existing_sort';
+----
+true
+
+# The sorted copy must hold every non-null-v2 row of the source. This catches a
+# COPY that silently wrote a partial file, which would otherwise show up only as
+# a suspiciously fast run.
+assert I
+SELECT count(*) = (SELECT count(*) FROM x WHERE v2 IS NOT NULL) FROM x_sorted;
+----
+true
+
+# The ORDER BY column really has the cardinality this query's name claims. A
+# tie-shape query whose `ob` turns out near-unique measures the no-ties case
+# under a heavy-ties name, and nothing else in the run would show it: the timings
+# stay plausible and only the output row count quietly collapses to K per
+# partition. `v2` is Float64, so this is a live trap — `v2 % 10` is float modulo
+# and yields no ties at all.
+assert I
+SELECT ${OB_BOUND} FROM x_sorted;
+----
+true
+
+# The per-partition top-K operator has to be in the plan, otherwise the
+# declared ordering was not picked up and this is just a window-plus-filter
+# measurement wearing the subgroup's name.
+#
+# `PartitionedTopKExec` is deliberately the string asserted rather than a
+# fully-qualified operator name: it is also a substring of the streaming
+# variant's name, so this same check holds on a branch where a streaming
+# operator replaces the heap one for declared-sorted input. That is the point of
+# the subgroup — the comparison is this file's numbers across two branches, so
+# the assertion must not be the thing that differs between them.
+expect_plan PartitionedTopKExec
Review Comment:
Could we also add a plan-level check that the `WITH ORDER` declaration actually reaches `DataSourceExec`, for example by checking the source `output_ordering`? The current `PartitionedTopKExec` assertion does not verify this because that operator only requires key distribution and can still appear with an unordered source. Having a separate ordering check would help catch accidental loss of the declared-order setup, especially if an ordering-dependent Top-N implementation uses this benchmark in the future.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] bench(h2o): window Top-N sweep over a declared-sorted input [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on code in PR #24732:
URL: https://github.com/apache/datafusion/pull/24732#discussion_r3905879856
##########
benchmarks/sql_benchmarks/h2o/window_sorted.benchmark.template:
##########
@@ -0,0 +1,90 @@
+# Shared template for the h2o `window_sorted` subgroup: WindowTopN over an
+# input that *declares* the ordering the window requires.
+#
+# Parameters set by each qNN.benchmark:
+# QPAD zero-padded query id
+# FN window function (ROW_NUMBER, RANK, DENSE_RANK)
+# PK_MOD partition count (100, 1000, 10000, 100000)
+# OB_EXPR ORDER BY value expression (`v2` distinct, integer-cast for ties)
+# OB_BOUND SQL predicate pinning ob's cardinality, asserted below
+# NAME display name
+#
+# Why this subgroup exists: the `window` subgroup registers `x` with no declared
+# ordering, so `output_ordering()` is None and the planner cannot know the input
+# is sorted. Any operator that requires a declared ordering is therefore
+# unreachable from those queries, however the data happens to be laid out on
+# disk. This subgroup republishes the same sweep over a `WITH ORDER` table so
+# the ordering-dependent plans are reachable.
+#
+# The first `load` is the existing unsorted loader, which creates `x`; the
+# second reads `x` and writes the sorted `x_sorted`. Reusing the existing loader
+# keeps both the `--size` and `--format` axes working with no duplication.
+
+load sql_benchmarks/h2o/init/load_window_${H2O_BENCH_SIZE:-small}_${H2O_FILE_TYPE:-csv}.sql
+
+load sql_benchmarks/h2o/init/load_window_sorted.sql
+
+init sql_benchmarks/h2o/init/window_sorted_settings.sql
+
+name ${NAME}
+group h2o
+
+echo Loading ${H2O_BENCH_SIZE:-small} window ${H2O_FILE_TYPE:-csv} h2o data, sorted by (pk, ob DESC) over ${PK_MOD} partitions
+
+# Guard against a silent config no-op: with the rewrite off the plan is a plain
+# window plus filter, and the subgroup would measure something other than what
+# its name claims.
+assert I
+SELECT value = 'true' FROM information_schema.df_settings WHERE name = 'datafusion.optimizer.enable_window_topn';
+----
+true
+
+# Same guard for the setting that decides an ordering-requiring operator gets an
+# order-preserving repartition instead of a redundant SortExec.
+assert I
+SELECT value = 'true' FROM information_schema.df_settings WHERE name = 'datafusion.optimizer.prefer_existing_sort';
+----
+true
+
+# The sorted copy must hold every non-null-v2 row of the source. This catches a
+# COPY that silently wrote a partial file, which would otherwise show up only as
+# a suspiciously fast run.
+assert I
+SELECT count(*) = (SELECT count(*) FROM x WHERE v2 IS NOT NULL) FROM x_sorted;
+----
+true
+
+# The ORDER BY column really has the cardinality this query's name claims. A
+# tie-shape query whose `ob` turns out near-unique measures the no-ties case
+# under a heavy-ties name, and nothing else in the run would show it: the timings
+# stay plausible and only the output row count quietly collapses to K per
+# partition. `v2` is Float64, so this is a live trap — `v2 % 10` is float modulo
+# and yields no ties at all.
+assert I
+SELECT ${OB_BOUND} FROM x_sorted;
+----
+true
+
+# The per-partition top-K operator has to be in the plan, otherwise the
+# declared ordering was not picked up and this is just a window-plus-filter
+# measurement wearing the subgroup's name.
+#
+# `PartitionedTopKExec` is deliberately the string asserted rather than a
+# fully-qualified operator name: it is also a substring of the streaming
+# variant's name, so this same check holds on a branch where a streaming
+# operator replaces the heap one for declared-sorted input. That is the point of
+# the subgroup — the comparison is this file's numbers across two branches, so
+# the assertion must not be the thing that differs between them.
+expect_plan PartitionedTopKExec
Review Comment:
Addressed in 550dd1b479f1e015184af4d692659258ac606d0e
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] bench(h2o): window Top-N sweep over a declared-sorted input [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on PR #24732:
URL: https://github.com/apache/datafusion/pull/24732#issuecomment-5520015410
🚀
@SubhamSinghal
Thank you for your contribution.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] bench(h2o): window Top-N sweep over a declared-sorted input [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew merged PR #24732:
URL: https://github.com/apache/datafusion/pull/24732
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] bench(h2o): window Top-N sweep over a declared-sorted input [datafusion]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #24732:
URL: https://github.com/apache/datafusion/pull/24732#issuecomment-5443258681
## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/24732?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 81.42%. Comparing base ([`408fc6f`](https://app.codecov.io/gh/apache/datafusion/commit/408fc6f57abffde619da7a3f66774ffcdd503dc6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`886ec22`](https://app.codecov.io/gh/apache/datafusion/commit/886ec2243b145d02fe9b95cc19a4f363d3dd1c2d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 3 commits behind head on main.
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #24732 +/- ##
==========================================
- Coverage 81.42% 81.42% -0.01%
==========================================
Files 1120 1120
Lines 402021 402021
Branches 402021 402021
==========================================
- Hits 327357 327351 -6
- Misses 55484 55488 +4
- Partials 19180 19182 +2
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/24732?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org