public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ashutosh Sharma <[email protected]>
To: pgsql-hackers <[email protected]>
Subject: How about using dirty snapshots to locate dependent objects?
Date: Thu, 6 Jun 2024 17:59:00 +0530
Message-ID: <CAE9k0Pnznev=s0t=M61fiO4==cxsxt4nbTxe42zzEJscaekwVA@mail.gmail.com> (raw)
Hello everyone,
At present, we use MVCC snapshots to identify dependent objects. This
implies that if a new dependent object is inserted within a transaction
that is still ongoing, our search for dependent objects won't include this
recently added one. Consequently, if someone attempts to drop the
referenced object, it will be dropped, and when the ongoing transaction
completes, we will end up having an entry for a referenced object that has
already been dropped. This situation can lead to an inconsistent state.
Below is an example illustrating this scenario:
Session 1:
- create table t1(a int);
- insert into t1 select i from generate_series(1, 10000000) i;
- create extension btree_gist;
- create index i1 on t1 using gist( a );
Session 2: (While the index creation in session 1 is in progress, drop the
btree_gist extension)
- drop extension btree_gist;
Above command succeeds and so does the create index command running in
session 1, post this, if we try running anything on table t1, i1, it fails
with an error: "cache lookup failed for opclass ..."
Attached is the patch that I have tried, which seems to be working for me.
It's not polished and thoroughly tested, but just sharing here to clarify
what I am trying to suggest. Please have a look and let me know your
thoughts.
--
With Regards,
Ashutosh Sharma.
Attachments:
[application/octet-stream] use-dirty-snapshots-to-find-dependent-objects.patch (945B, ../CAE9k0Pnznev=s0t=M61fiO4==cxsxt4nbTxe42zzEJscaekwVA@mail.gmail.com/3-use-dirty-snapshots-to-find-dependent-objects.patch)
download | inline diff:
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index d4b5b2ade1..78a73c2e9a 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -449,6 +449,7 @@ findDependentObjects(const ObjectAddress *object,
int maxDependentObjects;
ObjectAddressStack mystack;
ObjectAddressExtra extra;
+ SnapshotData SnapshotDirty;
/*
* If the target object is already being visited in an outer recursion
@@ -823,8 +824,14 @@ findDependentObjects(const ObjectAddress *object,
else
nkeys = 2;
+ /*
+ * We use a "dirty snapshot" to read rows modified by transactions still
+ * in-progress, which wouldn't be visible with normal snapshots.
+ */
+ InitDirtySnapshot(SnapshotDirty);
+
scan = systable_beginscan(*depRel, DependReferenceIndexId, true,
- NULL, nkeys, key);
+ &SnapshotDirty, nkeys, key);
while (HeapTupleIsValid(tup = systable_getnext(scan)))
{
view thread (3+ messages) latest in thread
reply
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: How about using dirty snapshots to locate dependent objects?
In-Reply-To: <CAE9k0Pnznev=s0t=M61fiO4==cxsxt4nbTxe42zzEJscaekwVA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox