Skip to content

Commit

Permalink
add session var and optimize inpredicate partition prune (apache#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 authored Dec 12, 2023
1 parent a57deb4 commit 1378ba6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,12 @@ public EvaluateRangeResult visitInPredicate(InPredicate inPredicate, EvaluateRan
if (inPredicate.getCompareExpr() instanceof Slot
&& inPredicate.getOptions().stream().allMatch(Literal.class::isInstance)) {
Slot slot = (Slot) inPredicate.getCompareExpr();
ColumnRange unionLiteralRange = inPredicate.getOptions()
.stream()
.map(Literal.class::cast)
.map(ColumnRange::singleton)
.reduce(ColumnRange.empty(), ColumnRange::union);
ColumnRange unionLiteralRange = ColumnRange.empty();
ColumnRange slotRange = result.childrenResult.get(0).columnRanges.get(slot);
for (Expression expr : inPredicate.getOptions()) {
unionLiteralRange = unionLiteralRange
.union(slotRange.intersect(ColumnRange.singleton((Literal) expr)));
}
Map<Slot, ColumnRange> slotRanges = result.childrenResult.get(0).columnRanges;
result = intersectSlotRange(result, slotRanges, slot, unionLiteralRange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public static Expression rewrite(Expression expression, double rangeLength, Casc

@Override
public Expression visitInPredicate(InPredicate inPredicate, CascadesContext ctx) {
if (inPredicate.getOptions().size() > 10) {
int maxInListSize = ctx.getConnectContext().getSessionVariable().maxInListSizeForRewrite;
if (inPredicate.getOptions().size() > maxInListSize) {
Expression opt0 = inPredicate.getOptions().get(0);
if (opt0 instanceof DateLiteral || opt0 instanceof DateTimeLiteral) {
Literal minOpt = (Literal) inPredicate.getOptions().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,9 @@ public void setMaxJoinNumberOfReorder(int maxJoinNumberOfReorder) {
@VariableMgr.VarAttr(name = "in_to_minmax_parition_rewrite_threshold", needForward = true)
public double inToMinmaxParitionRewriteThreshold = 0.2;

@VariableMgr.VarAttr(name = "max_in_list_size_for_rewrite", needForward = true)
public int maxInListSizeForRewrite = 25;

// If this fe is in fuzzy mode, then will use initFuzzyModeVariables to generate some variables,
// not the default value set in the code.
public void initFuzzyModeVariables() {
Expand Down

0 comments on commit 1378ba6

Please sign in to comment.