Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLX79-0006Ww-8U for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2020 19:08:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jLX77-0008K9-Sw for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2020 19:08:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLX77-0008K2-Lo for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2020 19:08:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLX75-0002XS-HE for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2020 19:08:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 036J8nWn003020; Mon, 6 Apr 2020 15:08:49 -0400 From: Tom Lane To: Alvaro Herrera cc: Mithun Cy , PostgreSQL Hackers Subject: Re: DROP OWNED CASCADE vs Temp tables In-reply-to: <20200123171423.GA25918@alvherre.pgsql> References: <20200123171423.GA25918@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Thu, 23 Jan 2020 14:14:23 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3018.1586200129.1@sss.pgh.pa.us> Date: Mon, 06 Apr 2020 15:08:49 -0400 Message-ID: <3019.1586200129@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > On 2020-Jan-14, Alvaro Herrera wrote: >> Hmm, it seems to be doing it differently. Maybe it should be acquiring >> locks on all objects in that nested loop and verified them for >> existence, so that when it calls performMultipleDeletions the objects >> are already locked, as you say. > Yeah, this solves the reported bug. I looked this over and think it should be fine. There will be cases where we get a deadlock error, but such risks existed anyway, since we'd have acquired all the same locks later in the process. > This is not a 100% solution: there's the cases when the user is removed > from an ACL and from a policy, and those deletions are done directly > instead of accumulating to the end for a mass deletion. Let's worry about that when and if we get field complaints. > I had to export AcquireDeletionLock (previously a static in > dependency.c). I wonder if I should export ReleaseDeletionLock too, for > symmetry. Hmmm ... there is an argument for doing ReleaseDeletionLock in the code paths where you discover that the object's been deleted. Holding a lock on a no-longer-existent object OID should be harmless from a deadlock standpoint; but it does represent useless consumption of a shared lock table entry, and that's a resource this operation could already burn with abandon. Also, if we're exporting these, it's worth expending a bit more effort on their header comments. In particular AcquireDeletionLock should describe its flags argument; perhaps along the lines of "Accepts the same flags as performDeletion (though currently only PERFORM_DELETION_CONCURRENTLY does anything)". regards, tom lane