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 1srY6t-002dbs-Sd for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Sep 2024 07:31: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 1srY6r-0007BW-EO for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Sep 2024 07:31:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srY6q-00073F-Ks for pgsql-hackers@lists.postgresql.org; Fri, 20 Sep 2024 07:31:22 +0000 Received: from fout6-smtp.messagingengine.com ([103.168.172.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srY6n-0009B3-V7 for pgsql-hackers@lists.postgresql.org; Fri, 20 Sep 2024 07:31:21 +0000 Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id A03E2138033D; Fri, 20 Sep 2024 03:31:16 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Fri, 20 Sep 2024 03:31: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=1726817476; x= 1726903876; bh=pDuwBDqMA1zvw+ASP7CtvVbtXAdUI72A4vvcLqzByN0=; b=C 9aOe6gX8XmxI/FGQ4yWxuPX+oexANVn1u+ThwaLUHhBZI4asmit/JmpWc3g6XWxH BDH9Z4+t+LvaCz2WMjY0B5dqJy2u2nQjkgK08qr7KagXdXIE2se3awgFVRh2Zxya dUQVMM1i6Sj3c3Cap6PLMczGTTjk8rDpufmrspRNG6W2A3dkgna4HqT2nt9I4ZKt Nmc4PdcKrGMjkFXR/cX9h5dkazLf/TCPVTg1QRrAPP+3UrRO7C0+im9eYfUH2QVY Y/JLnAU1Vnka9/Wp5fboYf+FQF4zX4AKCta/VnRLcSiGWPLL7uOxAg2CiVKerKlW LMfnJk6JxgczFzgCF9DNg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudelvddguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdej necuhfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvh hhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpefgtdegleeggffftdeiuddu fffhveekgfdufeethefgtefhkedvgeejlefhteehvdenucffohhmrghinhepvghnthgvrh hprhhishgvuggsrdgtohhmpdhpohhsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvh hhrdhnohdqihhprdhorhhgpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehjihgrnhdruhhnihhvvghrshgrlhhithihsehgmhgrihhlrdgtoh hmpdhrtghpthhtohepthhnughrfigrnhhgsehgmhgrihhlrdgtohhmpdhrtghpthhtohep phhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 20 Sep 2024 03:31:15 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1726817473; bh=AyaWzDWyOg7rmbZ0mMm8Z3jK9N/3R0WvCRXLdj0QBKM=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=qLVcN/o0PxBWoW8MMfdEXDmDW9BRz1Q5WZgiukTtRfjFK8ojZCC02eGwoc9q2FXyk TYbh3b/dCYxAIb20zG79syz7fKghDnkKoHNTYt8jmhv/b0TXLrLddELFkfMAxvZSOr +D/BtTBxGq/UUXes9PsfSuvsGeTThUqdnmZ2GP5c7Ef/FlabGv1yebVhwWQQmgT5kO pZDpT+pdMfBFn26eyaLa0GIwey0e6WIWipKQbfbRNl/uXHSbRvieaL3AC5qmn1xvhR DxvpeGTsURAQIu7Jc30XYnzfyJl7Jg7xEkGk5HD1MBheEjChPoRjUhah5VrA7bRjbD pse60lfNblpTw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 60B4CB9; Fri, 20 Sep 2024 09:31:13 +0200 (CEST) Date: Fri, 20 Sep 2024 09:31:13 +0200 From: Alvaro Herrera To: Tender Wang Cc: jian he , Pg Hackers Subject: Re: not null constraints, again Message-ID: <202409200731.rxqstsmup5nl@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-Sep-20, Tender Wang wrote: > jian he 于2024年9月20日周五 11:34写道: > > > another bug. > > I will dig later, just want to share it first. > > > > minimum producer: > > drop table if exists pp1,cc1, cc2,cc3; > > create table pp1 (f1 int ); > > create table cc1 () inherits (pp1); > > create table cc2() inherits(pp1,cc1); > > create table cc3() inherits(pp1,cc1,cc2); > > > > alter table pp1 alter f1 set not null; > > ERROR: tuple already updated by self > > I guess some place needs call CommandCounterIncrement(). Yeah ... this fixes it: diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 579b8075b5..3f66e43b9a 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7877,12 +7877,6 @@ ATExecSetNotNull(List **wqueue, Relation rel, char *conName, char *colName, { List *children; - /* - * Make previous addition visible, in case we process the same - * relation again while chasing down multiple inheritance trees. - */ - CommandCounterIncrement(); - children = find_inheritance_children(RelationGetRelid(rel), lockmode); @@ -7890,6 +7884,8 @@ ATExecSetNotNull(List **wqueue, Relation rel, char *conName, char *colName, { Relation childrel = table_open(childoid, NoLock); + CommandCounterIncrement(); + ATExecSetNotNull(wqueue, childrel, conName, colName, recurse, true, lockmode); table_close(childrel, NoLock); I was trying to save on the number of CCIs that we perform, but it's likely not a wise expenditure of time given that this isn't a very common scenario anyway. (Nobody with thousands of millions of children tables will try to run thousands of commands in a single transaction anyway ... so saving a few increments doesn't make any actual difference. If such people exist, they can show us their use case and we can investigate and fix it then.) -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "This is what I like so much about PostgreSQL. Most of the surprises are of the "oh wow! That's cool" Not the "oh shit!" kind. :)" Scott Marlowe, http://archives.postgresql.org/pgsql-admin/2008-10/msg00152.php