From: Quan Zongliang <quanzongliang@yeah.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Bug: When user-defined AM is used, the index path cannot be selected correctly
Date: Wed, 17 Aug 2022 17:11:43 +0800
Message-ID: <7f498182-6736-8fee-d2fe-452e336de795@yeah.net> (raw)
In-Reply-To: <1606486.1660701833@sss.pgh.pa.us>
References: <f293b91d-1d46-d386-b6bb-4b06ff5c667b@yeah.net>
<1606486.1660701833@sss.pgh.pa.us>
On 2022/8/17 10:03, Tom Lane wrote:
> Quan Zongliang <quanzongliang@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.
Attachments:indxpath.patch (text/plain, 1.5K) downloaddiff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.cindex 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.hindex 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 instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: quanzongliang@yeah.net, tgl@sss.pgh.pa.us
Subject: Re: Bug: When user-defined AM is used, the index path cannot be selected correctly
In-Reply-To: <7f498182-6736-8fee-d2fe-452e336de795@yeah.net>
References: <f293b91d-1d46-d386-b6bb-4b06ff5c667b@yeah.net> <1606486.1660701833@sss.pgh.pa.us> <7f498182-6736-8fee-d2fe-452e336de795@yeah.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox