Skip to content

Commit d2ca9a5

Browse files
committed
Minor corrections for partition pruning
When the partition pruning code finds an OpExpr with an operator that does not belong to the partition key's opfamily, the code checks to see if the negator of the operator is the opfamily's BTEqualStrategyNumber operator so that partition pruning can support that operator and invert the matching partitions. Doing this only works for LIST partitioned tables. Here we fix a minor correctness issue where when we discover we're not pruning for a LIST partitioned table, we return PARTCLAUSE_NOMATCH. PARTCLAUSE_NOMATCH is only meant to be used when the clause may match another partitioned key column. For this case, the clause is not going to be any more useful to another partitioned key as the partition strategy is not going to change from one key to the next. Noticed while working 4c2369a. No backpatch because returning PARTCLAUSE_NOMATCH instead of PARTCLAUSE_UNSUPPORTED mostly just causes wasted effort checking subsequent partition keys against a clause that will never be used for pruning. In passing, correct a comment for get_matching_range_bounds() which mentions that an 'opstrategy' of 0 is supported. It's not, so fix the comment. This was pointed out by Alexander Lakhin. Discussion: https://postgr.es/m/CAApHDvqriy8mPOFJ_Bd66YGXJ4+XULpv-4YdB+ePdCQFztyisA@mail.gmail.com Discussion: https://postgr.es/m/312fb507-9b5e-cf83-d8ed-cd0da72a902c@gmail.com
1 parent 818fefd commit d2ca9a5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/backend/partitioning/partprune.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,9 +1936,11 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
19361936
* whatsoever, but their negators (equality) are. We can use one of
19371937
* those if we find it, but only for list partitioning.
19381938
*
1939-
* Note: we report NOMATCH on failure, in case a later partkey has the
1940-
* same expression but different opfamily. That's unlikely, but not
1941-
* much more so than duplicate expressions with different collations.
1939+
* Note: we report NOMATCH on failure if the negator isn't the
1940+
* equality operator for the partkey's opfamily as other partkeys may
1941+
* have the same expression but different opfamily. That's unlikely,
1942+
* but not much more so than duplicate expressions with different
1943+
* collations.
19421944
*/
19431945
if (op_in_opfamily(opno, partopfamily))
19441946
{
@@ -1948,8 +1950,9 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
19481950
}
19491951
else
19501952
{
1953+
/* not supported for anything apart from LIST partitioned tables */
19511954
if (part_scheme->strategy != PARTITION_STRATEGY_LIST)
1952-
return PARTCLAUSE_NOMATCH;
1955+
return PARTCLAUSE_UNSUPPORTED;
19531956

19541957
/* See if the negator is equality */
19551958
negator = get_negator(opno);
@@ -2924,7 +2927,7 @@ get_matching_list_bounds(PartitionPruneContext *context,
29242927
* multiple pruning steps might exclude it, so we infer its inclusion
29252928
* elsewhere.
29262929
*
2927-
* 'opstrategy' if non-zero must be a btree strategy number.
2930+
* 'opstrategy' must be a btree strategy number.
29282931
*
29292932
* 'values' contains Datums indexed by the partition key to use for pruning.
29302933
*

0 commit comments

Comments
 (0)