Repository navigation
Commit c280a4b
authored
Fix GroupOrdering memory descriptor double-counting (apache#26074)
## Which issue does this PR close?
- Part of apache#23393
## Rationale for this change
`GroupOrdering::size()` currently counts both the outer enum descriptor
and the inline active variant descriptor. Because the active variant is
stored inside `GroupOrdering`, this double-counts inline memory for
partial and full ordering states.
This change makes the `GroupOrdering` enum the single owner of the
descriptor charge. Partial ordering continues to include retained
`order_indices` capacity and state-owned allocations, while full
ordering adds no additional descriptor charge.
## What changes are included in this PR?
- Make `GroupOrdering::size()` charge `size_of::<GroupOrdering>()`
exactly once for `None`, `Partial`, and `Full`.
- Rename `GroupOrderingPartial::size()` to `heap_size()` and make it
report only:
- retained `order_indices` allocation
- allocations owned by the partial ordering state
- Remove `GroupOrderingFull::size()`, since full ordering has no
additional heap allocation to add beyond the outer enum descriptor.
- Document the ownership boundary in `GroupOrdering::size()` and
`GroupOrderingPartial::heap_size()`.
- Add deterministic size-accounting tests for none, full, and partial
ordering states.
## Are these changes tested?
Yes. This PR adds:
- `test_size_none`, which verifies that `GroupOrdering::None` reports
exactly `size_of::<GroupOrdering>()`.
- `test_size_full`, which verifies that full ordering reports exactly
one `GroupOrdering` descriptor before and after `new_groups`,
`remove_groups`, `input_done`, and `reset`.
- `test_size_partial_retained_allocations`, which verifies that:
- grown-and-truncated `order_indices` capacity remains charged
- a variable-width `ScalarValue::Utf8` sort key is included in the
reported size
- replacing the sort key charges the replacement rather than retaining
the old key
- `input_done` and `reset` drop state-owned key allocations while
retaining the `order_indices` capacity
- repopulating the state causes the key allocation to be charged again
The tests use deterministic `size_of`, vector capacity, and
`ScalarValue::size()` expectations rather than allocator-observed byte
counts.
## Are there any user-facing changes?
No public API changes are introduced.
This changes internal memory accounting reported by
`GroupOrdering::size()` so that inline descriptor memory is no longer
double-counted. Grouping and aggregation behavior is otherwise unchanged
by this patch.
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated
content has been manually reviewed.1 parent 07077ff commit c280a4b
3 files changed
Lines changed: 47 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
143 | 142 | | |
144 | 143 | | |
145 | 144 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 145 | | |
151 | 146 | | |
152 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
154 | | - | |
155 | | - | |
156 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
157 | 160 | | |
158 | 161 | | |
159 | 162 | | |
| |||
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
167 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
168 | 206 | | |
169 | 207 | | |
170 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | | - | |
| 104 | + | |
106 | 105 | | |
107 | 106 | | |
108 | 107 | | |
| |||
267 | 266 | | |
268 | 267 | | |
269 | 268 | | |
270 | | - | |
271 | | - | |
272 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| |||
0 commit comments