@@ -200,7 +200,7 @@ static PartClauseMatchStatus match_boolean_partition_clause(Oid partopfamily,
200
200
Expr * clause ,
201
201
Expr * partkey ,
202
202
Expr * * outconst ,
203
- bool * noteq );
203
+ bool * notclause );
204
204
static void partkey_datum_from_expr (PartitionPruneContext * context ,
205
205
Expr * expr , int stateidx ,
206
206
Datum * value , bool * isnull );
@@ -1798,13 +1798,14 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
1798
1798
Oid partopfamily = part_scheme -> partopfamily [partkeyidx ],
1799
1799
partcoll = part_scheme -> partcollation [partkeyidx ];
1800
1800
Expr * expr ;
1801
- bool noteq ;
1801
+ bool notclause ;
1802
1802
1803
1803
/*
1804
1804
* Recognize specially shaped clauses that match a Boolean partition key.
1805
1805
*/
1806
1806
boolmatchstatus = match_boolean_partition_clause (partopfamily , clause ,
1807
- partkey , & expr , & noteq );
1807
+ partkey , & expr ,
1808
+ & notclause );
1808
1809
1809
1810
if (boolmatchstatus == PARTCLAUSE_MATCH_CLAUSE )
1810
1811
{
@@ -1818,7 +1819,7 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
1818
1819
* punt it off to gen_partprune_steps_internal() to generate pruning
1819
1820
* steps.
1820
1821
*/
1821
- if (noteq )
1822
+ if (notclause )
1822
1823
{
1823
1824
List * new_clauses ;
1824
1825
List * or_clause ;
@@ -1836,9 +1837,8 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
1836
1837
else
1837
1838
{
1838
1839
/*
1839
- * We only expect match_boolean_partition_clause to match for
1840
- * IS_NOT_TRUE and IS_NOT_FALSE. IS_NOT_UNKNOWN is not
1841
- * supported.
1840
+ * We only expect match_boolean_partition_clause to return
1841
+ * PARTCLAUSE_MATCH_CLAUSE for IS_NOT_TRUE and IS_NOT_FALSE.
1842
1842
*/
1843
1843
Assert (false);
1844
1844
}
@@ -1876,6 +1876,15 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
1876
1876
1877
1877
return PARTCLAUSE_MATCH_CLAUSE ;
1878
1878
}
1879
+ else if (boolmatchstatus == PARTCLAUSE_MATCH_NULLNESS )
1880
+ {
1881
+ /*
1882
+ * Handle IS UNKNOWN and IS NOT UNKNOWN. These just logically
1883
+ * translate to IS NULL and IS NOT NULL.
1884
+ */
1885
+ * clause_is_not_null = notclause ;
1886
+ return PARTCLAUSE_MATCH_NULLNESS ;
1887
+ }
1879
1888
else if (IsA (clause , OpExpr ) &&
1880
1889
list_length (((OpExpr * ) clause )-> args ) == 2 )
1881
1890
{
@@ -3652,22 +3661,23 @@ perform_pruning_combine_step(PartitionPruneContext *context,
3652
3661
* match_boolean_partition_clause
3653
3662
*
3654
3663
* If we're able to match the clause to the partition key as specially-shaped
3655
- * boolean clause, set *outconst to a Const containing a true or false value,
3656
- * set *noteq according to if the clause was in the "not" form, i.e. "is not
3657
- * true" or "is not false", and return PARTCLAUSE_MATCH_CLAUSE. Returns
3658
- * PARTCLAUSE_UNSUPPORTED if the clause is not a boolean clause or if the
3659
- * boolean clause is unsuitable for partition pruning. Returns
3660
- * PARTCLAUSE_NOMATCH if it's a bool quals but just does not match this
3661
- * partition key. *outconst is set to NULL in the latter two cases.
3664
+ * boolean clause, set *outconst to a Const containing a true, false or NULL
3665
+ * value, set *notclause according to if the clause was in the "not" form,
3666
+ * i.e. "IS NOT TRUE", "IS NOT FALSE" or "IS NOT UNKNOWN" and return
3667
+ * PARTCLAUSE_MATCH_CLAUSE for "IS [NOT] (TRUE|FALSE)" clauses and
3668
+ * PARTCLAUSE_MATCH_NULLNESS for "IS [NOT] UNKNOWN" clauses. Otherwise,
3669
+ * return PARTCLAUSE_UNSUPPORTED if the clause cannot be used for partition
3670
+ * pruning, and PARTCLAUSE_NOMATCH for supported clauses that do not match this
3671
+ * 'partkey'.
3662
3672
*/
3663
3673
static PartClauseMatchStatus
3664
3674
match_boolean_partition_clause (Oid partopfamily , Expr * clause , Expr * partkey ,
3665
- Expr * * outconst , bool * noteq )
3675
+ Expr * * outconst , bool * notclause )
3666
3676
{
3667
3677
Expr * leftop ;
3668
3678
3669
3679
* outconst = NULL ;
3670
- * noteq = false;
3680
+ * notclause = false;
3671
3681
3672
3682
/*
3673
3683
* Partitioning currently can only use built-in AMs, so checking for
@@ -3680,11 +3690,6 @@ match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey,
3680
3690
{
3681
3691
BooleanTest * btest = (BooleanTest * ) clause ;
3682
3692
3683
- /* Only IS [NOT] TRUE/FALSE are any good to us */
3684
- if (btest -> booltesttype == IS_UNKNOWN ||
3685
- btest -> booltesttype == IS_NOT_UNKNOWN )
3686
- return PARTCLAUSE_UNSUPPORTED ;
3687
-
3688
3693
leftop = btest -> arg ;
3689
3694
if (IsA (leftop , RelabelType ))
3690
3695
leftop = ((RelabelType * ) leftop )-> arg ;
@@ -3694,23 +3699,28 @@ match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey,
3694
3699
switch (btest -> booltesttype )
3695
3700
{
3696
3701
case IS_NOT_TRUE :
3697
- * noteq = true;
3702
+ * notclause = true;
3698
3703
/* fall through */
3699
3704
case IS_TRUE :
3700
3705
* outconst = (Expr * ) makeBoolConst (true, false);
3701
- break ;
3706
+ return PARTCLAUSE_MATCH_CLAUSE ;
3702
3707
case IS_NOT_FALSE :
3703
- * noteq = true;
3708
+ * notclause = true;
3704
3709
/* fall through */
3705
3710
case IS_FALSE :
3706
3711
* outconst = (Expr * ) makeBoolConst (false, false);
3707
- break ;
3712
+ return PARTCLAUSE_MATCH_CLAUSE ;
3713
+ case IS_NOT_UNKNOWN :
3714
+ * notclause = true;
3715
+ /* fall through */
3716
+ case IS_UNKNOWN :
3717
+ return PARTCLAUSE_MATCH_NULLNESS ;
3708
3718
default :
3709
3719
return PARTCLAUSE_UNSUPPORTED ;
3710
3720
}
3711
3721
}
3712
- if ( * outconst )
3713
- return PARTCLAUSE_MATCH_CLAUSE ;
3722
+ /* does not match partition key */
3723
+ return PARTCLAUSE_NOMATCH ;
3714
3724
}
3715
3725
else
3716
3726
{
@@ -3726,12 +3736,11 @@ match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey,
3726
3736
* outconst = (Expr * ) makeBoolConst (!is_not_clause , false);
3727
3737
else if (equal (negate_clause ((Node * ) leftop ), partkey ))
3728
3738
* outconst = (Expr * ) makeBoolConst (is_not_clause , false);
3739
+ else
3740
+ return PARTCLAUSE_NOMATCH ;
3729
3741
3730
- if (* outconst )
3731
- return PARTCLAUSE_MATCH_CLAUSE ;
3742
+ return PARTCLAUSE_MATCH_CLAUSE ;
3732
3743
}
3733
-
3734
- return PARTCLAUSE_NOMATCH ;
3735
3744
}
3736
3745
3737
3746
/*
0 commit comments