diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java index 42bc0b5bd7502..1f5dc8a97a004 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/optimizer/statistics/StatisticsCalculator.java @@ -1623,9 +1623,9 @@ public Void visitPhysicalNoCTE(PhysicalNoCTEOperator node, ExpressionContext con // avoid use partition cols filter rows twice @VisibleForTesting public ScalarOperator removePartitionPredicate(ScalarOperator predicate, Operator operator, - OptimizerContext optimizerContext) { + OptimizerContext optimizerContext) { boolean isTableTypeSupported = operator instanceof LogicalIcebergScanOperator || - isOlapScanListPartitionTable(operator); + isOlapScanListPartitionTable(operator); if (isTableTypeSupported && !optimizerContext.isObtainedFromInternalStatistics()) { LogicalScanOperator scanOperator = operator.cast(); List partitionColNames = scanOperator.getTable().getPartitionColumnNames(); @@ -1634,8 +1634,8 @@ public ScalarOperator removePartitionPredicate(ScalarOperator predicate, Operato List conjuncts = Utils.extractConjuncts(predicate); List newPredicates = Lists.newArrayList(); for (ScalarOperator scalarOperator : conjuncts) { - boolean isPartitionCol = isPartitionCol(scalarOperator.getChild(0), partitionColNames); - if (isPartitionCol && ListPartitionPruner.canPruneWithConjunct(scalarOperator)) { + if (ListPartitionPruner.canPruneWithConjunct(scalarOperator) && + isPartitionCol(scalarOperator.getChild(0), partitionColNames)) { // drop this predicate } else { newPredicates.add(scalarOperator); diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/plan/PartitionPruneTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/plan/PartitionPruneTest.java index 4fc3a1e067586..bed5845efc90a 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/plan/PartitionPruneTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/plan/PartitionPruneTest.java @@ -78,6 +78,13 @@ public static void beforeClass() throws Exception { starRocksAssert.ddl("ALTER TABLE t_gen_col ADD PARTITION p2_202402 VALUES IN (('2', '2024-02-01'))"); starRocksAssert.ddl("ALTER TABLE t_gen_col ADD PARTITION p2_202403 VALUES IN (('2', '2024-03-01'))"); + starRocksAssert.withTable("CREATE TABLE t_bool_partition (" + + " c1 datetime NOT NULL, " + + " c2 boolean" + + " ) " + + " PARTITION BY (c1, c2) " + + " PROPERTIES('replication_num'='1')"); + // year(c1) starRocksAssert.withTable("CREATE TABLE t_gen_col_1 (" + " c1 datetime NOT NULL," + @@ -232,6 +239,10 @@ public void testGeneratedColumnPrune_RemovePredicate() throws Exception { testRemovePredicate("select * from t_gen_col where c2 in (1, 2,3)", "true"); testRemovePredicate("select * from t_gen_col where c2 = cast('123' as int)", "true"); + // bool partition column + testRemovePredicate("select * from t_bool_partition where c2=true", "2: c2"); + testRemovePredicate("select * from t_bool_partition where c2=false", "true"); + // can not be removed testRemovePredicate("select * from t_gen_col where c1 = random() and c2 > 100", "cast(1: c1 as double) = random(1)");