1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-26 01:22:12 +03:00

Replace get_equal_strategy_number_for_am() by get_equal_strategy_number()

get_equal_strategy_number_for_am() gets the equal strategy number for
an AM.  This currently only supports btree and hash.  In the more
general case, this also depends on the operator class (see for example
GistTranslateStratnum()).  To support that, replace this function with
get_equal_strategy_number() that takes an opclass and derives it from
there.  (This function already existed before as a static function, so
the signature is kept for simplicity.)

This patch is only a refactoring, it doesn't add support for other
index AMs such as gist.  This will be done separately.

Reviewed-by: Paul Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CA+renyUApHgSZF9-nd-a0+OPGharLQLO=mDHcY4_qQ0+noCUVg@mail.gmail.com
This commit is contained in:
Peter Eisentraut
2024-12-10 12:53:27 +01:00
parent 321c287351
commit a2a475b011
3 changed files with 18 additions and 20 deletions

View File

@ -29,6 +29,7 @@
#include "replication/logicalrelation.h"
#include "replication/worker_internal.h"
#include "utils/inval.h"
#include "utils/syscache.h"
static MemoryContext LogicalRepRelMapContext = NULL;
@ -815,7 +816,7 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap)
* The reasons why only Btree and Hash indexes can be considered as usable are:
*
* 1) Other index access methods don't have a fixed strategy for equality
* operation. Refer get_equal_strategy_number_for_am().
* operation. Refer get_equal_strategy_number().
*
* 2) For indexes other than PK and REPLICA IDENTITY, we need to match the
* local and remote tuples. The equality routine tuples_equal() cannot accept
@ -833,10 +834,7 @@ bool
IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap)
{
AttrNumber keycol;
/* Ensure that the index access method has a valid equal strategy */
if (get_equal_strategy_number_for_am(idxrel->rd_rel->relam) == InvalidStrategy)
return false;
oidvector *indclass;
/* The index must not be a partial index */
if (!heap_attisnull(idxrel->rd_indextuple, Anum_pg_index_indpred, NULL))
@ -844,6 +842,17 @@ IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap)
Assert(idxrel->rd_index->indnatts >= 1);
indclass = (oidvector *) DatumGetPointer(SysCacheGetAttrNotNull(INDEXRELID,
idxrel->rd_indextuple,
Anum_pg_index_indclass));
/* Ensure that the index has a valid equal strategy for each key column */
for (int i = 0; i < idxrel->rd_index->indnkeyatts; i++)
{
if (get_equal_strategy_number(indclass->values[i]) == InvalidStrategy)
return false;
}
/* The leftmost index field must not be an expression */
keycol = idxrel->rd_index->indkey.values[0];
if (!AttributeNumberIsValid(keycol))