Repository navigation
fix(graph): an allocation failure while building a query plan answers oom, not a crash, nyi or memory kept - #1820
Open
singaraiona wants to merge 1 commit into
Open
singaraiona wants to merge 1 commit into
singaraiona wants to merge 1 commit into
Conversation
singaraiona
force-pushed
the
fix/1817-group-build-oom
branch
from
November 27, 2026 07:33
9354fe9 to
4e05e20
Compare
singaraiona
commented
Nov 27, 2026
singaraiona
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review of 4e05e20: NEEDS CHANGES
The parted per-partition crash from #1812 is fixed, and a recorded failure never reaches a later query. Plan building for where: + by: and for joins still crashes under a single allocation failure, and a plain by: keeps 640 bytes on early failures.
Method
I added a local seam, never pushed: the nth ray_alloc of the whole query fails on any thread, every position swept once. The table is 3,000 rows with 4 pool threads, and the parted copy has 3 partitions.
- Each failed run must answer
oomwithnet_bytes <= 0(ray_mem_trace, every heap, after release and GC), or an answeridenticalto the unfailed one. - After every run, the same query runs again unfailed on the same thread and must equal the reference. That is the check that a recorded failure is cleared.
Findings
where:+by:still crashes in the select planner.(select {c: (sum v) from: F where: (> v 100) by: j})takes a SIGSEGV atquery.c:29216:uint32_t where_input_id = root->id;withrootNULL. The table node (ray_const_table) failed to allocate, andray_select_bodyuses it beforeray_executecould answer the recordedoom. This is the NULL-root crash I listed in the #1809 review; the planner needs the same check onrootthatray_execute_innernow has. The same query over the parted table crashes the same way.- A join crashes on a failed input node.
(inner-join F G ['j])takes a SIGSEGV inray_join(called fromjoin_exec,query.c:41486) withleft_table == NULL. Onlyray_group_buildgained the NULL-input refusal.ray_join,ray_antijoin,ray_asof_join,ray_sort_op,ray_window_op,ray_select_opandray_pivot_opnow record a failed id carve, but they still readkeys[i]->idand the table inputs without a NULL check. I did not sweep the left join or the sort after this crash. - A plain
by:keeps 640 bytes on early failures. In(select {c: (sum v) from: F by: j}), 18 of the 30oompositions (from n=7 on) keep 640 bytes by the trace. The partedby: jand the two-keyby: [j s]show the same (18 and 21 positions). This is before the group runs; the #1809 review saw the same 576-640 bytes in the whole-query sweep. Not introduced here, but it is in plan building, which this PR is about.
What is right
- Parted per-partition group (
select … from: P by: j, 136 positions): every failure answersoomor the unfailed answer, apart from the bytes in item 3. No crash and nonyi; #1812's SIGSEGV inray_group_buildis gone. by: jandby: [j s]in memory:oomor the unfailed answer, no crash, nonyi(bytes as in item 3).- The record is cleared. It is per graph (
g->compile_err, freed in the graph's free,graph.c:178) and handed over byray_execute_inner. In all three sweeps the healthy re-run after every failed one answered the reference: 0 stale. - Uninjected: release builds of this head and dev 84408f0,
-c 1, 200,000 rows:by:,where:+by:, two keys,inner-join, a group over a join, andmaxby an F64 key. Theserof all results is identical. Callgrind totals are 1,110,219,265 against 1,110,219,042 (+223 over the script). - Runs:
- gcc
make -j4 test TEST_ARGS="-j 4": 5899 of 5903 passed, 4 skipped, 0 failed; - ASan+UBSan: the aware tests this head touches (
group_build_alloc_fail,group_parted_alloc_fail,group_alloc_fail,group_fallback_order,group_sym_key_nulls_flag,holistic_oom,radix_cancel_keeps_nothing,sel_compact_cancel_at_dispatch) and-f group/98/98, no sanitizer report.
- gcc
Not covered (about 30 minutes)
- The left join, the group over a join, and the sort-only select: the join crash stopped my sweep before them.
- Keyless selects and windows.
- TSan.
- Whether item 3's 640 bytes are the plan or the parse: I did not trace which allocation keeps them.
… oom, not a crash, nyi or memory kept A plan built while an allocation failed crashed, answered nyi, or kept memory: - The graph builders read the id and type of every input node they were given. A node that failed to build is NULL, so a group, join, filter, sort, window or select node over it was read through NULL: the parted per-partition group took a SIGSEGV in ray_group_build, inner-join one in ray_join. ray_select_body read the root that ray_const_table gave unchecked, and the deferred where: read a take's head unchecked. - A plan whose root is NULL answered nyi: the node allocators record their failure in g->compile_err, but ray_execute did not read it, and the builders' own scratch carves recorded none. - A failure the engine answers by another route kept the failure's error object, which ray_release does not free: the v2 serial group's result table and aggregate column, the expression bridge's extended table, the per-partition group's sub, merge and trimmed tables and its merge result, and the fused top-k's gathered column. A failed span table (ray_nfo_create) was an error the evaluator handed to the parser and kept, and a span whose append failed left an error in the table. The factorized group shortcut released a table that a failed ray_table_add_col had already consumed. Every graph builder refuses a NULL input node and answers NULL (a NULL array holds none): the failure is the one already recorded, and a plan built under it ends in a NULL root. The builders record a failed scratch carve, and ray_execute answers a NULL root with the graph's compile error when there is one. The select's root and the deferred where:'s head are checked. Each dropped error is freed or answered, ray_nfo_create answers NULL (no spans) when a part fails, and a span whose append fails is not recorded. aware/plan_alloc_fail and aware/group_build_alloc_fail fail the nth allocation of the evaluation, every n, of eighteen select and join shapes: on the calling thread, then on its pool tasks too, then with the parse included. Every run answers the unfailed answer (grouped ones in key order) or oom, keeping nothing either way. aware/group_parted_alloc_fail sweeps the group seam over three per-partition groups, and aware/group_alloc_fail now also sweeps the slice-group route and the keyless whole-table route. Fixes #1817
singaraiona
force-pushed
the
fix/1817-group-build-oom
branch
from
November 27, 2026 08:02
4e05e20 to
ffcb87c
Compare
Collaborator
Author
|
Thanks. The rule is now general, in this pull request, at ffcb87c:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The defect
A query plan built while an allocation failed crashed, answered the wrong error, or kept memory (#1817; the review of #1812 found the first case, and the review of this pull request found the general one):
ray_group_build(the parted per-partition group);ray_join(inner-join);ray_select_bodyatroot->id, whenray_const_tablefailed under awhere:;where:read a take's head unchecked.nyiinstead ofoom. A plan whose root is NULL answerednyi. The node allocators record their failure ing->compile_err, butray_executedid not read it, and the builders' own scratch carves recorded nothing.ray_releasedoes not free:agg_run_one);exec_group_v2_exprs_run);ray_nfo_createwas an error object, which the evaluator handed to the parser as its span table and kept. A span whose append failed left an error in the table.ray_table_add_colhad already consumed.The fix: one rule for every builder
graph_ins_ok); a NULL array holds none.ray_executeanswers that root with the graph's compile error (oom), andnyionly when nothing was recorded, as before.a->out_type(most of the one-liners) checks before it. The others pass the input tomake_unary,make_binaryormake_cmp, which check it.make_unary,make_unary_param,make_binary,ray_neg,ray_abs,ray_not,ray_sqrt_op,ray_log_op,ray_exp_op,ray_sin_op,ray_asin_op,ray_cos_op,ray_acos_op,ray_tan_op,ray_atan_op,ray_reciprocal_op,ray_signum_op,ray_ceil_op,ray_floor_op,ray_round_op,ray_isnull,ray_cast,make_cmp,ray_binop,ray_add,ray_sub,ray_mul,ray_div,ray_idiv,ray_mod,ray_pow_op,ray_eq,ray_ne,ray_lt,ray_le,ray_gt,ray_ge,ray_and,ray_or,ray_min2,ray_max2,ray_in,ray_not_in,ray_if,ray_like,ray_ilike,ray_upper,ray_lower,ray_strlen,ray_trim_op,ray_str_find_op,ray_substr,ray_replace,ray_concat,ray_sum,ray_prod,ray_all,ray_any,ray_min_op,ray_max_op,ray_count,ray_avg,ray_first,ray_last,ray_count_distinct,ray_distinct_op,ray_asc_op,ray_desc_op,ray_reverse_op,ray_lag_op,ray_lead_op,ray_deltas_op,ray_ratios_op,ray_fills_op,ray_sums_op,ray_avgs_op,ray_mins_op,ray_maxs_op,ray_prds_op,ray_differ_op,ray_msum_op,ray_mavg_op,ray_mmin_op,ray_mmax_op,ray_mcount_op,ray_mvar_op,ray_mdev_op,ray_stddev,ray_stddev_pop,ray_var,ray_var_pop,ray_median,ray_filter,ray_sort_op,ray_group_build,ray_group,ray_distinct,ray_pivot_op,ray_join,ray_antijoin,ray_asof_join,ray_window_op,ray_select_op,ray_head,ray_tail,ray_extract,ray_date_trunc,ray_expand,ray_var_expand,ray_shortest_path,ray_dijkstra,ray_dfs,ray_random_walk,ray_astar,ray_k_shortest,ray_ann_rerank,ray_knn_rerank.ray_const_table, the whole-graph algorithms; no node inputs) already recorded a failed node or literal allocation:graph_alloc_node,ray_scan,ray_scan_sym,ray_const_f64,ray_const_i64,ray_const_bool,ray_const_str,ray_const_vec,ray_const_atom,ray_const_table,ray_scan_table,ray_pagerank,ray_connected_comp,ray_louvain,ray_degree_cent,ray_topsort,ray_wco_join,ray_cluster_coeff,ray_betweenness,ray_closeness,ray_mst,ray_graph_input_vec.ray_select_bodychecks its root and the deferredwhere:'s head. A scan of every builder call outsidegraph.cfor a dereference of its result before a NULL check finds no other.ray_nfo_createanswers NULL (no spans) when a part fails, and a span whose append fails goes unrecorded, with its key taken back.What the review's 640 bytes were
The sweeps clear the trace before they measure.
Tests
aw_sweep_evalfails the nth allocation of an evaluation, every n it reaches, in three modes: the parsed query on the calling thread, the same with its pool tasks failing too, and the text with the parse included. Every run must answer the unfailed answer (grouped ones in key order: a failed dense route falls back in first-seen order, #1819) oroom. Either way it must keep nothing by the process's allocation trace: an answered run is released before it is measured.aware/plan_alloc_fail(new):by: kandby: [k j];take:;max/avg;sums,mavg);inner-joinandleft-join;inner-join.aware/group_build_alloc_fail: its eleven in-memory and parted shapes now run through the same sweep, so leaks and pool tasks are checked too.aware/group_parted_alloc_fail: the group seam over three per-partition groups.aware/group_alloc_fail: also sweeps the slice-group route and the keyless whole-table route.where:shapes (where:+by:, sorted, keyless and window selects under awhere:, on in-memory, splayed, compressed and parted tables) are swept in sel_compact hands back the whole table when its row index fails to allocate, and some callers answer from the dropped rows #1818, stacked on this. Its own fixes (the row-selection builder's abort, the "every row" selection) are needed before awhere:survives a failure. Without this pull request's root check, that sweep takes theray_select_bodySIGSEGV.Each fix is needed. Each was undone in turn, and the sweeps then fail:
plan_alloc_failtakes a SIGSEGV;The factorized shortcut's double release, and the sibling
agg_run_oneexit, are fixed by reading; no sweep reaches them.Cost
Callgrind, release (gcc),
-c 1, against dev (84408f0), with table setup subtracted. Eight queries over 1,048,576 rows and a 200,000 × 50,000-row join: by[k j], keyless, median byj, sort and take, window, inner join, left join, group over join.That is +1,259 instructions in all: a NULL check per builder call while planning. The answers are byte for byte the same as dev's.
Checks
make -j4 test TEST_ARGS="-j 4": 5,900 of 5,904 passed, 4 skipped.cancel: 87 of 88 passed, 1 skipped; no sanitizer report.clang-23 -fsyntax-onlyon every changed C file, with and without-DDEBUG: clean.Fixes #1817