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 1sFDAl-0005FV-DL for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jun 2024 13:28:56 +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 1sFD9l-000Cje-1U for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jun 2024 13:27:53 +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 1sFD9k-000CjV-Me for pgsql-hackers@lists.postgresql.org; Thu, 06 Jun 2024 13:27:53 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sFD9g-0000J2-K2 for pgsql-hackers@postgresql.org; Thu, 06 Jun 2024 13:27:52 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4210aa012e5so11218105e9.0 for ; Thu, 06 Jun 2024 06:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717680466; x=1718285266; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jIxOseew9+ZBKmcfdGtRTS/6u5YExzMAQilufUXERgI=; b=HtLFR3ZWQDlwr7O+5/bKAMmUR1MH5SECbX5XQhdYHOEAPbS8L8TVHSS/5A0XdAs1zE u9DlhOPURVigRjKipl2cCbWOeg4Ii6lx93d5KkhMsCkWwODT+LUpzwZ5KlUEowLDCyV8 jOiG6HSZD2vdUFIK5NvCEcRHmTDJb1Ha8iXJTllv0folqsuinkYTA/GmQV595+qkGok7 Lt3dOruzn6OvWHUabpTdgqwqjNfX1Zi1fWZWsNXmVtBlDbfkVCfguzZuVuu116JFTlDQ fwxoXuCW9S0pklv0U3doAEI5NvaBAKB/REnxIc8NM06lIfYgOgAUkabRfAlU9itw+XfE Mf3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717680466; x=1718285266; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jIxOseew9+ZBKmcfdGtRTS/6u5YExzMAQilufUXERgI=; b=XHuYzldA7mZxxt3qpWyTxnbPbqlwIJYvxJzpHtfMoowoDJgim7BBcT2XCS+kzLqNzF l0K/dn8mrUgTXEkPG3gj5v1knUjhCDKV5rJYORKfklflaxamRjrh/fC5qOWn8lC2If0a RnvHtVEmG9oG+qsTNkgBFCDcmOiOiA0P8rvBNy/XF4UPVxuFsBL3ntXz4ErUSMr2VzXR ZmO8ycUcjRlpZ9MJJmHYiMbopJW2/hifIM6/NyiPbowYJTncKJt7VLX77AI+7OnloKd6 HKP7ISTxeIU+ctLG343ByE/Tw7Q+ghmhnKeJF0wdxRll9scwd1Z8MqYzcDaVD7Nv6IeM iuWg== X-Gm-Message-State: AOJu0YxHGwZb93EpmFIVhw8PiLAp43GY0mU18GSnuXsFAy7cYp2iMpic F1zY2OI6PWr5nQbPRfV5/MO6SIMgogA4sYLLwJBGrRGFAe2tJkTLbPITwQ== X-Google-Smtp-Source: AGHT+IFrtn85qDdWYqxOvjXt7A/wVbPmoGlXa1NW1hKvns2VNSRekCM1TijXrZHcjqQpVhCnIKqUcg== X-Received: by 2002:a05:600c:4e08:b0:421:5242:ee2 with SMTP id 5b1f17b1804b1-42156f8cfb8mr44391505e9.25.1717680465987; Thu, 06 Jun 2024 06:27:45 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4215810242fsm54966495e9.12.2024.06.06.06.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 06:27:45 -0700 (PDT) Date: Thu, 6 Jun 2024 13:27:44 +0000 From: Bertrand Drouvot To: Ashutosh Sharma Cc: pgsql-hackers Subject: Re: How about using dirty snapshots to locate dependent objects? Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jun 06, 2024 at 05:59:00PM +0530, Ashutosh Sharma wrote: > 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. Thanks for the patch proposal! The patch does not fix the other way around: - session 1: BEGIN; DROP extension btree_gist; - session 2: create index i1 on t1 using gist( a ); - session 1: commits while session 2 is creating the index and does not address all the possible orphaned dependencies cases. There is an ongoing thread (see [1]) to fix the orphaned dependencies issue. v9 attached in [1] fixes the case you describe here. [1]: https://www.postgresql.org/message-id/flat/ZiYjn0eVc7pxVY45%40ip-10-97-1-34.eu-west-3.compute.internal Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com