On 2022/8/17 10:03, Tom Lane wrote:
Quan Zongliang <quanzongli...@yeah.net> writes:
1. When using extended PGroonga
...
3. Neither ID = 'f' nor id= 't' can use the index correctly.

This works fine for btree indexes.  I think the actual problem
is that IsBooleanOpfamily only accepts the btree and hash
opclasses, and that's what needs to be improved.  Your proposed
patch fails to do that, which makes it just a crude hack that
solves some aspects of the issue (and probably breaks other
things).

It might work to change IsBooleanOpfamily so that it checks to
see whether BooleanEqualOperator is a member of the opclass.
That's basically what we need to know before we dare generate
substitute index clauses.  It's kind of an expensive test
though, and the existing coding assumes that IsBooleanOpfamily
is cheap ...

                        regards, tom lane

New patch attached.

It seems that partitions do not use AM other than btree and hash.
Rewrite only indxpath.c and check if it is a custom AM.
diff --git a/src/backend/optimizer/path/indxpath.c 
b/src/backend/optimizer/path/indxpath.c
index 7d176e7b00..30df5cb2f6 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -23,6 +23,7 @@
 #include "catalog/pg_operator.h"
 #include "catalog/pg_opfamily.h"
 #include "catalog/pg_type.h"
+#include "commands/defrem.h"
 #include "nodes/makefuncs.h"
 #include "nodes/nodeFuncs.h"
 #include "nodes/supportnodes.h"
@@ -2295,7 +2296,7 @@ match_clause_to_indexcol(PlannerInfo *root,
 
        /* First check for boolean-index cases. */
        opfamily = index->opfamily[indexcol];
-       if (IsBooleanOpfamily(opfamily))
+       if (IsBooleanAmOpfamily(index->relam, opfamily))
        {
                iclause = match_boolean_index_clause(root, rinfo, indexcol, 
index);
                if (iclause)
diff --git a/src/include/catalog/pg_opfamily.h 
b/src/include/catalog/pg_opfamily.h
index 8dc9ce01bb..5c4cc616d8 100644
--- a/src/include/catalog/pg_opfamily.h
+++ b/src/include/catalog/pg_opfamily.h
@@ -58,6 +58,12 @@ DECLARE_UNIQUE_INDEX_PKEY(pg_opfamily_oid_index, 2755, 
OpfamilyOidIndexId, on pg
 #define IsBooleanOpfamily(opfamily) \
        ((opfamily) == BOOL_BTREE_FAM_OID || (opfamily) == BOOL_HASH_FAM_OID)
 
+#define IsBooleanAmOpfamily(amid, opfamily) \
+       ((opfamily) == BOOL_BTREE_FAM_OID || (opfamily) == BOOL_HASH_FAM_OID || 
\
+               ((amid) >= FirstNormalObjectId && \
+                               OidIsValid(GetDefaultOpClass(BOOLOID, (amid)))) 
\
+       )
+
 #endif                                                 /* 
EXPOSE_TO_CLIENT_CODE */
 
 #endif                                                 /* PG_OPFAMILY_H */

Reply via email to