Repository navigation
fix(group): a SYM or STR group key is flagged has-nulls only when a key is null - #1821
Conversation
…ey is null ray_group_gather, which builds the key columns of the v2 routes, set RAY_ATTR_HAS_NULLS whenever its source may have nulls. For a text column that is always, since its attrs do not tell, and the settle pass that clears a spurious flag skips text columns. Every SYM or STR key of those routes came back flagged. A failed slice-group route, which groups the selection on the v2 serial-dense route, therefore answered the unfailed values with a key column flagged otherwise. The legacy routes flag a key only when one is null. A text key column is now scanned, one cell per group, and flagged only when a key is null; numeric keys are as before. A failed allocation on a direct group route falls back to the hash route, which emits its groups in first-seen order, and a failed per-partition group falls back to the flattened table, which sums in another order. The order of a result without asc: or desc: follows the strategy, so this stays; pipeline.md now says so. aware/group_sym_key_nulls_flag compares the v2 and legacy answers of four SYM-keyed groups, a null key included, and checks the flag. aware/group_fallback_order sweeps the group seam over two dense-route groups, v2 on and off: every answer is the unfailed one or oom, and sorted by the key the groups and values are the same. Fixes #1819
singaraiona
left a comment
There was a problem hiding this comment.
Review of 46230c3: READY
The flag fix
I probed the key column's attrs with v2 on and off, against dev 3c30dbd. The cases are SYM and STR keys, with and without null keys, in memory and on a splayed table (narrow-width mapped SYM), bare and under where:.
| Key | dev, v2 | this head, v2 |
|---|---|---|
SYM, no null (in memory, by: s and with where:) |
43: flagged, no null |
03: not flagged |
| SYM, no null (splayed) | 40: flagged |
00 |
| SYM with a null key (in memory, splayed) | 43 / 40 |
43 / 40 (flagged, correct) |
| STR, no null | 00 |
00 |
| STR with a null key | 40 |
40 |
So the v2 key column is now flagged exactly when a key is null, for both types and both storages. Numeric keys keep the old branch: flag, then ray_group_key_settle_nulls. GUID, whose nullness rests on the flag, stays on that branch.
aw/group_sym_key_nulls_flag fails on dev's agg_engine.c (key attrs 43) and passes here.
Readers of the flag answer the same. Over SYM keys with and without nulls (2,000 rows, 50 groups) I compared release outputs of dev and this head for:
(sum (nil? k)),distinct,asc:on the result, regrouping the result,in,asc/descof the key;left-joinof the result with a table holding a null key;nil?over STR keys.
All are identical. The only difference is ser of a no-null SYM result, in the key column's attrs byte (0x40 gone), which is the fix itself.
One description nit. "The legacy routes flag a key only when one is null" is not what I see. With v2 off, a SYM or STR key column holding a null is not flagged at all (03 / 00). That is harmless, since text nulls are read from the payload whatever the flag says (ray_vec_is_null), but the sentence overstates it. The two engines still differ in the flag when a key is null.
Docs
The new sentence in pipeline.md matches the code:
- the dense and direct routes fall back to the hash route;
- a failed
exec_group_per_partitionreturns NULL and falls through to the concatenated table (group.c~14322-14335), which sums in another order; - otherwise the groups and values are the same.
It sits next to the existing line that the order without asc:/desc: is the strategy's.
Nothing else changed
The diff against 3c30dbd is agg_engine.c (the 10-line branch above), the docs sentence and the two tests in test_aware.c.
Runs (gcc)
make -j4 test TEST_ARGS="-j 4": 5897 of 5901 passed, 4 skipped, 0 failed.- ASan+UBSan test binary:
group_sym_key_nulls_flag1/1,group_fallback_order1/1,-f group/98/98, no sanitizer report.
Not covered (about 20 minutes)
- The cost claim (+1.4 instructions per group) was not re-measured.
mkdocs.- Parted tables for the flag.
- I did not confirm that
aw/group_fallback_orderreaches the fallback on every build. I relied on the test's own "at least one position takes the hash fallback" assertion.
The defect
#1819 raised three ways an allocation failure changes a group's answer in its bytes. The values stay the same. Two of them are the strategy's order and stay as they are; one was a wrong attribute.
ray_group_gatherbuilds the key columns of the v2 routes.RAY_ATTR_HAS_NULLSwhenever its source may have nulls. For a text column that is always, since its attrs do not tell. The settle pass that clears a spurious flag skips text columns.0x43against0x03), with or without a failure. The legacy routes flag a key only when one is null.asc:ordesc:follows the strategy (A sort after a group on the shared or partitioned dense kernel breaks the documented tie order (4096+ slots) #1678), and a group that can still finish on the other route should finish.The fix
ray_group_gatherscans a text key column, one cell per group, and flags it only when a key is null. Numeric keys are as before.docs/architecture/pipeline.mdnow says that a strategy that cannot allocate its tables falls back to another one, so a failed allocation can change the order of the groups and the last bits of a float aggregate.Tests
aware/group_sym_key_nulls_flagruns four SYM-keyed groups with v2 on and off:by: s,by: sunderwhere: (in s …)and underwhere: (> v 5), and a key holding the null symbol.(select {c: (count v) from: TP by: s}): key attrs 43.aware/group_fallback_ordersweeps the group seam over every position of(select {s: (sum v) c: (count v) from: F where: (> v 5) by: j})and(select {s: (sum v) from: F by: w})(50,000 values), with v2 on and off.oomor, sorted by the key, the unfailed answer byte for byte.Cost
Callgrind, release (gcc),
-c 1, 1,048,576 rows, with table setup subtracted:(select {c: (count v) from: T by: s})(200,000 SYM groups) and(select {c: (sum v) from: T by: x})(10,000 STR groups), one runThat is +297,708 instructions (+0.07%), about 1.4 per group, for the scan of the key column. Nothing is added per row.
Checks
make -j4 test TEST_ARGS="-j 4": 5,897 of 5,901 passed, 4 skipped.clang-23 -fsyntax-onlyonagg_engine.c(with and without-DDEBUG) and ontest_aware.c(-DDEBUG): clean.mkdocs build --strict: clean.Fixes #1819