EmmyMiao87 commented on a change in pull request #7434:
URL: https://github.com/apache/incubator-doris/pull/7434#discussion_r772823857



##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java
##########
@@ -111,10 +125,159 @@ public void computeColumnFilter() {
             if (null == slotDesc) {
                 continue;
             }
+            // Set `columnFilters` all the time because `DistributionPruner` 
also use this.
+            // Maybe we could use `columnNameToRange` for `DistributionPruner` 
and
+            // only create `columnFilters` when 
`partition_prune_algorithm_version` is 1.
             PartitionColumnFilter keyFilter = createPartitionFilter(slotDesc, 
conjuncts);
             if (null != keyFilter) {
                 columnFilters.put(column.getName(), keyFilter);
             }
+
+            if 
(analyzer.getContext().getSessionVariable().getPartitionPruneAlgorithmVersion() 
== 2) {
+                ColumnRange columnRange = createColumnRange(slotDesc, 
conjuncts);
+                if (columnRange != null) {
+                    columnNameToRange.put(column.getName(), columnRange);
+                }
+            }
+
+        }
+    }
+
+    private ColumnRange createColumnRange(SlotDescriptor desc,
+                                          List<Expr> conjuncts) {
+        ColumnRange result = null;
+        for (Expr expr : conjuncts) {
+            if (!expr.isBound(desc.getId())) {
+                continue;
+            }
+
+            // Finish early if we have ever met `is null` predicate.
+            if (result != null && result.hasConjunctiveIsNull()) {
+                return result;
+            }
+
+            if (expr instanceof CompoundPredicate &&
+                ((CompoundPredicate) expr).getOp() == 
CompoundPredicate.Operator.OR) {
+                // Try to get column filter from disjunctive predicates.
+                List<Expr> disjunctivePredicates = 
PredicateUtils.splitDisjunctivePredicates(expr);
+                if (disjunctivePredicates.isEmpty()) {

Review comment:
       select * from test where k1 is null and k1=1;
   The partition range is empty.
   After it returns early, does the column range still include the range k1=1?

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/analysis/PredicateUtils.java
##########
@@ -0,0 +1,45 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+public class PredicateUtils {
+
+    public static List<Expr> splitDisjunctivePredicates(Expr expr) {

Review comment:
       Please add some comment and example ~

##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/ColumnRange.java
##########
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.planner;
+
+import java.util.List;
+import java.util.Optional;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.Range;
+import com.google.common.collect.RangeSet;
+import com.google.common.collect.TreeRangeSet;
+
+/**
+ * There are two kinds of predicates for a column: `is null` predicate and 
other predicates that
+ * the value of a column is not null, e.g., col=1, col>2, col in (1,2,3), etc.
+ *
+ * This can represent both conjunctive and disjunctive predicates for a column.
+ *
+ * The meaning of the predicates is: `conjunctiveIsNull` AND (`rangeSet` OR 
`disjunctiveIsNull`)
+ */
+public class ColumnRange {
+    private boolean hasConjunctiveIsNull;
+    private boolean hasDisjunctiveIsNull;
+    private RangeSet<ColumnBound> rangeSet;
+
+    private ColumnRange() {
+    }
+
+    public void merge(List<Range<ColumnBound>> ranges) {

Review comment:
       ```suggestion
       public void intersect(List<Range<ColumnBound>> disjunctRanges) {
   ```

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/analysis/PredicateUtils.java
##########
@@ -0,0 +1,45 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.analysis;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+public class PredicateUtils {
+
+    public static List<Expr> splitDisjunctivePredicates(Expr expr) {
+        ArrayList<Expr> result = Lists.newArrayList();
+        if (expr == null) {
+            return result;
+        }
+
+        splitDisjunctivePredicates(expr, result);
+        return result;
+    }
+
+    private static void splitDisjunctivePredicates(Expr expr, List<Expr> 
result) {

Review comment:
       From a logical point of view, it is actually impossible to deal with 
splits of expressions similar to (a or b) and c. 
   So you can explain in the comments




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