Skip to content

Commit adeb8d0

Browse files
committed
Do simple hash_search for single entry evictions
Previously we were doing a seqscan for each cache eviction
1 parent 53f7137 commit adeb8d0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pglogical_relcache.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,29 @@ pglogical_relation_close(PGLogicalRelation * rel, LOCKMODE lockmode)
140140
static void
141141
pglogical_relcache_invalidate_callback(Datum arg, Oid reloid)
142142
{
143-
HASH_SEQ_STATUS status;
144143
PGLogicalRelation *entry;
145144

146145
/* Just to be sure. */
147146
if (PGLogicalRelationHash == NULL)
148147
return;
149148

150-
hash_seq_init(&status, PGLogicalRelationHash);
149+
if (reloid != InvalidOid)
150+
{
151+
/* invalidate one entry */
152+
entry = (PGLogicalRelation *) hash_search(PGLogicalRelationHash,
153+
(void*) &reloid, HASH_FIND, NULL);
151154

152-
while ((entry = (PGLogicalRelation *) hash_seq_search(&status)) != NULL)
155+
if (entry != NULL)
156+
entry->reloid = InvalidOid;
157+
}
158+
else
153159
{
154-
if (reloid == InvalidOid || entry->reloid == reloid)
160+
/* invalidate all cache entries */
161+
HASH_SEQ_STATUS status;
162+
163+
hash_seq_init(&status, PGLogicalRelationHash);
164+
165+
while ((entry = (PGLogicalRelation *) hash_seq_search(&status)) != NULL)
155166
entry->reloid = InvalidOid;
156167
}
157168
}

0 commit comments

Comments
 (0)