Skip to content

Commit 996f1cd

Browse files
starocean999Doris-Extras
authored andcommitted
[enhancement](nereids)convert Or to in-predicate and optimize in-predicate evaluation in range partition prune (apache#31)
1 parent 9d9428c commit 996f1cd

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/OneRangePartitionEvaluator.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,12 @@ public EvaluateRangeResult visitInPredicate(InPredicate inPredicate, EvaluateRan
381381
if (inPredicate.getCompareExpr() instanceof Slot
382382
&& inPredicate.getOptions().stream().allMatch(Literal.class::isInstance)) {
383383
Slot slot = (Slot) inPredicate.getCompareExpr();
384-
ColumnRange unionLiteralRange = inPredicate.getOptions()
385-
.stream()
386-
.map(Literal.class::cast)
387-
.map(ColumnRange::singleton)
388-
.reduce(ColumnRange.empty(), ColumnRange::union);
384+
ColumnRange unionLiteralRange = ColumnRange.empty();
385+
ColumnRange slotRange = result.childrenResult.get(0).columnRanges.get(slot);
386+
for (Expression expr : inPredicate.getOptions()) {
387+
unionLiteralRange = unionLiteralRange
388+
.union(slotRange.intersect(ColumnRange.singleton((Literal) expr)));
389+
}
389390
Map<Slot, ColumnRange> slotRanges = result.childrenResult.get(0).columnRanges;
390391
result = intersectSlotRange(result, slotRanges, slot, unionLiteralRange);
391392
}

‎fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPruner.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public static List<Long> prune(List<Slot> partitionSlots, Expression partitionPr
123123
partitionTableType))
124124
.collect(ImmutableList.toImmutableList());
125125

126+
partitionPredicate = OrToIn.INSTANCE.rewrite(partitionPredicate, null);
126127
PartitionPruner partitionPruner = new PartitionPruner(evaluators, partitionPredicate);
127128
//TODO: we keep default partition because it's too hard to prune it, we return false in canPrune().
128129
return partitionPruner.prune();

0 commit comments

Comments
 (0)