Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sFCF2-007w9R-5L for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jun 2024 12:29:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sFCF2-000r3k-1n for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jun 2024 12:29:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sFCF1-000r3c-OW for pgsql-hackers@lists.postgresql.org; Thu, 06 Jun 2024 12:29:15 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sFCEz-003jft-8g for pgsql-hackers@postgresql.org; Thu, 06 Jun 2024 12:29:14 +0000 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2c1b542ae9eso679249a91.1 for ; Thu, 06 Jun 2024 05:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717676951; x=1718281751; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=wX3E6YEdZ3xGEC153eQ2DaGU0yJwFBuTNAi79xDu6Ks=; b=ehGg/5mpdHreUqQGiPTZlogxv7gkmOPnvCkrDdo89EvdT+G86fIAvkyfRSBOI7NQ/P Vo+8RCVTTNpOx+LDSSLrN7Dphlytk61vBzl5mOFLbURyg7QcgJK0o326GZnMneubzWFV VobotyWTi6woOogHzwrg4txWnZvgB6L7XkFFpU8RAWpz0uXLoKG7uJsK29vUeASLnqIf L4Zlg1tVcpIm330Hyx4kr15MvIaE+ai6KNdPqcH9sxeZ3c1NeI6eOZNZpIe2bY2Ak0sP GOs+czL4TUl6jiEFNbbAdP3IgpOzxzk94TYMr0/buJMdtc4msn6ZfmILX9XtA5nF5gjo zhEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717676951; x=1718281751; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wX3E6YEdZ3xGEC153eQ2DaGU0yJwFBuTNAi79xDu6Ks=; b=OtCFIMxFh6SIe5w4RmhfMxqknx6m3sENx3M0+E4fEPM/bqiIi2SnuS4VwHqbT1T8SO vDeWx0L++YnFOucgKnAyZR+HibcpFp60WlgcfMWAdKAkMSPOsAPLvsH+GCOM13hhJa2R 4Xsd750md8suNvbrhejO6k3/XZgVI6wvYRLfkwvRZRBqQdwOqHBVBt05FkCD6tCGgJNN +AWcH2JmTLt8tdehb093lRzurG1h8lJZVtku4L3SFLuacXL5pec5W/aw6H3oeH/byy/N B9ewNNRAd3kgnP9M3KR7gcGt4FuvC39eRwZDf09KrvVSL3rnRws58mxYFdgSYah8jtIY 7Xag== X-Gm-Message-State: AOJu0YwMj4QbsP5X3fnEZOmqY299ZCYHQlyGhHBfWrFyLcs/52RIfhlv N7QMGsdf/+1MKMkQroh8bcU8Q+5w1joG//yGGav5s5InG+J3FVtwY1ElH0drsEj8CnI+sVfhoCu RkxEo+tKsQVw8MHSbDULy6ie3AISxaM5N X-Google-Smtp-Source: AGHT+IELnPE0O0VsjPJedWBCjAfgS/XwWC46zdGSibg7yhXScmx6oWROFSp0nZKBGTyVts1jdnM2qkCRkWHOECCSCsA= X-Received: by 2002:a17:90b:110f:b0:2bd:d6cc:c305 with SMTP id 98e67ed59e1d1-2c27dd578bfmr4714378a91.49.1717676951270; Thu, 06 Jun 2024 05:29:11 -0700 (PDT) MIME-Version: 1.0 From: Ashutosh Sharma Date: Thu, 6 Jun 2024 17:59:00 +0530 Message-ID: Subject: How about using dirty snapshots to locate dependent objects? To: pgsql-hackers Content-Type: multipart/mixed; boundary="000000000000851ab3061a37d4c3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000851ab3061a37d4c3 Content-Type: multipart/alternative; boundary="000000000000851ab2061a37d4c1" --000000000000851ab2061a37d4c1 Content-Type: text/plain; charset="UTF-8" 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. --000000000000851ab2061a37d4c1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello everyone,

At present, we use MVCC snapshots t= o identify dependent objects. This implies that if a new dependent object i= s inserted within a transaction that is still ongoing, our search for depen= dent objects won't include this recently added one. Consequently, if so= meone 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 ref= erenced 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;
- crea= te index i1 on t1 using gist( a );

Session 2: (While the index creat= ion in session 1 is in progress, drop the btree_gist extension)
- drop e= xtension btree_gist;

Above command succeeds and so does the create = index command running in session 1, post this, if we try running anything o= n table t1, i1, it fails with an error: "cache lookup failed for opcla= ss ..."

Attached is the patch that I have tried, which seems to= be working for me. It's not polished and thoroughly tested, but just s= haring here to clarify what I am trying to suggest. Please have a look and = let me know your thoughts.

--
With Regards= ,
Ashutosh Sharma.
--000000000000851ab2061a37d4c1-- --000000000000851ab3061a37d4c3 Content-Type: application/octet-stream; name="use-dirty-snapshots-to-find-dependent-objects.patch" Content-Disposition: attachment; filename="use-dirty-snapshots-to-find-dependent-objects.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lx38f3yi0 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2NhdGFsb2cvZGVwZW5kZW5jeS5jIGIvc3JjL2JhY2tl bmQvY2F0YWxvZy9kZXBlbmRlbmN5LmMKaW5kZXggZDRiNWIyYWRlMS4uNzhhNzNjMmU5YSAxMDA2 NDQKLS0tIGEvc3JjL2JhY2tlbmQvY2F0YWxvZy9kZXBlbmRlbmN5LmMKKysrIGIvc3JjL2JhY2tl bmQvY2F0YWxvZy9kZXBlbmRlbmN5LmMKQEAgLTQ0OSw2ICs0NDksNyBAQCBmaW5kRGVwZW5kZW50 T2JqZWN0cyhjb25zdCBPYmplY3RBZGRyZXNzICpvYmplY3QsCiAJaW50CQkJbWF4RGVwZW5kZW50 T2JqZWN0czsKIAlPYmplY3RBZGRyZXNzU3RhY2sgbXlzdGFjazsKIAlPYmplY3RBZGRyZXNzRXh0 cmEgZXh0cmE7CisJU25hcHNob3REYXRhIFNuYXBzaG90RGlydHk7CiAKIAkvKgogCSAqIElmIHRo ZSB0YXJnZXQgb2JqZWN0IGlzIGFscmVhZHkgYmVpbmcgdmlzaXRlZCBpbiBhbiBvdXRlciByZWN1 cnNpb24KQEAgLTgyMyw4ICs4MjQsMTQgQEAgZmluZERlcGVuZGVudE9iamVjdHMoY29uc3QgT2Jq ZWN0QWRkcmVzcyA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