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 1u4mJV-007Bzv-FJ for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Apr 2025 19:51:21 +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 1u4mJT-00G7ul-G9 for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Apr 2025 19:51:20 +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 1u4mJT-00G7tr-64 for pgsql-hackers@lists.postgresql.org; Tue, 15 Apr 2025 19:51:20 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u4mJQ-000FJA-2c for pgsql-hackers@lists.postgresql.org; Tue, 15 Apr 2025 19:51:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 53FJpEgL1719551; Tue, 15 Apr 2025 15:51:14 -0400 From: Tom Lane To: Alvaro Herrera cc: Tender Wang , jian he , Pg Hackers Subject: Re: not null constraints, again In-reply-to: <202504151911.mezh7j3bizh5@alvherre.pgsql> References: <202504151911.mezh7j3bizh5@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Tue, 15 Apr 2025 21:11:49 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1719549.1744746674.1@sss.pgh.pa.us> Date: Tue, 15 Apr 2025 15:51:14 -0400 Message-ID: <1719550.1744746674@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera writes: > However, I've also been looking at this and realized that this code can > have different structure which may allows us to skip the > find_inheritance_children() altogether. The reason is that we already > scan the parent's list of columns searching for not-null constraints on > each of them; we only need to run this verification on children for > columns where there is none in the parent, and then only in the case > where recursion is turned off. +1. Fundamentally the problem here is that pg_restore needs ALTER TABLE ONLY foo ADD PRIMARY KEY to not recurse to child tables at all. It is expecting this command to acquire a lock on foo and nothing else; and it has already taken care of making foo's PK column(s) NOT NULL, so there is no reason we should have to examine the children. Looking at the patch itself, it doesn't seem like the got_children flag is accomplishing anything; I guess that was leftover from an earlier version? You could declare "List *children" inside the block where it's used, too. Basically, this patch is just moving the check-the-children logic from one place to another. Also I find the comments still a bit confusing, but maybe that's on me. regards, tom lane