github-actions[bot] commented on code in PR #63974:
URL: https://github.com/apache/doris/pull/63974#discussion_r3601617539
##########
fe/fe-core/src/main/java/org/apache/doris/statistics/query/QueryStatsRecorder.java:
##########
@@ -254,153 +263,272 @@ private static void walkPlan(Plan plan,
Aggregate<?> agg = (Aggregate<?>) plan;
// GROUP BY keys
for (Expression expr : agg.getGroupByExpressions()) {
- recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
}
// Columns consumed by aggregate functions (e.g. k2 in SUM(k2))
for (NamedExpression expr : agg.getOutputExpressions()) {
- recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
+ }
+ // HAVING: link each non-scan-backed aggregate output to its own
inputs, however
+ // computed those already are (e.g. HAVING SUM(x) where x is
itself computed).
+ for (NamedExpression ne : agg.getOutputExpressions()) {
+ if (exprIdToScan.containsKey(ne.getExprId()) || ne instanceof
Slot) {
+ // Bare pass-through output (e.g. two-phase DISTINCT's
merge phase reusing the
+ // local phase's slot) — already linked there;
getInputSlots() on a bare Slot
+ // includes itself, which would self-loop here.
+ continue;
+ }
+ Set<Slot> inputSlots = ne.getInputSlots();
+ if (!inputSlots.isEmpty()) {
+ derivedSlotInputs.put(ne.getExprId(), inputSlots);
+ }
}
}
if (plan instanceof AbstractPhysicalSort) {
for (OrderKey orderKey : ((AbstractPhysicalSort<?>)
plan).getOrderKeys()) {
- recordInputSlotsAsQueryHit(orderKey.getExpr(), exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(orderKey.getExpr(), exprIdToScan,
exprIdToColName, deltas,
+ derivedSlotInputs);
}
}
// PhysicalPartitionTopN does not extend AbstractPhysicalSort but also
has ORDER BY and
// partition keys (used for row_number() / rank() per partition).
if (plan instanceof PhysicalPartitionTopN) {
PhysicalPartitionTopN<?> ptn = (PhysicalPartitionTopN<?>) plan;
for (Expression partKey : ptn.getPartitionKeys()) {
- recordInputSlotsAsQueryHit(partKey, exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(partKey, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
}
for (OrderKey orderKey : ptn.getOrderKeys()) {
- recordInputSlotsAsQueryHit(orderKey.getExpr(), exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(orderKey.getExpr(), exprIdToScan,
exprIdToColName, deltas,
+ derivedSlotInputs);
}
}
// PhysicalRepeat handles ROLLUP/CUBE: group sets are like GROUP BY
keys.
if (plan instanceof PhysicalRepeat) {
PhysicalRepeat<?> repeat = (PhysicalRepeat<?>) plan;
for (List<Expression> groupSet : repeat.getGroupingSets()) {
for (Expression expr : groupSet) {
- recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
}
}
for (NamedExpression expr : repeat.getOutputExpressions()) {
- recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
}
}
if (plan instanceof PhysicalWindow) {
WindowFrameGroup wfg = ((PhysicalWindow<?>)
plan).getWindowFrameGroup();
Set<Expression> partitionKeys = wfg.getPartitionKeys();
for (Expression expr : partitionKeys) {
- recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(expr, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
}
for (OrderExpression orderExpr : wfg.getOrderKeys()) {
- recordInputSlotsAsQueryHit(orderExpr.child(), exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsQueryHit(orderExpr.child(), exprIdToScan,
exprIdToColName, deltas,
+ derivedSlotInputs);
}
- // queryHit for the window function value columns (e.g. k2 in
SUM(k2) OVER (...)).
+ // queryHit for window value columns (e.g. k2 in SUM(k2) OVER
(...)), and link the
+ // alias to those inputs for a QUALIFY-style filter above;
positional functions
+ // like ROW_NUMBER have no column arguments, so nothing gets
linked for those.
for (NamedExpression windowAlias : wfg.getGroups()) {
Expression windowExpr = windowAlias.child(0);
if (windowExpr instanceof WindowExpression) {
- recordInputSlotsAsQueryHit(
- ((WindowExpression) windowExpr).getFunction(),
- exprIdToScan, exprIdToColName, deltas);
+ Expression function = ((WindowExpression)
windowExpr).getFunction();
+ recordInputSlotsAsQueryHit(function, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
+ if (!exprIdToScan.containsKey(windowAlias.getExprId())) {
+ Set<Slot> inputSlots = function.getInputSlots();
+ if (!inputSlots.isEmpty()) {
+ derivedSlotInputs.put(windowAlias.getExprId(),
inputSlots);
+ }
+ }
}
}
}
- // filterHit for JOIN ON conditions (hash equality and non-equality
predicates).
+ // filterHit for all JOIN ON conditions; mark conjuncts are a separate
field not included
+ // in hashJoinConjuncts or otherJoinConjuncts (IN/EXISTS subquery
correlation columns).
if (plan instanceof AbstractPhysicalJoin) {
AbstractPhysicalJoin<?, ?> join = (AbstractPhysicalJoin<?, ?>)
plan;
for (Expression conjunct : join.getHashJoinConjuncts()) {
- recordInputSlotsAsFilterHit(conjunct, exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsFilterHit(conjunct, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
}
for (Expression conjunct : join.getOtherJoinConjuncts()) {
- recordInputSlotsAsFilterHit(conjunct, exprIdToScan,
exprIdToColName, deltas);
+ recordInputSlotsAsFilterHit(conjunct, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
+ }
+ for (Expression conjunct : join.getMarkJoinConjuncts()) {
+ recordInputSlotsAsFilterHit(conjunct, exprIdToScan,
exprIdToColName, deltas, derivedSlotInputs);
+ }
+ }
+ // UNION / INTERSECT / EXCEPT: queryHit per branch, plus link the set
op's own output
+ // slots to those branch slots so a filter kept above the set op (e.g.
a volatile
+ // predicate PushDownFilterThroughSetOperation can't push down) still
resolves.
+ if (plan instanceof PhysicalSetOperation) {
+ PhysicalSetOperation setOp = (PhysicalSetOperation) plan;
+ recordSetOpChildrenOutputs(setOp.getOutput(),
setOp.getRegularChildrenOutputs(),
+ exprIdToScan, exprIdToColName, deltas, derivedSlotInputs);
+ }
+ // PhysicalRecursiveUnion extends PhysicalBinary (not
PhysicalSetOperation); handle its
+ // getRegularChildrenOutputs() explicitly. Recursive-case
(WorkTableReference) slots skipped.
Review Comment:
This remains unresolved in the final physical plan. PhysicalRecursiveUnion
requires GATHER on both children, while PhysicalRecursiveUnionAnchor derives
ANY, so property enforcement can make left() a PhysicalDistribute[GATHER]
wrapping the anchor. The direct instanceof check is then false and no
work-table edges are installed before the recursive branch is walked. Please
unwrap/find the matching anchor through the enforced distribute and cover that
shape (ideally with the requested real recursive regression).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]