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 1lOiSU-0002ex-Ee for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Mar 2021 14:56:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lOiRx-0007t3-Ee for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Mar 2021 14:56:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOiRx-0007sw-7W for pgsql-hackers@lists.postgresql.org; Tue, 23 Mar 2021 14:56:05 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOiRu-0006NX-Kp for pgsql-hackers@lists.postgresql.org; Tue, 23 Mar 2021 14:56:04 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 77B8F10DA; Tue, 23 Mar 2021 10:55:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 23 Mar 2021 10:55:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=0aN0EE6gxVkhe1Cv/nBuAvkbneo6R/VFdh8VZO3xyc8=; b=fP+mMpOG DDg1zHrcS50AADptdDIYsbQn9VY5SPKOiYxjNEHs5NOCFLTB1fVuK2ygtWVhVD4o 1S3LZgeP699wkGayEnZrleCRM7sigLdTqO2lBISZqV0EQEnTa1rrblQgV2WDMvRW d0UImXxdrmdmFXwBi6KCW/qQpqrn+gkCQx3I2T0YLxW5gPKmEGWWiCtGZQyxZp5v TMezsNYI1w9WuPjwVYAWlSe1uTrLGNMvaECVTS7L6l2x10SeJ2TFqg0z0ply68NZ Ld2W9G83myZL4IuL8jWMyUafMMyE9gHi91QZQKlhK/vGpOsHe4bQjTFB02sXlseb +uHNM1Wf9ya+dQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudegiedgjeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjfgesthekredttderudenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepueffhfejieeuueffgedvudekgeeltdeviedvieeufeei ieevgfetheeufeethedvnecukfhppeduledtrdelhedrudelrdelheenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghl vhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.19.95]) by mail.messagingengine.com (Postfix) with ESMTPA id 62D571080057; Tue, 23 Mar 2021 10:55:57 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id CEAD92A0FC3; Tue, 23 Mar 2021 11:55:54 -0300 (-03) Date: Tue, 23 Mar 2021 11:55:54 -0300 From: Alvaro Herrera To: Justin Pryzby Cc: Amit Langote , pgsql-hackers@lists.postgresql.org Subject: Re: ALTER TABLE .. DETACH PARTITION CONCURRENTLY Message-ID: <20210323145554.GA7700@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210323141826.GA26281@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Mar-23, Alvaro Herrera wrote: > So I was about ready to get these patches pushed, when I noticed that in > REPEATABLE READ isolation mode it is possible to insert rows violating > an FK referencing the partition that is being detached. I'm not sure > what is a good solution to this problem. ... > I had the idea that the RI code, in REPEATABLE READ mode, used a > different snapshot for the RI queries than the transaction snapshot. I am definitely right about this. So why doesn't it work? The reason is that when SPI goes to execute the query, it obtains a new partition directory, and we tell it to include detached partitions precisely because we're in REPEATABLE READ mode. In other words, the idea that we can blanket use the snapshot-isolation condition to decide whether to include detached partitions or not, is bogus and needs at least the refinement that for any query that comes from the RI system, we need a partition directory that does not include detached partitions. -- Álvaro Herrera 39°49'30"S 73°17'W "El sabio habla porque tiene algo que decir; el tonto, porque tiene que decir algo" (Platon).