[fix](nereids) removeRuntimeFilter() removes more than one RFs if there are different types of RF from the buildNode to the target (#31197)

this bug can be produced on tpcds 95, when set runtime filter type: min-max + bloom
This commit is contained in:
minghong
2024-02-21 15:53:23 +08:00
committed by yiguolei
parent 49411a3139
commit f1fbfeba2f
8 changed files with 61 additions and 34 deletions

View File

@ -181,12 +181,12 @@ public class RuntimeFilterContext {
}
/**
* remove rf from builderNode to target
* remove the given target from runtime filters from builderNode to target with all runtime filter types
*
* @param targetId rf target
* @param builderNode rf src
*/
public void removeFilter(ExprId targetId, PhysicalHashJoin builderNode) {
public void removeFilters(ExprId targetId, PhysicalHashJoin builderNode) {
List<RuntimeFilter> filters = targetExprIdToFilter.get(targetId);
if (filters != null) {
Iterator<RuntimeFilter> filterIter = filters.iterator();
@ -219,6 +219,33 @@ public class RuntimeFilterContext {
}
}
/**
* remove one target from rf, and if there is no target, remove the rf
*/
public void removeFilter(RuntimeFilter rf, ExprId targetId) {
Iterator<Slot> targetSlotIter = rf.getTargetSlots().listIterator();
Iterator<PhysicalRelation> targetScanIter = rf.getTargetScans().iterator();
Iterator<Expression> targetExpressionIter = rf.getTargetExpressions().iterator();
Slot targetSlot;
PhysicalRelation targetScan;
while (targetScanIter.hasNext() && targetSlotIter.hasNext() && targetExpressionIter.hasNext()) {
targetExpressionIter.next();
targetScan = targetScanIter.next();
targetSlot = targetSlotIter.next();
if (targetSlot.getExprId().equals(targetId)) {
targetScan.removeAppliedRuntimeFilter(rf);
targetExpressionIter.remove();
targetScanIter.remove();
targetSlotIter.remove();
}
}
if (rf.getTargetSlots().isEmpty()) {
rf.getBuilderNode().getRuntimeFilters().remove(rf);
targetExprIdToFilter.get(targetId).remove(rf);
prunedRF.add(rf);
}
}
public void setTargetsOnScanNode(PhysicalRelation relation, Slot slot) {
this.targetOnOlapScanNodeMap.computeIfAbsent(relation, k -> Lists.newArrayList()).add(slot);
}

View File

@ -224,8 +224,8 @@ public class RuntimeFilterGenerator extends PlanPostProcessor {
);
if (pushedDown) {
rfCtx.removeFilter(
rightDeepTargetExpressionOnCTE.getInputSlotExprIds().iterator().next(),
(PhysicalHashJoin) rfToPush.getBuilderNode());
rfToPush,
rightDeepTargetExpressionOnCTE.getInputSlotExprIds().iterator().next());
}
}
}

View File

@ -147,7 +147,7 @@ public class RuntimeFilterPruner extends PlanPostProcessor {
outputExprIdOfExpandTargets.addAll(expand.target2.getOutputExprIds());
rfContext.getTargetExprIdByFilterJoin(join)
.stream().filter(exprId -> outputExprIdOfExpandTargets.contains(exprId))
.forEach(exprId -> rfContext.removeFilter(exprId, join));
.forEach(exprId -> rfContext.removeFilters(exprId, join));
}
}
RuntimeFilterContext.EffectiveSrcType childType =
@ -163,7 +163,7 @@ public class RuntimeFilterPruner extends PlanPostProcessor {
}
}
if (!isEffective) {
exprIds.stream().forEach(exprId -> rfContext.removeFilter(exprId, join));
exprIds.stream().forEach(exprId -> rfContext.removeFilters(exprId, join));
}
}
}

View File

@ -52,7 +52,7 @@ public class RuntimeFilterPrunerForExternalTable extends PlanPostProcessor {
for (int i = 0; i < rf.getTargetScans().size(); i++) {
PhysicalRelation scan = rf.getTargetScans().get(i);
if (canPrune(scan, joinAncestors)) {
rfCtx.removeFilter(rf.getTargetSlots().get(i).getExprId(), (PhysicalHashJoin) join);
rfCtx.removeFilters(rf.getTargetSlots().get(i).getExprId(), (PhysicalHashJoin) join);
}
}
}