Commit 2028927
authored
fix: sliding window
## Which issue does this PR close?
- Closes #23872
## Rationale for this change
`SlidingMinAccumulator::update_batch` skipped NULL values. This meant
that if all the non-NULL values in a window frame were retracted, the
window frame would not be empty but the `MovingMin` data structure by
the `SlidingMinAccumulator` would not contain any values. This resulted
in incorrectly returning a stale non-NULL value for a sliding `min()`
over a window frame consisting of only NULL values.
Along the way, optimize the min and max sliding window accumulators to
make them both more efficient and more symmetric with one another. In
the original coding, `SlidingMaxAccumulator` included NULL values but
`SlidingMinAccumulator` omitted them, in part because omitting NULLs
made the original `retract_batch` implementation more expensive. This PR
optimizes `retract_batch`, so we can now use the same scheme for both
the min and max sliding accumulators:
* Omit NULLs on `update_batch` (this improves on the prior behavior of
`max`)
* Efficiently account for NULLs in `retract_batch` (this improves on the
prior behavior of `min`)
* Ensure correct results for all-NULL window frames (this fixes the
prior bug in `min`).
## What changes are included in this PR?
* Fix bug in `min()` over all-NULL window frames
* Optimize `SlidingMinAccumulator::retract_batch` (avoid materializing
values just to count NULLs)
* Optimize `SlidingMinAccumulator::update_batch` (omit NULLs), also
improving symmetry with `min`
* Optimize both accumulators to stop caching the current `min` / `max`;
this saves a few clones, but perhaps more importantly it is simpler and
avoids the risk of inconsistency between the cached value and the
underlying `MovingMin` / `MovingMax` data structure
## Are these changes tested?
Yes, new tests added.
## Are there any user-facing changes?
No, aside from the bug fix.min() returns wrong value for all-NULL windows (#23874)1 parent 9ab2068 commit 2028927
2 files changed
Lines changed: 111 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
384 | | - | |
| 384 | + | |
| 385 | + | |
385 | 386 | | |
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
389 | 390 | | |
390 | 391 | | |
391 | 392 | | |
392 | | - | |
| 393 | + | |
393 | 394 | | |
394 | 395 | | |
395 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
396 | 404 | | |
397 | 405 | | |
398 | 406 | | |
399 | 407 | | |
400 | 408 | | |
401 | 409 | | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
406 | 413 | | |
407 | 414 | | |
408 | 415 | | |
409 | 416 | | |
410 | 417 | | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
416 | 425 | | |
417 | 426 | | |
418 | 427 | | |
| |||
422 | 431 | | |
423 | 432 | | |
424 | 433 | | |
425 | | - | |
| 434 | + | |
426 | 435 | | |
427 | 436 | | |
428 | 437 | | |
429 | | - | |
| 438 | + | |
430 | 439 | | |
431 | 440 | | |
432 | 441 | | |
433 | 442 | | |
434 | 443 | | |
435 | 444 | | |
436 | 445 | | |
437 | | - | |
438 | | - | |
| 446 | + | |
| 447 | + | |
439 | 448 | | |
440 | 449 | | |
441 | 450 | | |
| |||
667 | 676 | | |
668 | 677 | | |
669 | 678 | | |
670 | | - | |
| 679 | + | |
| 680 | + | |
671 | 681 | | |
672 | 682 | | |
673 | 683 | | |
674 | 684 | | |
675 | 685 | | |
676 | 686 | | |
677 | | - | |
| 687 | + | |
678 | 688 | | |
679 | 689 | | |
680 | 690 | | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
681 | 698 | | |
682 | 699 | | |
683 | 700 | | |
684 | 701 | | |
685 | | - | |
| 702 | + | |
686 | 703 | | |
687 | 704 | | |
688 | 705 | | |
| |||
692 | 709 | | |
693 | 710 | | |
694 | 711 | | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | 712 | | |
699 | 713 | | |
700 | 714 | | |
701 | 715 | | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
710 | 723 | | |
711 | 724 | | |
712 | 725 | | |
| |||
716 | 729 | | |
717 | 730 | | |
718 | 731 | | |
719 | | - | |
| 732 | + | |
720 | 733 | | |
721 | 734 | | |
722 | 735 | | |
723 | 736 | | |
724 | 737 | | |
725 | 738 | | |
726 | 739 | | |
727 | | - | |
728 | | - | |
| 740 | + | |
| 741 | + | |
729 | 742 | | |
730 | 743 | | |
731 | 744 | | |
| |||
1193 | 1206 | | |
1194 | 1207 | | |
1195 | 1208 | | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
1196 | 1261 | | |
1197 | 1262 | | |
1198 | 1263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6842 | 6842 | | |
6843 | 6843 | | |
6844 | 6844 | | |
| 6845 | + | |
| 6846 | + | |
| 6847 | + | |
| 6848 | + | |
| 6849 | + | |
| 6850 | + | |
| 6851 | + | |
| 6852 | + | |
| 6853 | + | |
| 6854 | + | |
| 6855 | + | |
| 6856 | + | |
| 6857 | + | |
| 6858 | + | |
0 commit comments