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

Commit bcbaac7

Browse files
danolivokelvich
authored andcommitted
Fix the bug [PGPRO-3034]
1. Update build_index_scan_key() routine with new version of build_replindex_scan_key() routine from execReplication.c module. 2. Small improvement of process_remote_update() 3. ExtractReplicaIdentity() in heapam.c - allow return automatically added replica identity index. 4. relcache.c - add CanbeReplicaIdentityIndex() routine that check the index as possibility to stay as replica identity index. This code is a part of ATExecReplicaIdentity() routine from tablecmds.c.
1 parent eff8852 commit bcbaac7

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/pglogical_apply.c

+17-20
Original file line numberDiff line numberDiff line change
@@ -342,60 +342,59 @@ static bool
342342
build_index_scan_key(ScanKey skey, Relation rel, Relation idxrel, TupleData *tup)
343343
{
344344
int attoff;
345-
Datum indclassDatum;
346-
Datum indkeyDatum;
347345
bool isnull;
346+
Datum indclassDatum;
348347
oidvector *opclass;
349-
int2vector *indkey;
348+
int2vector *indkey = &idxrel->rd_index->indkey;
350349
bool hasnulls = false;
351350

351+
Assert(RelationGetReplicaIndex(rel) == RelationGetRelid(idxrel));
352+
352353
indclassDatum = SysCacheGetAttr(INDEXRELID, idxrel->rd_indextuple,
353354
Anum_pg_index_indclass, &isnull);
354355
Assert(!isnull);
355356
opclass = (oidvector *) DatumGetPointer(indclassDatum);
356357

357-
indkeyDatum = SysCacheGetAttr(INDEXRELID, idxrel->rd_indextuple,
358-
Anum_pg_index_indkey, &isnull);
359-
Assert(!isnull);
360-
indkey = (int2vector *) DatumGetPointer(indkeyDatum);
361-
362-
358+
/* Build scankey for every attribute in the index. */
363359
for (attoff = 0; attoff < IndexRelationGetNumberOfKeyAttributes(idxrel); attoff++)
364360
{
365361
Oid operator;
366362
Oid opfamily;
367363
RegProcedure regop;
368364
int pkattno = attoff + 1;
369365
int mainattno = indkey->values[attoff];
370-
Oid atttype = attnumTypeId(rel, mainattno);
371366
Oid optype = get_opclass_input_type(opclass->values[attoff]);
372367

368+
/*
369+
* Load the operator info. We need this to get the equality operator
370+
* function for the scan key.
371+
*/
373372
opfamily = get_opclass_family(opclass->values[attoff]);
374373

375374
operator = get_opfamily_member(opfamily, optype,
376375
optype,
377376
BTEqualStrategyNumber);
378-
379377
if (!OidIsValid(operator))
380-
mtm_log(ERROR,
381-
"could not lookup equality operator for type %u, optype %u in opfamily %u",
382-
atttype, optype, opfamily);
378+
elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
379+
BTEqualStrategyNumber, optype, optype, opfamily);
383380

384381
regop = get_opcode(operator);
385382

386-
/* FIXME: convert type? */
383+
/* Initialize the scankey. */
387384
ScanKeyInit(&skey[attoff],
388385
pkattno,
389386
BTEqualStrategyNumber,
390387
regop,
391388
tup->values[mainattno - 1]);
392389

390+
/* Check for null value. */
393391
if (tup->isnull[mainattno - 1])
394392
{
395393
hasnulls = true;
396394
skey[attoff].sk_flags |= SK_ISNULL;
397395
}
398396
}
397+
399398
return hasnulls;
400399
}
401400

@@ -742,7 +741,7 @@ read_tuple_parts(StringInfo s, Relation rel, TupleData *tup)
742741
case 'u': /* unchanged column */
743742
tup->isnull[i] = true;
744743
tup->changed[i] = false;
745-
tup->values[i] = 0xdeadbeef; /* make bad usage more obvious */
744+
tup->values[i] = NULL;
746745
break;
747746

748747
case 'b': /* binary format */
@@ -1240,10 +1239,8 @@ process_remote_update(StringInfo s, Relation rel)
12401239
action);
12411240

12421241
estate = create_rel_estate(rel);
1243-
oldslot = ExecInitExtraTupleSlot(estate, NULL);
1244-
ExecSetSlotDescriptor(oldslot, tupDesc);
1245-
newslot = ExecInitExtraTupleSlot(estate, NULL);
1246-
ExecSetSlotDescriptor(newslot, tupDesc);
1242+
oldslot = ExecInitExtraTupleSlot(estate, tupDesc);
1243+
newslot = ExecInitExtraTupleSlot(estate, tupDesc);
12471244

12481245
if (action == 'K')
12491246
{

0 commit comments

Comments
 (0)