github-actions[bot] commented on code in PR #70480:
URL: https://github.com/apache/doris/pull/70480#discussion_r4680603205
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPruner.java:
##########
@@ -110,34 +203,85 @@ public PhysicalIntersect
visitPhysicalIntersect(PhysicalIntersect intersect, Cas
CascadesContext context) {
join.right().accept(this, context);
join.left().accept(this, context);
- if
(context.getRuntimeFilterContext().isEffectiveSrcNode(join.child(0))) {
- RuntimeFilterContext.EffectiveSrcType childType =
context.getRuntimeFilterContext()
- .getEffectiveSrcType(join.child(0));
- context.getRuntimeFilterContext().addEffectiveSrcNode(join,
childType);
- }
+ RuntimeFilterContext rfContext = context.getRuntimeFilterContext();
+ propagateOrdinaryJoinSource(join, join.left(),
join.getJoinType().isLeftSideNullable(), rfContext);
+ propagateJoinChangelog(join, join.getJoinType().isRemainRightJoin(),
rfContext);
Review Comment:
[P2] Preserve stream membership through nested-loop semi joins
`isRemainRightJoin()` is false for `LEFT_SEMI_JOIN`, but the right side
still determines which left keys survive:
```text
HashJoin(F.k = A.k)
F
NestedLoopLeftSemiJoin(A.k < S.k)
A
S@incr(MIN_DELTA)
```
For A/F keys 1..100 and incremental S containing only 2, the build emits
only key 1, so the parent runtime filter can reject 99% of F. This guard
discards S's changelog influence because no right slots are emitted. With
BLOOM-only filters, unknown/equal parent statistics and no partition/bucket
pruning on `F.k`, the parent removes that useful filter. The newly added
`testNestedLoopLeftSemiBuildDoesNotPropagateRightChangelog` asserts this
unwanted pruning; the hash-semi path already preserves right-side influence.
Please account for semi/anti membership dependence and update that test to
require retention, including unknown statistics. This is distinct from the
fixed inner nested-loop output case and the existing left-outer preserved-key
concern: semi joins can remove left keys.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPruner.java:
##########
@@ -56,50 +73,126 @@
* 2. the build column ndv is less than that of probe column, OR
* 3. the build column's ColumnStats.selectivity < 1, OR
* 4. the build column is reduced by another RF, which satisfies above
criterions, OR
- * 5. the RF can eliminate whole scan ranges.
+ * 5. the RF can eliminate whole scan ranges, OR
+ * 6. the build side scans a table stream's incremental data.
*
* TODO: item 2 is not used since the estimation is not accurate now.
*/
public class RuntimeFilterPruner extends PlanPostProcessor {
+ private final Map<CTEId, Plan> changelogCteProducers = new HashMap<>();
+ private final Set<CTEId> changelogWorkTableIds = new HashSet<>();
@Override
public Plan visit(Plan plan, CascadesContext context) {
if (!plan.children().isEmpty()) {
Preconditions.checkArgument(plan.children().size() == 1,
plan.getClass().getSimpleName()
+ " has more than one child, needs its own visitor
implementation");
- plan.child(0).accept(this, context);
- if
(context.getRuntimeFilterContext().isEffectiveSrcNode(plan.child(0))) {
- RuntimeFilterContext.EffectiveSrcType childType =
context.getRuntimeFilterContext()
- .getEffectiveSrcType(plan.child(0));
- context.getRuntimeFilterContext().addEffectiveSrcNode(plan,
childType);
- }
+ return propagateEffectiveSrc(plan, context);
}
return plan;
}
@Override
- public PhysicalRecursiveUnion visitPhysicalRecursiveUnion(
+ public PhysicalRecursiveUnion<? extends Plan, ? extends Plan>
visitPhysicalRecursiveUnion(
PhysicalRecursiveUnion<? extends Plan, ? extends Plan>
recursiveUnion, CascadesContext context) {
- for (Plan child : recursiveUnion.children()) {
- child.accept(this, context);
- }
+ visitSetOperationChildren(recursiveUnion,
recursiveUnion.getRegularChildrenOutputs(), true, context);
return recursiveUnion;
}
+ @Override
+ public PhysicalRecursiveUnionAnchor<? extends Plan>
visitPhysicalRecursiveUnionAnchor(
+ PhysicalRecursiveUnionAnchor<? extends Plan> anchor,
CascadesContext context) {
+ // The recursive union visits the seed before the recursive term reads
the work table.
+ propagateEffectiveSrc(anchor, context);
+ if (context.getRuntimeFilterContext().getEffectiveSrcType(anchor)
+ == RuntimeFilterContext.EffectiveSrcType.CHANGELOG) {
+ changelogWorkTableIds.add(anchor.getCteId());
+ }
+ return anchor;
+ }
+
+ @Override
+ public PhysicalWorkTableReference visitPhysicalWorkTableReference(
+ PhysicalWorkTableReference reference, CascadesContext context) {
+ if (changelogWorkTableIds.contains(reference.getCteId())) {
+ context.getRuntimeFilterContext().addEffectiveSrcNode(reference,
+ RuntimeFilterContext.EffectiveSrcType.CHANGELOG);
+ } else {
+ visitPhysicalRelation(reference, context);
+ }
+ return reference;
+ }
+
@Override
public PhysicalSetOperation visitPhysicalSetOperation(PhysicalSetOperation
setOperation, CascadesContext context) {
- for (Plan child : setOperation.children()) {
+ visitSetOperationChildren(setOperation,
setOperation.getRegularChildrenOutputs(),
+ setOperation instanceof PhysicalUnion, context);
+ return setOperation;
+ }
+
+ private void visitSetOperationChildren(Plan plan,
List<List<SlotReference>> childOutputs,
+ boolean union, CascadesContext context) {
+ RuntimeFilterContext rfContext = context.getRuntimeFilterContext();
+ for (int i = 0; i < plan.arity(); i++) {
+ Plan child = plan.child(i);
child.accept(this, context);
+ if (rfContext.hasChangelogSource(child)) {
+ if (union) {
+ Set<Slot> sourceSlots =
rfContext.getChangelogSourceSlots(child);
+ Set<Slot> outputSlots = new HashSet<>();
+ List<SlotReference> inputs = childOutputs.get(i);
+ List<Slot> outputs = plan.getOutput();
+ for (int j = 0; j < inputs.size(); j++) {
+ if (sourceSlots.contains(inputs.get(j))) {
+ outputSlots.add(outputs.get(j));
+ }
+ }
+ rfContext.addChangelogSource(plan, outputSlots);
+ } else {
+ // Membership in EXCEPT and INTERSECT depends on the
entire tuple.
+ rfContext.addEffectiveSrcNode(plan,
RuntimeFilterContext.EffectiveSrcType.CHANGELOG);
+ }
+ }
}
- return setOperation;
+ }
+
+ private void propagateChangelog(Plan plan, Plan child,
RuntimeFilterContext rfContext) {
+ if (!rfContext.hasChangelogSource(child)) {
+ return;
+ }
+ Set<Slot> sourceSlots = rfContext.getChangelogSourceSlots(child);
+ if (sourceSlots.containsAll(child.getOutputSet())
+ || (plan instanceof PhysicalFilter &&
plan.getExpressions().stream()
+ .anyMatch(predicate ->
!Collections.disjoint(predicate.getInputSlots(), sourceSlots)))) {
+ rfContext.addEffectiveSrcNode(plan,
RuntimeFilterContext.EffectiveSrcType.CHANGELOG);
+ return;
+ }
+ Set<Slot> outputs = new HashSet<>();
+ if (plan instanceof PhysicalProject) {
+ for (NamedExpression project : ((PhysicalProject<?>)
plan).getProjects()) {
+ if (!Collections.disjoint(project.getInputSlots(),
sourceSlots)) {
+ outputs.add(project.toSlot());
+ }
+ }
+ } else if (plan instanceof PhysicalHashAggregate) {
+ for (NamedExpression output : ((PhysicalHashAggregate<?>)
plan).getOutputExpressions()) {
+ // An aggregate can depend on row multiplicity even when its
input key is unchanged.
+ if (output.anyMatch(AggregateExpression.class::isInstance)
+ || !Collections.disjoint(output.getInputSlots(),
sourceSlots)) {
+ outputs.add(output.toSlot());
+ }
+ }
+ } else {
+ outputs.addAll(plan.getOutputSet());
+ outputs.retainAll(sourceSlots);
Review Comment:
[P2] Preserve changelog dependencies of derived unary outputs
Consider this reduced build subtree, with `S` a `MIN_DELTA` scan and an
ordinary `A.keep` also selected by the query:
```text
HashJoin(F.k = b.total)
F
Project(A.keep, total)
Window(SUM(S.v) OVER (PARTITION BY A.id) AS total)
LeftOuterJoin(A.id = S.id)
A
S
```
The outer join correctly marks only the S-side slots. `PhysicalWindow` then
uses the generic visitor, and this intersection retains only those existing
slots: it never marks the fresh `total` output, even though its value depends
on S. Keeping `A.keep` live prevents the all-input-slots fast path. With no
ordinary effective source, unknown/non-selective stats, and a
non-partition/non-bucket `F.k`, the parent removes the runtime filter built
from `total`.
Please propagate dependencies to newly produced unary outputs.
`PhysicalGenerate` has the same path for outputs such as
`explode_numbers(S.v)`. Add partial-source window/generator cases that retain
an ordinary output too. This differs from the existing preserved-key thread:
the lost key here actually depends on the stream.
--
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]