Repository navigation
Extract reusable ActionsDAG lineage computation into actionsDAGUtils - #114824
Conversation
Add a reusable lineage computation to actionsDAGUtils that traces every `ActionsDAG` output to at most one input via iterative, memoized traversal. Each hop is classified as `Identity`, `ValuePreserving`, or the weaker `DistinctValuesBound` (output NDV bounded by input NDV plus `ndv_delta`), and results are keyed by input/output positions, so they stay unambiguous under duplicated column names. Rewire `remapColumnStats` in the join-order optimizer onto the new API, replacing its hand-rolled `propagatesNdv`/`backTrackColumnsInDag` walk. Skip the lineage walk entirely when there are no column stats to remap, since statistics are usually absent.
|
Workflow [PR], commit [9463d80] Summary: ✅
AI ReviewSummaryThis PR extracts reusable Findings
Final VerdictChanges requested: the reusable lineage API still overclaims LLVM Coverage ReportMeasured on commit 9463d80.
Changed lines: Changed C/C++ lines covered: 200/200 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes4 object files changed (-14.09 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units17 translation units recompiled, 130 s compile time in total, 17 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
| else if (node.children.size() == 1 && node.function_base->isDeterministic()) | ||
| kind = ActionsDAGLineageKind::DistinctValuesBound; | ||
| else | ||
| return {}; |
There was a problem hiding this comment.
remapColumnStats previously used equivalent logic to determine whether an NDV bound propagates through a hop. The new lineage kinds retain stronger semantic information by distinguishing Identity, ValuePreserving, and DistinctValuesBound. remapColumnStats currently treats ValuePreserving and DistinctValuesBound equivalently because it only consumes input_position and ndv_delta.
| || child->kind == ActionsDAGLineageKind::ValuePreserving) | ||
| kind = ActionsDAGLineageKind::ValuePreserving; | ||
| result = ActionsDAGInputLineage{child->input_position, kind, child->ndv_delta + hop->ndv_delta}; | ||
| } |
There was a problem hiding this comment.
remapColumnStats previously followed only children[0], so this preserves existing behavior. As a follow-up, add a child position to ActionsDAGLineageHop for multi-argument functions with one value-bearing child.
Supporting genuinely multi-source functions requires more than a set of child positions: the lineage result must represent multiple inputs and the hop must specify how their NDV bounds are composed. The composition logic currently around line 622 could then be extracted into a dedicated helper.
ActionsDAG lineageActionsDAG lineage computation into actionsDAGUtils
| @@ -294,6 +295,59 @@ TEST(ColumnStatsDerivation, DeepChainOfFunctionsResolves) | |||
| /// The bound propagates through a chain of deterministic single-argument functions: no link can | |||
| /// increase the distinct count, so the final output is still bounded by the source column. A | |||
| /// multi-argument link anywhere in the chain breaks the propagation. | |||
There was a problem hiding this comment.
I think this description is related to the test that was already in the file, maybe move it to the right place and add a specific description for this new test case.
There was a problem hiding this comment.
Oh, that one indeed belongs to ChainOfFunctionsPropagatesBound. Moved the comment back to it's front: e757ead
diegomestre2
left a comment
There was a problem hiding this comment.
Hi @cv4g , great work! The code is clean and straight to the point. I really like the trick with memoization. I left a few questions and comments, feel free to implement what you think makes sense. Once you are ready I can take a final look.
| kind = ActionsDAGLineageKind::ValuePreserving; | ||
| else if (function_name == "_CAST" || function_name == "CAST") | ||
| kind = ActionsDAGLineageKind::DistinctValuesBound; | ||
| else if (node.children.size() == 1 && node.function_base->isDeterministic()) |
There was a problem hiding this comment.
This generic isDeterministic() bucket is too broad for the new reusable API. assumeNotNull is unary and deterministic, but its contract is explicitly weaker than "NDV <= input_ndv + 1": the docs say a NULL input may yield an arbitrary result, and FunctionAssumeNotNull::executeImpl just returns the nested column (src/Functions/assumeNotNull.cpp), so different NULL rows can surface different underlying values. That means traceActionsDAGLineage can now report a false DistinctValuesBound for nullable inputs, even though the exported type/comment presents it as a real proof for future callers. I think assumeNotNull (and any similar nullable-stripping wrappers with arbitrary null semantics) needs to be excluded from this generic branch or handled separately, with a focused regression test here.
There was a problem hiding this comment.
Let's address this in a follow-up PR. This PR prepares for re-use but should preserve the current behavior in order to make sure that remapColumnStats does not change too much. Having the re-usable API surface, we can then start opening pull requests to introduce additional call sites and follow up improvements concurrently.
diegomestre2
left a comment
There was a problem hiding this comment.
Thanks for addressing the comments and for the replies. Everything looks clear now. Feel free to merge it once CI is ready! Great work! It was fun to review it!
|
Pushed another merge commit. No conflicts but want to be sure no other issues arised due to changes merged in the meantime |
The new
traceActionsDAGLineagecomputes lineage for everyActionsDAGoutput using iterative traversal with memoization shared across all output roots. Each output is traced to at most one input through supported hops. Hops are classified as:IdentityValuePreservingDistinctValuesBound, meaning output NDV is bounded by input NDV plusndv_deltaInputs and outputs are identified by position rather than column name, so the reusable lineage result remains unambiguous when names are duplicated.
remapColumnStatsin the join-order optimizer now uses this API instead of its localdescribeValueHop/backTrackColumnsInDagtraversal.This changes the call site as follows:
ActionsDAG, with memoization shared across all outputs, instead of running an independent DFS for every statistics entry.The lineage-related complexity changes from approximately
O(#stats × DAG)toO(DAG + #outputs), with the remaining statistics-map handling linear in the number of entries.For outputs that can be represented unambiguously by the name-keyed statistics map, the computed statistics remain unchanged. The supported-hop and
ndv_deltarules are equivalent to the previous implementation: nullable-to-non-nullable hops may add one distinct value, and the existing overflow guard remains in place.remapColumnStatsdoes not currently distinguish between lineage kinds; it only usestraceability,input_position, andndv_delta.The reusable API handles duplicate names positionally.
remapColumnStatsitself remains keyed by column name and therefore cannot represent separate statistics for conflicting duplicate output names.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Workflow [PR]
Sync PR [sync-upstream/pr/114824]
Version info
26.9.1.257(included in26.9and later)