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 1sTRTo-00GJVL-8o for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Jul 2024 19:35:24 +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 1sTRTm-00CmKc-M3 for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Jul 2024 19:35:22 +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 1sTRTl-00CmKT-HL for pgsql-bugs@lists.postgresql.org; Mon, 15 Jul 2024 19:35:22 +0000 Received: from fhigh2-smtp.messagingengine.com ([103.168.172.153]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sTRTi-002DXX-H1 for pgsql-bugs@lists.postgresql.org; Mon, 15 Jul 2024 19:35:20 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id F04571147FAD; Mon, 15 Jul 2024 15:35:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 15 Jul 2024 15:35:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1721072116; x= 1721158516; bh=R158fsFqEoZdyUsUvVl9l3xLpKkzvIcB9XD3dJG5cL8=; b=Y JqiuPhWL5uBCPnj7IU3FtGI7lAfYsXDylgCksOqw1oE7s9E/7Bh9UB0Y/+lh+EP5 t4kpqM7vzp9RNNETzn3yqQEFXGNlzGSa+P1lNLoowVBtAune/AsV4maLGC0O9pMu CpeNIvkBPM3OKNPmWHTNPHpexxjeByPS7y9iRBdfff/fREnNPAnB0UUxeoKPVfSu Ew3CHXD8hrxnlOXk4RRzUcmMOwv4iyG3azLkBWdPYue4rea6LCkKo9fikJoT1Mqc EwckKJOQ8cg+8GbaYXWyp+N6VPT+RgKeMhrvhqYCzFJcvmOGYfw7pxek6XWiUz1W LBkX5rtOVjh+DYnXKtXMQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrgedvgddufeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfggtggugfgjsehtke ertddttdejnecuhfhrohhmpegrlhhvhhgvrhhrvgcuoegrlhhvhhgvrhhrvgesrghlvhhh rdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpefgiedtvddtgeeuvedvfeelvd euvdeliedvfedtheetgfffvedukeefkedtudfhteenucffohhmrghinhepphhoshhtghhr rdgvshdpvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhi phdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Jul 2024 15:35:15 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1721072113; bh=w8VVmgCd5cixb7GxE3yCbmRCZcj8479btR3/N/bUEPU=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=PriXYSGol1GmnQ+43kgHWRvWdD1B3mRaR3JIfpUUnrF26WhNajcl0Yl9Y8z8rRE1Y 4jWX6MQmNiux3ea6AGpgoyjBqxTnfmOIcDuPuyewHJBrlERemZ9FYJkg1sWogb5xto wfCHwcH27sifbqubYuTkKvQ8DvJIXaHSUU53lwykQE5S4uXHoQoMrOGop9N6+IGqw8 /C8A9VRHVlE6iZ0PGzbrfe7xyrnDkZBVVI3yhVcJQpGakzrCGFGmSEsm+Dvivw7WIp 6KWZA6Id0IWdG32Q9aFtkGkVcR2pUaFA5GwDqyA52uLgL+NxVPliD4MUR+fI1R4BIR LWjU6hMaQMMzQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id B053F149; Mon, 15 Jul 2024 21:35:13 +0200 (CEST) Date: Mon, 15 Jul 2024 21:35:13 +0200 From: alvherre To: feichanghong Cc: pgsql-bugs Subject: Re: BUG #18371: There are wrong constraint residues when detach hash partiton concurrently Message-ID: <202407151935.jzia4tm6j3kj@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-Feb-29, feichanghong wrote: > > This can work normally on range partitions. However, the constraint on hash > > partitions uses satisfies_hash_partition with the OID of the parent table, and > > the newly created constraint does not take effect. For example, in the following > > case, although there is a t_p1_a_check constraint on t_p1, it is still possible > > to perform an insert: > What I said here is wrong, the constraints on the hash partition will also take > effect. But this constraint depends on the oid of the parent partition. We should definitely not have this constraint on hash-partition tables after the detach. However, I wonder if instead of adding it and later removing it as you propose, it wouldn't be better to just not add it in the first place. As a first step, I tried commenting out and found that no interesting test fails (only alter_table.sql fails but only because the constraint is not there when looking for it specifically.) The current code does not explain *why* we have to add this constraint, and I had forgotten, so I went to look at the first patch submission in that thread [1] and saw this comment there: + /* + * Concurrent mode has to work harder; first we add a new constraint to the + * partition that matches the partition constraint. The reason for this is + * that the planner may have made optimizations that depend on the + * constraint. XXX Isn't it sufficient to invalidate the partition's + * relcache entry? I'm trying to figure out whether it's possible that the planner would make optimizations based on the hashing function. Quite possibly it won't. If that's so, then we should just not make the constraint at all, which would make the fix even simpler. I also wonder, maybe that XXX comment (which I removed before committing the patch) is right and we don't actually need the constraint with _any_ partition strategy, not just hash. [1] https://postgr.es/m/20200803234854.GA24158@alvherre.pgsql -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/