Commit 9867814
authored
Drop velocity-based estimation in favor of driver path completion estimation (#552)
## Summary
Replaces the **velocity-based** runtime-statistics estimate used by the
dynamic task-count planner with a **driver-path completion** estimate.
The sampler on top of each stage feeds statistics (final row/byte
counts) back to the coordinator, which uses them to size the stage
above. The old estimate extrapolated those final sizes from a sampled
throughput multiplied by a fixed, assumed query duration, which
systematically overestimated — often by orders of magnitude. The new
estimate instead scales what a stage has already produced by how far it
is through its *known* total work.
## How it worked before
The `SamplerExec` reported, per partition:
- `*_ready` — rows / bytes already materialized at sampling time, and
- `*_per_second` — a sampled production **velocity** (rows/bytes per
second).
`gather_runtime_statistics` extrapolated the final size as:
```text
total_rows = rows_ready + rows_per_second * ESTIMATED_QUERY_TIME_S // = 10
total_bytes = bytes_ready + bytes_per_second * ESTIMATED_QUERY_TIME_S
```
i.e. *"what's ready now, plus the sampled rate projected over 10 more
seconds of execution."*
While doing some benchmarks, I've seen that this approach heavily
over-estimates row count.
## How the new estimate avoids it
Instead of projecting a velocity over a made-up duration, it computes an
actual **completion fraction** and divides by it:
```text
pct_completed = rows_pulled_from_leaf / estimated_driver_path_leaf_rows
total_rows = rows_ready / pct_completed
total_bytes = bytes_ready / pct_completed
```
- `rows_pulled_from_leaf` — how many rows the stage has actually pulled
from its leaf scans so far (now reported by the sampler in place of the
velocity fields).
- `estimated_driver_path_leaf_rows` — the total number of rows the stage
must pull to finish, obtained by summing the leaf `num_rows` statistics
along the **driver path**: the probe-side chain that actually streams to
the output. Join build sides are excluded because they are one-off setup
work, not output progress (see the new `apply_driver_path` helper).
These counts come from real source statistics (e.g. parquet row counts).
## Caveats
If a stage's leaves expose no row-count statistics, it falls back to a
fixed `FALLBACK_ESTIMATED_PCT_SAMPLED = 0.2` (assume ~20 % sampled).
## Benchmarks
TPCH-SF1: 1.02 faster
TPCH-SF10: 1.04 faster
TPCH-SF100: 1.01 faster
TPC-DS-SF1: 1.01 slower
ClickBench: 1.01 slower
Performance is not impacted because both in `main` and this PR max out
on tasks for a cluster of 12 workers.
Regarding q-error on stats estimation, here are the results:
TPCH-SF1:
QERR P50: prev=1.80x, new=1.80x
QERR P95: prev=6.75x, new=2.29x
TPCH-SF10:
QERR P50: prev=1.80x, new=1.45x
QERR P95: prev=8.94x, new=2.12x
TPCH-SF100:
QERR P50: prev=2.12x, new=1.73x
QERR P95: prev=9.68x, new=2.16x
TPC-DS-SF1:
QERR P50: prev=1.54x, new=1.45x
QERR P95: prev=4.62x, new=4.01x
ClickBench:
QERR P50: prev=1.42x, new=1.45x
QERR P95: prev=1.42x, new=1.45x1 parent fb7b8c5 commit 9867814
13 files changed
Lines changed: 416 additions & 193 deletions
File tree
- benchmarks/cdk/bin
- src
- common
- coordinator
- distributed_planner
- execution_plans
- metrics
- protocol
- grpc
- generated
- worker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
| 198 | + | |
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
29 | 60 | | |
30 | 61 | | |
31 | 62 | | |
32 | 63 | | |
33 | 64 | | |
34 | | - | |
35 | 65 | | |
36 | 66 | | |
37 | 67 | | |
| |||
62 | 92 | | |
63 | 93 | | |
64 | 94 | | |
65 | | - | |
66 | 95 | | |
67 | 96 | | |
68 | 97 | | |
| |||
104 | 133 | | |
105 | 134 | | |
106 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
107 | 162 | | |
108 | 163 | | |
109 | 164 | | |
| |||
213 | 268 | | |
214 | 269 | | |
215 | 270 | | |
216 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
217 | 275 | | |
218 | 276 | | |
| 277 | + | |
219 | 278 | | |
220 | 279 | | |
221 | 280 | | |
| |||
348 | 407 | | |
349 | 408 | | |
350 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
351 | 485 | | |
352 | 486 | | |
353 | 487 | | |
| |||
566 | 700 | | |
567 | 701 | | |
568 | 702 | | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
569 | 711 | | |
570 | 712 | | |
571 | 713 | | |
| |||
581 | 723 | | |
582 | 724 | | |
583 | 725 | | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
584 | 767 | | |
585 | 768 | | |
586 | 769 | | |
| |||
630 | 813 | | |
631 | 814 | | |
632 | 815 | | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
633 | 822 | | |
634 | 823 | | |
635 | 824 | | |
| |||
664 | 853 | | |
665 | 854 | | |
666 | 855 | | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
667 | 879 | | |
668 | 880 | | |
669 | 881 | | |
| |||
0 commit comments