From: Masahiko Sawada <msawada@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use an index scan in RemoveSubscriptionRel() when possible.
Date: Fri, 20 Nov 2026 18:22:00 +0000
Message-ID: <E1xUTFH-00000000Xvx-3tl1@gemulon.postgresql.org> (raw)
Use an index scan in RemoveSubscriptionRel() when possible.
Previously, RemoveSubscriptionRel() scanned all of pg_subscription_rel
with a heap scan, even when given a relation OID that the (srrelid,
srsubid) primary key index could serve. Since it's called for every
dropped relation, dropping tables on a subscriber with a large
pg_subscription_rel could be slow.
Use the index when a relation OID is given. DROP SUBSCRIPTION passes
only a subscription OID (the second index column), so it keeps using a
heap scan. In a performance test with 100,000 entries in
pg_subscription_rel, dropping 1,000 tables became 10x faster.
Author: Manu <manuelreyesbravo@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/179489354788.348371.16745415952616502664@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/72146c7db15773ba0660c7c7e0284e3b1116ae2f
Modified Files
--------------
src/backend/catalog/pg_subscription.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: msawada@postgresql.org
Subject: Re: pgsql: Use an index scan in RemoveSubscriptionRel() when possible.
In-Reply-To: <E1xUTFH-00000000Xvx-3tl1@gemulon.postgresql.org>
References: <E1xUTFH-00000000Xvx-3tl1@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox