aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/pathkeys.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-09-02 17:01:51 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-09-02 17:01:51 -0400
commitff720a597c0a53a8fcdf2cf4e45248dc5c37f9ab (patch)
treed65c09ead47e4aafb0d12ec5217b6bad7395c417 /src/backend/optimizer/path/pathkeys.c
parentd885a6b612cf10a3013ba206a2607c88ccea42bc (diff)
downloadpostgresql-ff720a597c0a53a8fcdf2cf4e45248dc5c37f9ab.tar.gz
postgresql-ff720a597c0a53a8fcdf2cf4e45248dc5c37f9ab.zip
Fix planner to consider matches to boolean columns in extension indexes.
The planner has to special-case indexes on boolean columns, because what we need for an indexscan on such a column is a qual of the shape of "boolvar = pseudoconstant". For plain bool constants, previous simplification will have reduced this to "boolvar" or "NOT boolvar", and we have to reverse that if we want to make an indexqual. There is existing code to do so, but it only fires when the index's opfamily is BOOL_BTREE_FAM_OID or BOOL_HASH_FAM_OID. Thus extension AMs, or extension opclasses such as contrib/btree_gin, are out in the cold. The reason for hard-wiring the set of relevant opfamilies was mostly to avoid a catalog lookup in a hot code path. We can improve matters while not taking much of a performance hit by relying on the hard-wired set when the opfamily OID is visibly built-in, and only checking the catalogs when dealing with an extension opfamily. While here, rename IsBooleanOpfamily to IsBuiltinBooleanOpfamily to remind future users of that macro of its limitations. At some point we might want to make indxpath.c's improved version of the test globally accessible, but it's not presently needed elsewhere. Zongliang Quan and Tom Lane Discussion: https://postgr.es/m/f293b91d-1d46-d386-b6bb-4b06ff5c667b@yeah.net
Diffstat (limited to 'src/backend/optimizer/path/pathkeys.c')
-rw-r--r--src/backend/optimizer/path/pathkeys.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c
index 1fa7fc99b51..18f88700981 100644
--- a/src/backend/optimizer/path/pathkeys.c
+++ b/src/backend/optimizer/path/pathkeys.c
@@ -1191,8 +1191,13 @@ partkey_is_bool_constant_for_query(RelOptInfo *partrel, int partkeycol)
PartitionScheme partscheme = partrel->part_scheme;
ListCell *lc;
- /* If the partkey isn't boolean, we can't possibly get a match */
- if (!IsBooleanOpfamily(partscheme->partopfamily[partkeycol]))
+ /*
+ * If the partkey isn't boolean, we can't possibly get a match.
+ *
+ * Partitioning currently can only use built-in AMs, so checking for
+ * built-in boolean opfamilies is good enough.
+ */
+ if (!IsBuiltinBooleanOpfamily(partscheme->partopfamily[partkeycol]))
return false;
/* Check each restriction clause for the partitioned rel */