Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a2a475b

Browse files
committed
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
1 parent 321c287 commit a2a475b

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

src/backend/executor/execReplication.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ static bool tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
3939

4040
/*
4141
* Returns the fixed strategy number, if any, of the equality operator for the
42-
* given index access method, otherwise, InvalidStrategy.
42+
* given operator class, otherwise, InvalidStrategy.
4343
*
4444
* Currently, only Btree and Hash indexes are supported. The other index access
4545
* methods don't have a fixed strategy for equality operation - instead, the
4646
* support routines of each operator class interpret the strategy numbers
4747
* according to the operator class's definition.
4848
*/
4949
StrategyNumber
50-
get_equal_strategy_number_for_am(Oid am)
50+
get_equal_strategy_number(Oid opclass)
5151
{
52+
Oid am = get_opclass_method(opclass);
5253
int ret;
5354

5455
switch (am)
@@ -68,18 +69,6 @@ get_equal_strategy_number_for_am(Oid am)
6869
return ret;
6970
}
7071

71-
/*
72-
* Return the appropriate strategy number which corresponds to the equality
73-
* operator.
74-
*/
75-
static StrategyNumber
76-
get_equal_strategy_number(Oid opclass)
77-
{
78-
Oid am = get_opclass_method(opclass);
79-
80-
return get_equal_strategy_number_for_am(am);
81-
}
82-
8372
/*
8473
* Setup a ScanKey for a search in the relation 'rel' for a tuple 'key' that
8574
* is setup to match 'rel' (*NOT* idxrel!).

src/backend/replication/logical/relation.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "replication/logicalrelation.h"
3030
#include "replication/worker_internal.h"
3131
#include "utils/inval.h"
32+
#include "utils/syscache.h"
3233

3334

3435
static MemoryContext LogicalRepRelMapContext = NULL;
@@ -815,7 +816,7 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap)
815816
* The reasons why only Btree and Hash indexes can be considered as usable are:
816817
*
817818
* 1) Other index access methods don't have a fixed strategy for equality
818-
* operation. Refer get_equal_strategy_number_for_am().
819+
* operation. Refer get_equal_strategy_number().
819820
*
820821
* 2) For indexes other than PK and REPLICA IDENTITY, we need to match the
821822
* local and remote tuples. The equality routine tuples_equal() cannot accept
@@ -833,17 +834,25 @@ bool
833834
IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap)
834835
{
835836
AttrNumber keycol;
836-
837-
/* Ensure that the index access method has a valid equal strategy */
838-
if (get_equal_strategy_number_for_am(idxrel->rd_rel->relam) == InvalidStrategy)
839-
return false;
837+
oidvector *indclass;
840838

841839
/* The index must not be a partial index */
842840
if (!heap_attisnull(idxrel->rd_indextuple, Anum_pg_index_indpred, NULL))
843841
return false;
844842

845843
Assert(idxrel->rd_index->indnatts >= 1);
846844

845+
indclass = (oidvector *) DatumGetPointer(SysCacheGetAttrNotNull(INDEXRELID,
846+
idxrel->rd_indextuple,
847+
Anum_pg_index_indclass));
848+
849+
/* Ensure that the index has a valid equal strategy for each key column */
850+
for (int i = 0; i < idxrel->rd_index->indnkeyatts; i++)
851+
{
852+
if (get_equal_strategy_number(indclass->values[i]) == InvalidStrategy)
853+
return false;
854+
}
855+
847856
/* The leftmost index field must not be an expression */
848857
keycol = idxrel->rd_index->indkey.values[0];
849858
if (!AttributeNumberIsValid(keycol))

src/include/executor/executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ extern void check_exclusion_constraint(Relation heap, Relation index,
657657
/*
658658
* prototypes from functions in execReplication.c
659659
*/
660-
extern StrategyNumber get_equal_strategy_number_for_am(Oid am);
660+
extern StrategyNumber get_equal_strategy_number(Oid opclass);
661661
extern bool RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
662662
LockTupleMode lockmode,
663663
TupleTableSlot *searchslot,

0 commit comments

Comments
 (0)