Skip to content

fix: subtract emitted memory size in MinMaxStructState::emit_to(EmitTo::First) - #27115

Open
dragonknightk wants to merge 1 commit into
apache:mainfrom
dragonknightk:fix-26891-min-max-struct-emit-to
Open

dragonknightk wants to merge 1 commit into
apache:mainfrom
dragonknightk:fix-26891-min-max-struct-emit-to

Conversation

@dragonknightk

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

Grouped max/min over structs with ordered aggregation can fail with Resources exhausted even when the data is small. When groups are emitted, the memory accounting subtracts the row count instead of the byte size, so emitted groups keep being counted.

Specifically, MinMaxStructState tracks the memory of stored values in total_data_bytes via get_array_memory_size(), but EmitTo::First(n) subtracted the len() of the emitted values, which is only 1 per group. Ordered aggregation calls First(n) after every batch, so the reported size grows with the number of groups seen.

What changes are included in this PR?

Subtract get_array_memory_size() of the emitted values instead.

What is the testing strategy for this PR?

Added a sqllogictest in ordered_aggregate_spill.slt that fails with Resources exhausted before the fix and returns the correct result after it, plus a unit test.

Are there any user-facing changes?

No API changes.

…o::First)

Grouped `max`/`min` over structs with ordered aggregation can fail with
Resources exhausted even when the data is small. When groups are
emitted, the memory accounting subtracts the row count instead of the
byte size, so emitted groups keep being counted.

Specifically, `MinMaxStructState` tracks the memory of stored values in
`total_data_bytes` via `get_array_memory_size()`, but
`EmitTo::First(n)` subtracted the `len()` of the emitted values, which
is only 1 per group. Ordered aggregation calls `First(n)` after every
batch, so the reported size grows with the number of groups seen.

Subtract `get_array_memory_size()` of the emitted values instead.

Added a sqllogictest that fails with Resources exhausted before the fix
and returns the correct result after it, plus a unit test.

Closes issue 26891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MinMaxStructState::emit_to(EmitTo::First(n)) subtracts row counts from a byte counter

1 participant