Repository navigation
Commit 49c0aa3
authored
fix: PartitionedTopKRank counts tie rows twice in output_rows (#25535)
## Which issue does this PR close?
- N/A — no issue filed; found while reading the code.
## Rationale for this change
For a `RANK()` window Top-N (`PartitionedTopKExec: fn=rank`), the
`output_rows` and `output_batches` metrics shown by `EXPLAIN ANALYZE`
are too high whenever rows tie at the K-th value.
`PartitionedTopKRank::emit` calls `record_output` on every tie batch
before pushing it into the `BatchCoalescer`, and then calls
`record_output` again on each completed batch coming out of that
coalescer — which already contains those tie rows. Heap rows are only
counted at the second site, so each tie row is counted twice and each
tie batch adds a phantom output batch.
Example: K = 2, one partition with values `5, 5, 10, 5`. Three rows are
emitted in one batch, but the metrics report `output_rows=4`,
`output_batches=2`.
`PartitionedTopK` (`ROW_NUMBER`) and `PartitionedTopKDenseRank` only
record at the coalescer output and are not affected.
## What changes are included in this PR?
Remove the extra `record_output` call on tie batches so every emitted
row is counted once, at the coalescer output, as in the other two
operators. Query results are unchanged; only the metrics are corrected.
## What is the testing strategy for this PR?
New unit test `test_partitioned_topk_rank_output_rows_counts_ties_once`,
which emits heap rows plus a boundary tie and asserts `output_rows` /
`output_batches` equal what the stream actually produced. It fails on
`main` with `(2, 4)` vs `(1, 3)`.
## Are there any user-facing changes?
`output_rows` / `output_batches` reported for `PartitionedTopKExec` with
`fn=rank` are now accurate when ties are present. No API changes.1 parent 7570366 commit 49c0aa3
1 file changed
Lines changed: 42 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1876 | 1876 | | |
1877 | 1877 | | |
1878 | 1878 | | |
1879 | | - | |
1880 | 1879 | | |
1881 | 1880 | | |
1882 | 1881 | | |
| |||
4138 | 4137 | | |
4139 | 4138 | | |
4140 | 4139 | | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
| 4152 | + | |
| 4153 | + | |
| 4154 | + | |
| 4155 | + | |
| 4156 | + | |
| 4157 | + | |
| 4158 | + | |
| 4159 | + | |
| 4160 | + | |
| 4161 | + | |
| 4162 | + | |
| 4163 | + | |
| 4164 | + | |
| 4165 | + | |
| 4166 | + | |
| 4167 | + | |
| 4168 | + | |
| 4169 | + | |
| 4170 | + | |
| 4171 | + | |
| 4172 | + | |
| 4173 | + | |
| 4174 | + | |
| 4175 | + | |
| 4176 | + | |
| 4177 | + | |
| 4178 | + | |
| 4179 | + | |
| 4180 | + | |
| 4181 | + | |
4141 | 4182 | | |
4142 | 4183 | | |
4143 | 4184 | | |
| |||
0 commit comments