morrySnow commented on code in PR #57169:
URL: https://github.com/apache/doris/pull/57169#discussion_r2459671167


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPruner.java:
##########
@@ -278,18 +307,66 @@ private static <K extends Comparable<K>> List<K> 
sequentialFiltering(
     }
 
     /**
-     * return true if partition is not qualified. that is, can be pruned out.
+     * return Pair
+     *     pair.first is true if partition can be pruned
+     *     pair.second is true if partitionPredicate is always true in this 
partition
      */
-    private static <K> boolean canBePrunedOut(Expression partitionPredicate, 
OnePartitionEvaluator<K> evaluator) {
+    private static <K> Pair<Boolean, Boolean> canBePrunedOut(Expression 
partitionPredicate,
+            OnePartitionEvaluator<K> evaluator) {
         List<Map<Slot, PartitionSlotInput>> onePartitionInputs = 
evaluator.getOnePartitionInputs();
-        for (Map<Slot, PartitionSlotInput> currentInputs : onePartitionInputs) 
{
-            // evaluate whether there's possible for this partition to accept 
this predicate
-            Expression result = 
evaluator.evaluateWithDefaultPartition(partitionPredicate, currentInputs);
-            if (!result.equals(BooleanLiteral.FALSE) && !(result instanceof 
NullLiteral)) {
-                return false;
+        if (evaluator instanceof OneListPartitionEvaluator) {
+            // if a table has default partition, the predicate should not be 
pruned,
+            // because evaluateWithDefaultPartition always return true in 
default partition
+            // e.g. PARTITION BY LIST(k1) (
+            //     PARTITION p1 VALUES IN ("1","2","3","4"),
+            //     PARTITION p2 VALUES IN ("5","6","7","8"),
+            //     PARTITION p3 )  p3 is default partition
+            Pair<Boolean, Boolean> res = Pair.of(true, 
!evaluator.isDefaultPartition());
+            for (Map<Slot, PartitionSlotInput> currentInputs : 
onePartitionInputs) {
+                // evaluate whether there's possible for this partition to 
accept this predicate
+                Expression result = 
evaluator.evaluateWithDefaultPartition(partitionPredicate, currentInputs);
+                if (result.equals(BooleanLiteral.FALSE) || (result instanceof 
NullLiteral)) {
+                    // Indicates that there is a partition value that does not 
satisfy the predicate
+                    res.second = false;
+                } else if (result.equals(BooleanLiteral.TRUE)) {
+                    // Indicates that there is a partition value that 
satisfies the predicate
+                    res.first = false;
+                } else {
+                    // Indicates that this partition value may or may not 
satisfy the predicate
+                    res.second = false;
+                    res.first = false;
+                }
             }
+            return res;
+        } else {
+            // only prune partition predicates in list partition, therefore 
set pair.second always be false,
+            // meaning not to prune partition predicates in range partition
+            for (Map<Slot, PartitionSlotInput> currentInputs : 
onePartitionInputs) {
+                Expression result = 
evaluator.evaluateWithDefaultPartition(partitionPredicate, currentInputs);
+                if (!result.equals(BooleanLiteral.FALSE) && !(result 
instanceof NullLiteral)) {
+                    return Pair.of(false, false);
+                }
+            }
+            // only have false result: Can be pruned out. have other exprs: 
CanNot be pruned out
+            return Pair.of(true, false);
+        }
+    }
+
+    /** remove predicates that are always true*/
+    public static Plan prunePredicate(boolean skipPrunePredicate, 
Optional<Expression> prunedPredicates,
+            LogicalFilter<? extends Plan> filter, LogicalRelation scan) {
+        if (!skipPrunePredicate && prunedPredicates.isPresent()) {

Review Comment:
   add ut for it



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/PartitionPruner.java:
##########
@@ -278,18 +307,66 @@ private static <K extends Comparable<K>> List<K> 
sequentialFiltering(
     }
 
     /**
-     * return true if partition is not qualified. that is, can be pruned out.
+     * return Pair
+     *     pair.first is true if partition can be pruned
+     *     pair.second is true if partitionPredicate is always true in this 
partition
      */
-    private static <K> boolean canBePrunedOut(Expression partitionPredicate, 
OnePartitionEvaluator<K> evaluator) {
+    private static <K> Pair<Boolean, Boolean> canBePrunedOut(Expression 
partitionPredicate,
+            OnePartitionEvaluator<K> evaluator) {
         List<Map<Slot, PartitionSlotInput>> onePartitionInputs = 
evaluator.getOnePartitionInputs();
-        for (Map<Slot, PartitionSlotInput> currentInputs : onePartitionInputs) 
{
-            // evaluate whether there's possible for this partition to accept 
this predicate
-            Expression result = 
evaluator.evaluateWithDefaultPartition(partitionPredicate, currentInputs);
-            if (!result.equals(BooleanLiteral.FALSE) && !(result instanceof 
NullLiteral)) {
-                return false;
+        if (evaluator instanceof OneListPartitionEvaluator) {
+            // if a table has default partition, the predicate should not be 
pruned,
+            // because evaluateWithDefaultPartition always return true in 
default partition
+            // e.g. PARTITION BY LIST(k1) (
+            //     PARTITION p1 VALUES IN ("1","2","3","4"),
+            //     PARTITION p2 VALUES IN ("5","6","7","8"),
+            //     PARTITION p3 )  p3 is default partition
+            Pair<Boolean, Boolean> res = Pair.of(true, 
!evaluator.isDefaultPartition());

Review Comment:
   add ut for it



-- 
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]

Reply via email to