Repository navigation
Preserve constant columns of ActionsDAG input nodes in serialization - #107124
Conversation
`ActionsDAG::serialize` skipped the column for all `INPUT` nodes. However,
inputs can legitimately carry a constant column: lambda capture DAGs reference
constants from the enclosing DAG as inputs with a pre-set constant column (see
`addInputConstantColumnIfNecessary` in `PlannerActionsVisitor`). On
deserialization every function node is re-resolved, and functions that require
constant arguments - e.g. `tupleElement` produced by tuple element access
`t.2` inside `arrayMap(t -> t.2, ...)` - threw `ILLEGAL_TYPE_OF_ARGUMENT`
("Second argument to tupleElement must be a constant Int, UInt or String").
Serialize the column for any node that has one. The format stays
self-describing through the existing per-node `column_flags`, so the change is
wire-compatible in both directions.
This blocks the query plan cache for complex queries, which round-trips plans
containing lambda captures; covered by a unit test that fails without the fix.
Co-Authored-By: Claude Fable 5 <[email protected]>
337f9a3 to
65ee574
Compare
|
Workflow [PR], commit [c0aeba1] Summary: ✅
AI ReviewSummaryThis PR preserves constant columns on Final VerdictStatus: ✅ Approve |
|
We need a functional test, not a unit test. |
…t-constant-serialization
Per review feedback, cover the fix with a functional test instead of a
unit test.
`04338_actions_dag_input_constant_serialization` exercises the bug end to
end: with `serialize_query_plan = 1` and a `remote(...)` shard, a lambda
that contains `tupleElement` (e.g. `arrayMap(t -> t.2, ...)`) ships its
capture DAG to the shard, where the plan is deserialized and every
function node is re-resolved via `IFunctionOverloadResolver::build`. The
constant tuple index lives on an `INPUT` node of the capture DAG; before
the fix its column was dropped during serialization, so `tupleElement`
re-resolution on the shard failed with:
Code: 43. Second argument to tupleElement must be a constant Int,
UInt or String. (ILLEGAL_TYPE_OF_ARGUMENT)
The array is built from `number` so the lambda is evaluated on the shard
(a fully constant array is folded away before serialization). Verified
that all four queries fail without the fix and pass with it.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Replaced the unit test with a functional test While writing it I found the bug is not actually masked by a fallback as the description originally claimed — any distributed query with SET serialize_query_plan = 1, prefer_localhost_replica = 0;
SELECT arrayMap(t -> t.2, [(number, 'a'), (number + 1, 'b')]) FROM remote('127.0.0.1', numbers(3));
-- Code: 43. Second argument to tupleElement must be a constant Int, UInt or String. (ILLEGAL_TYPE_OF_ARGUMENT)The test runs four such query shapes over |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 4/4 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code |
ActionsDAG::serializeskipped the column for allINPUTnodes:However,
INPUTnodes can legitimately carry a constant column: lambda capture DAGs reference constants from the enclosing DAG as inputs with a pre-set constant column (seeaddInputConstantColumnIfNecessaryinPlannerActionsVisitor). When such a DAG is deserialized, every function node is re-resolved viaIFunctionOverloadResolver::build, and functions that require constant arguments —tupleElementproduced by tuple element accesst.2inside a lambda being the simplest example — throw:This is reachable today by any distributed query with
serialize_query_plan = 1whose projection contains a lambda with a constant argument that is evaluated on the shard, e.g.:The initiator serializes the plan and ships it to the shard, where the capture DAG is deserialized and
tupleElementis re-resolved without its constant index, so the query fails. (The array must depend on the row; a fully constant array is folded away before serialization.) The setting is off by default, so stable releases are not affected unless it is enabled; it is also a prerequisite for the upcoming query plan cache, which round-trips plans containing lambda captures on every cache hit.The fix serializes the column for any node that has one. The format remains self-describing through the existing per-node
column_flags, so old readers handle new bytes and vice versa.Covered by
04338_actions_dag_input_constant_serialization, a functional test that runs the above query shapes overremote(...)withserialize_query_plan = 1; each one fails without the fix and passes with it.Related: #99309
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix an
ILLEGAL_TYPE_OF_ARGUMENTerror for distributed queries withserialize_query_plan = 1that contain a lambda with a constant argument (e.g.arrayMap(t -> t.2, ...)). Constant columns ofActionsDAGINPUTnodes are now preserved during query plan serialization.Documentation entry for user-facing changes
Version info
26.6.1.784