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

Commit 328c709

Browse files
committed
Optimize RelationFindReplTupleSeq() for CLOBBER_CACHE_ALWAYS.
Specifically, remember lookup_type_cache() results instead of retrieving them once per comparison. Under CLOBBER_CACHE_ALWAYS, this reduced src/test/subscription/t/001_rep_changes.pl elapsed time by an order of magnitude, which reduced check-world elapsed time by 9%. Discussion: https://postgr.es/m/20200406085420.GC162712@rfd.leadboat.com
1 parent 4216858 commit 328c709

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/backend/executor/execReplication.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ RelationFindReplTupleByIndex(Relation rel, Oid idxoid,
225225
* Compare the tuples in the slots by checking if they have equal values.
226226
*/
227227
static bool
228-
tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2)
228+
tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2,
229+
TypeCacheEntry **eq)
229230
{
230231
int attrnum;
231232

@@ -256,12 +257,18 @@ tuples_equal(TupleTableSlot *slot1, TupleTableSlot *slot2)
256257

257258
att = TupleDescAttr(slot1->tts_tupleDescriptor, attrnum);
258259

259-
typentry = lookup_type_cache(att->atttypid, TYPECACHE_EQ_OPR_FINFO);
260-
if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
261-
ereport(ERROR,
262-
(errcode(ERRCODE_UNDEFINED_FUNCTION),
263-
errmsg("could not identify an equality operator for type %s",
264-
format_type_be(att->atttypid))));
260+
typentry = eq[attrnum];
261+
if (typentry == NULL)
262+
{
263+
typentry = lookup_type_cache(att->atttypid,
264+
TYPECACHE_EQ_OPR_FINFO);
265+
if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
266+
ereport(ERROR,
267+
(errcode(ERRCODE_UNDEFINED_FUNCTION),
268+
errmsg("could not identify an equality operator for type %s",
269+
format_type_be(att->atttypid))));
270+
eq[attrnum] = typentry;
271+
}
265272

266273
if (!DatumGetBool(FunctionCall2Coll(&typentry->eq_opr_finfo,
267274
att->attcollation,
@@ -290,12 +297,15 @@ RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
290297
TupleTableSlot *scanslot;
291298
TableScanDesc scan;
292299
SnapshotData snap;
300+
TypeCacheEntry **eq;
293301
TransactionId xwait;
294302
bool found;
295303
TupleDesc desc PG_USED_FOR_ASSERTS_ONLY = RelationGetDescr(rel);
296304

297305
Assert(equalTupleDescs(desc, outslot->tts_tupleDescriptor));
298306

307+
eq = palloc0(sizeof(*eq) * outslot->tts_tupleDescriptor->natts);
308+
299309
/* Start a heap scan. */
300310
InitDirtySnapshot(snap);
301311
scan = table_beginscan(rel, &snap, 0, NULL);
@@ -309,7 +319,7 @@ RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
309319
/* Try to find the tuple */
310320
while (table_scan_getnextslot(scan, ForwardScanDirection, scanslot))
311321
{
312-
if (!tuples_equal(scanslot, searchslot))
322+
if (!tuples_equal(scanslot, searchslot, eq))
313323
continue;
314324

315325
found = true;

0 commit comments

Comments
 (0)