Repository navigation
Description
What happens
When an allocation fails on the dense or sparse direct group route, the group falls back to the hash route. The answer has the same groups and the same values, but in another order. Found in the review of #1812.
The group seam (ray_group_alloc_fail_for_test(n)) on a 70,000-row table, swept over every position:
| Query | Engine | Unfailed order | After the failure | Positions |
|---|---|---|---|---|
(select {s: (sum v) from: F where: (> v 5) by: j}) |
v2 on | 0 1 2 3 4 5 6 (key order) |
6 0 1 2 3 4 5 (first seen: row 6 has j = 6) |
2 |
(select {s: (sum v) from: F where: (> v 5) by: j}) |
v2 off | key order | first seen | 5 |
(select {s: (sum v) from: F by: w}) (50,000 values) |
v2 off | 0 1 2 … |
0 7919 15838 … |
1 |
Every other position gives the unfailed answer or oom. Sorted by the key, the reordered answers equal the unfailed ones.
The mechanism. About ten allocation exits of the direct routes in exec_group_run jump to ht_path:
- the dense-array accumulators (
group.c~19554, ~19650, ~19846); - the product slots (~20323);
- the range count/sum arrays (~20495, ~20504, ~20513);
- the sparse table (~20739, ~20765, ~20810).
The dense route emits groups in key order: a group's slot is the mixed-radix offset of its key tuple. ht_path emits them in first-seen order.
What the docs promise. docs/architecture/pipeline.md: "Without an explicit ordering clause, full grouped results can follow the selected strategy's group order. Use asc: or desc: when result positions matter." Order is not part of the contract today. Still, a query run twice on the same data answers in two orders, depending on whether an allocation failed.
The same thing happens in two other places. In each, a fallback after a failure gives an answer that differs from the unfailed run in bytes, not in values:
- Parted variance. On the per-partition route, a failure the route cannot answer sends
(select {d: (dev w) from: P by: j})to the flattened table, where the variance can differ in its last bit (4.4e-16 at one group). - The has-nulls flag. A failed slice-group route (
exec_group_slices) groups the selection on the v2 serial-dense route. That route marks the SYM key column as having nulls (attrs0x43against0x03). It does the same over a plain, unindexed table, failure or not.
Options
A. Keep the fallback and document it.
- What it does: say in
pipeline.md(and the group section ofselect.md) that the strategy, and so the order, can change when an allocation fails. - Cost: nothing at run time.
- Limit: the order of a result without
asc:/desc:stays unspecified.
B. A failed allocation on a direct route answers oom, not the hash route.
- What it does: change the ~10
goto ht_pathexits above, and the v2 dense route's matching ones. A query then answers in its route's order or not at all. - Cost: small and local, nothing on the unfailed path.
- Limit: a group that the hash route could still have finished now fails.
- That is rare: the dense route's tables are bounded by its slot budget, and the hash route needs memory in proportion to the groups.
- The exception is a wide, sparse key range on many workers, where the per-worker dense accumulators can exceed the hash table.
C. Keep the fallback and put its groups back in the dense route's order.
- What it does: sort the hash route's groups by the offset the dense route would have given them. That means the same key compaction and SYM code order, with nulls in the dense route's null slot.
- Cost: a sort and an index of the groups, allocated on the path that just failed an allocation.
- Limit: it has to reproduce the dense route's slot rule exactly, including its compacted composite keys. Not cheap to get right.
The two other places above would need their own choice: re-sum in the per-partition order, or answer oom; and fix the flag on the serial-dense route.
Activity