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 1tGIBE-0023Ck-Br for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Nov 2024 13:34:08 +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 1tGIBD-00EooP-2b for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Nov 2024 13:34:07 +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 1tGIBC-00EooF-31 for pgsql-hackers@lists.postgresql.org; Wed, 27 Nov 2024 13:34:06 +0000 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tGIB9-004KZu-1B for pgsql-hackers@postgresql.org; Wed, 27 Nov 2024 13:34:05 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id C310A13806C0; Wed, 27 Nov 2024 08:34:00 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Wed, 27 Nov 2024 08:34:00 -0500 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-sender :x-me-sender:x-sasl-enc; s=fm1; t=1732714440; x=1732800840; bh=7 OJX8IUQ0hUs1Fo6g9Nr62LM2bsIgZrRirtskYTd0P4=; b=mZymBeUzyKVoJhx+Q /NcKZH8YoVrA3UPZHl98dXd05K0wBpMDaO2hVgbuJefZlJmE9/3XcUw/gcM/fBHz IEZ+Pv2Sn9JGvEzToQUDNHKm149ZhQVClxVcmNaY1YzE1aCuLdtsKvtiTuLWNGr6 Cu+QMhYsfB+LmRI5bUhwOB7UHS1foqaONlTuM/qLJtIUHbcGlD2LHLW64pX30pyJ xFfgXjpuLEgILpqOTteuE1oN98zSQup0ocs2tJe3I7Yp2aKrwAX4ZMEOKW5yhMxZ KWvsaB+IkAMutHSWjyar76PIB2oO/8Eh+E3qgvfpcIDWHwihpXsLCJnVdy9DG5wI VSs2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrgeelgdehtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuf fkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgr uceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvg hrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeekfffgudffhfduffffueev necuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhh rdhnohdqihhprdhorhhgpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuth dprhgtphhtthhopegrshhhuhhtohhshhdrsggrphgrthdrohhsshesghhmrghilhdrtgho mhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdroh hrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Nov 2024 08:34:00 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1732714438; bh=SUY5tjom0Bs0M2oOnIzFvTEHK5TH3r/rHGlBp7wRwfI=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=YKh5dA0oF+W9j37oJOXGTOi7ru23Vb4R8QATsMOBp8OiD2OETOY1Fr530ZpJqpeq8 +L4TMVHWSQk1Tx65hLEzO2aUxawhZWmvRaX70MF/f6bEgbUxy56+awX8mlADalrQs4 ARde1q0APyRnT2HqAliUrvFpnl8Tq+f5lpElvcY4Rp6rvzam66DwvQVQSNn96eYF0+ CTNJv1Xg7YKv/8l8m5JjdjbK3swEiiZmpOVlOc7Xhi865HZC1YhSNlkFU4u/DbPSiw K0RLBg7TtNHqpg2/BNsASayqTtNLcTwC2YqUzsBUHs3/12MS0hyKjNl+u8r6iclLpU qvtfIy3oyL2+w== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 2D18A95; Wed, 27 Nov 2024 14:33:58 +0100 (CET) Date: Wed, 27 Nov 2024 14:33:58 +0100 From: Alvaro Herrera To: Ashutosh Bapat Cc: pgsql-hackers Subject: Re: Difference in dump from original and restored database due to NOT NULL constraints on children Message-ID: <202411271333.iwaete4g4ltv@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-Nov-27, Ashutosh Bapat wrote: > I noticed that. But two reasons why I chose the backend changes > 1. The comment where we add explicit ADD CONSTRAINT is > /* > * Dump additional per-column properties that we can't handle in the > * main CREATE TABLE command. > */ > ... snip > > /* > * If we didn't dump the column definition explicitly above, and > * it is not-null and did not inherit that property from a parent, > * we have to mark it separately. > */ > if (!shouldPrintColumn(dopt, tbinfo, j) && > tbinfo->notnull_constrs[j] != NULL && > (tbinfo->notnull_islocal[j] && !tbinfo->ispartition && !dopt->binary_upgrade)) > ... snip > > The comment seems to say that we can not handle the NOT NULL > constraint property in the CREATE TABLE command. Don't know why. We > add CHECK constraints separately in CREATE TABLE even if we didn't add > corresponding columns in CREATE TABLE. So there must be a reason not > to dump NOT NULL constraints that way and hence we required separate > code like above. I am afraid going that direction will show us some > other problems. I don't think this is an important restriction. We can change that, as long as all cases work correctly. We previously didn't try to use "CONSTRAINT foobar NOT NULL a" because 1) we didn't support the table-constraint syntax for not-null constraint and 2) not-null constraint didn't support names anyway. We now support that syntax, so we can use it. > 2. Name of the constraint provided by ALTER TABLE ... ADD CONSTRAINT > ... being silently ignored didn't seem right to me. Especially when we > were adjusting the constraint to be local. We could make this throw an error when the names don't match; I don't think that'd affect anything important. I'm not in love with the idea of ADD CONSTRAINT changing the constraint name. Or, to be more precise, I think having ALTER TABLE ADD CONSTRAINT change the name of an existing constraint is a terrible idea. I will forever be shamed publicly if I let that happen, and frankly I don't need any more reasons to be shamed publicly, as I have plenty already. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "Use it up, wear it out, make it do, or do without"