Repository navigation
Commit 0d79252
authored
Fix retained-capacity accounting for grouped byte MIN/MAX (#26154)
## Which issue does this PR close?
- Part of #23393
## Rationale for this change
Grouped byte MIN/MAX accumulators can underreport memory usage because
their accounting is based on the current data length and number of group
slots rather than the memory allocations they retain.
For example, replacing a 128-byte string with a one-byte string reuses
the existing vector allocation, but the previous accounting reports only
the new string length. Similarly, unused capacity in the outer group
vector is not counted.
This change makes memory accounting reflect retained allocations,
providing more accurate memory usage estimates for grouped MIN/MAX
operations.
## What changes are included in this PR?
- Add `total_data_capacity` to `MinMaxBytesState` to track retained
inner `Vec<u8>` capacities independently of `total_data_bytes`, which
remains responsible for output preallocation.
- Update `set_value()` to maintain capacity accounting when values are
inserted, replaced, or cause an existing vector to grow.
- Update `size()` to account for the outer `min_max` vector's capacity
and the cached inner vector capacities, without double-counting the
inline `Option<Vec<u8>>` descriptors.
- Keep `size()` O(1) by maintaining the inner capacity total
incrementally.
- Update `emit_to()` to reset capacity accounting on full emission and
subtract emitted inner vector capacities on partial emission.
## Are these changes tested?
Three regression tests are added:
- `size_counts_outer_capacity`: Verifies that memory accounting includes
allocated outer vector capacity, even when fewer group slots are
initialized.
- `size_retains_inner_capacity`: Tests both MIN and MAX accumulators,
verifying that replacing a long string with a shorter one preserves
retained-capacity accounting and that partial and full emission update
it correctly.
- `size_tracks_growth_and_emit_reuse`: Verifies capacity accounting when
an inner vector grows, groups are partially emitted, and the state is
reused after full emission.
## Are there any user-facing changes?
No changes to SQL MIN/MAX results or public APIs are intended.
The change corrects internal memory accounting for grouped byte MIN/MAX
accumulators, allowing retained allocations to be reported more
accurately.
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated
content has been manually reviewed.1 parent 92323f7 commit 0d79252
1 file changed
Lines changed: 83 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
419 | | - | |
420 | | - | |
| 419 | + | |
421 | 420 | | |
| 421 | + | |
| 422 | + | |
422 | 423 | | |
423 | 424 | | |
424 | 425 | | |
| |||
433 | 434 | | |
434 | 435 | | |
435 | 436 | | |
| 437 | + | |
436 | 438 | | |
437 | 439 | | |
438 | 440 | | |
439 | 441 | | |
440 | 442 | | |
441 | 443 | | |
442 | 444 | | |
443 | | - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
444 | 448 | | |
445 | 449 | | |
446 | 450 | | |
447 | 451 | | |
448 | 452 | | |
449 | 453 | | |
| 454 | + | |
450 | 455 | | |
451 | 456 | | |
| 457 | + | |
452 | 458 | | |
453 | 459 | | |
454 | 460 | | |
| |||
509 | 515 | | |
510 | 516 | | |
511 | 517 | | |
512 | | - | |
| 518 | + | |
513 | 519 | | |
514 | | - | |
| 520 | + | |
515 | 521 | | |
516 | 522 | | |
517 | 523 | | |
518 | 524 | | |
| 525 | + | |
519 | 526 | | |
520 | 527 | | |
521 | 528 | | |
522 | 529 | | |
523 | 530 | | |
524 | 531 | | |
525 | 532 | | |
526 | | - | |
| 533 | + | |
527 | 534 | | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
532 | 542 | | |
533 | 543 | | |
534 | 544 | | |
535 | 545 | | |
536 | 546 | | |
537 | | - | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
538 | 550 | | |
539 | 551 | | |
540 | 552 | | |
| |||
543 | 555 | | |
544 | 556 | | |
545 | 557 | | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
546 | 618 | | |
547 | 619 | | |
548 | 620 | | |
| |||
0 commit comments