diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 510145e3c0..8e36bbe419 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -201,7 +201,8 @@ static PruneStepResult *perform_pruning_combine_step(PartitionPruneContext *cont static PartClauseMatchStatus match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, - Expr **outconst); + Expr **outconst, + bool *noteq); static void partkey_datum_from_expr(PartitionPruneContext *context, Expr *expr, int stateidx, Datum *value, bool *isnull); @@ -1809,12 +1810,12 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context, Oid partopfamily = part_scheme->partopfamily[partkeyidx], partcoll = part_scheme->partcollation[partkeyidx]; Expr *expr; - + bool noteq; /* * Recognize specially shaped clauses that match a Boolean partition key. */ boolmatchstatus = match_boolean_partition_clause(partopfamily, clause, - partkey, &expr); + partkey, &expr, ¬eq); if (boolmatchstatus == PARTCLAUSE_MATCH_CLAUSE) { @@ -1824,7 +1825,7 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context, partclause->keyno = partkeyidx; /* Do pruning with the Boolean equality operator. */ partclause->opno = BooleanEqualOperator; - partclause->op_is_ne = false; + partclause->op_is_ne = noteq; partclause->expr = expr; /* We know that expr is of Boolean type. */ partclause->cmpfn = part_scheme->partsupfunc[partkeyidx].fn_oid; @@ -3596,11 +3597,12 @@ perform_pruning_combine_step(PartitionPruneContext *context, */ static PartClauseMatchStatus match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, - Expr **outconst) + Expr **outconst, bool *noteq) { Expr *leftop; *outconst = NULL; + *noteq = false; /* * Partitioning currently can only use built-in AMs, so checking for @@ -3623,11 +3625,26 @@ match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, leftop = ((RelabelType *) leftop)->arg; if (equal(leftop, partkey)) - *outconst = (btest->booltesttype == IS_TRUE || - btest->booltesttype == IS_NOT_FALSE) - ? (Expr *) makeBoolConst(true, false) - : (Expr *) makeBoolConst(false, false); - + { + switch (btest->booltesttype) + { + case IS_NOT_TRUE: + *noteq = true; + /* fall through */ + case IS_TRUE: + *outconst = (Expr *) makeBoolConst(true, false); + break; + case IS_NOT_FALSE: + *noteq = true; + /* fall through */ + case IS_FALSE: + *outconst = (Expr *) makeBoolConst(false, false); + break; + default: + Assert(false); /* hmm? */ + return PARTCLAUSE_UNSUPPORTED; + } + } if (*outconst) return PARTCLAUSE_MATCH_CLAUSE; } diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out index d700c00629..55cc528e55 100644 --- a/src/test/regress/expected/partition_prune.out +++ b/src/test/regress/expected/partition_prune.out @@ -1070,20 +1070,25 @@ explain (costs off) select * from boolpart where a is true or a is not true; Filter: ((a IS TRUE) OR (a IS NOT TRUE)) -> Seq Scan on boolpart_t boolpart_2 Filter: ((a IS TRUE) OR (a IS NOT TRUE)) -(5 rows) + -> Seq Scan on boolpart_default boolpart_3 + Filter: ((a IS TRUE) OR (a IS NOT TRUE)) +(7 rows) explain (costs off) select * from boolpart where a is not true; - QUERY PLAN ---------------------------------- - Seq Scan on boolpart_f boolpart - Filter: (a IS NOT TRUE) -(2 rows) + QUERY PLAN +----------------------------------------------- + Append + -> Seq Scan on boolpart_f boolpart_1 + Filter: (a IS NOT TRUE) + -> Seq Scan on boolpart_default boolpart_2 + Filter: (a IS NOT TRUE) +(5 rows) explain (costs off) select * from boolpart where a is not true and a is not false; - QUERY PLAN --------------------------- - Result - One-Time Filter: false + QUERY PLAN +-------------------------------------------------- + Seq Scan on boolpart_default boolpart + Filter: ((a IS NOT TRUE) AND (a IS NOT FALSE)) (2 rows) explain (costs off) select * from boolpart where a is unknown;