[PATCH] Use direct hash lookup in logicalrep_partmap_invalidate_cb()

From: DaeMyung Kang <charsyam(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: DaeMyung Kang <charsyam(at)gmail(dot)com>
Subject: [PATCH] Use direct hash lookup in logicalrep_partmap_invalidate_cb()
Date: 2026-04-17 17:44:50
Message-ID: 20260417174450.4158878-1-charsyam@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


LogicalRepPartMap is keyed by the partition's OID, which is assigned
to entry->relmapentry.localreloid when the entry is populated in
logicalrep_partition_open(). The invalidation callback therefore
does not need to iterate over every entry to find the one matching
the invalidated relation OID; a single hash_search(HASH_FIND) on
reloid suffices.

This replaces an O(N) hash_seq_search loop with an O(1) lookup and
removes the longstanding "TODO, use inverse lookup hashtable?"
comment. An Assert in logicalrep_partition_open() documents the
partOid == entry->relmapentry.localreloid invariant that the new
path relies on.
---

Tested on an --enable-cassert build: the full src/test/subscription
TAP suite (39 files, 579 tests) passes, including 013_partition.pl
which exercises the partmap invalidation path via ADD COLUMN on a
partitioned root (cascades a relcache inval to every leaf partition).

src/backend/replication/logical/relation.c | 23 +++++++++-------------
1 file changed, 9 insertions(+), 14 deletions(-)

Attachment Content-Type Size
0001-Use-direct-hash-lookup-in-logicalrep_partmap_invalid.patch text/x-patch 1.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2026-04-17 18:50:53 Re: Heads Up: cirrus-ci is shutting down June 1st
Previous Message SATYANARAYANA NARLAPURAM 2026-04-17 17:40:39 Re: [PATCH] Compressed TOAST data corruption with REPACK CONCURRENTLY