mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
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 4c2369ac5. 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
This commit is contained in:
parent
818fefd8fd
commit
d2ca9a50b5
@ -1936,9 +1936,11 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
|
||||
* whatsoever, but their negators (equality) are. We can use one of
|
||||
* those if we find it, but only for list partitioning.
|
||||
*
|
||||
* Note: we report NOMATCH on failure, in case a later partkey has the
|
||||
* same expression but different opfamily. That's unlikely, but not
|
||||
* much more so than duplicate expressions with different collations.
|
||||
* Note: we report NOMATCH on failure if the negator isn't the
|
||||
* equality operator for the partkey's opfamily as other partkeys may
|
||||
* have the same expression but different opfamily. That's unlikely,
|
||||
* but not much more so than duplicate expressions with different
|
||||
* collations.
|
||||
*/
|
||||
if (op_in_opfamily(opno, partopfamily))
|
||||
{
|
||||
@ -1948,8 +1950,9 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
|
||||
}
|
||||
else
|
||||
{
|
||||
/* not supported for anything apart from LIST partitioned tables */
|
||||
if (part_scheme->strategy != PARTITION_STRATEGY_LIST)
|
||||
return PARTCLAUSE_NOMATCH;
|
||||
return PARTCLAUSE_UNSUPPORTED;
|
||||
|
||||
/* See if the negator is equality */
|
||||
negator = get_negator(opno);
|
||||
@ -2924,7 +2927,7 @@ get_matching_list_bounds(PartitionPruneContext *context,
|
||||
* multiple pruning steps might exclude it, so we infer its inclusion
|
||||
* elsewhere.
|
||||
*
|
||||
* 'opstrategy' if non-zero must be a btree strategy number.
|
||||
* 'opstrategy' must be a btree strategy number.
|
||||
*
|
||||
* 'values' contains Datums indexed by the partition key to use for pruning.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user