Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1izmx5-0007xx-UX for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Feb 2020 19:36:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1izmx3-000223-Bq for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Feb 2020 19:36:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1izmx2-0001ve-AD for pgsql-hackers@lists.postgresql.org; Thu, 06 Feb 2020 19:36:37 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1izmwu-0005Yd-JD for pgsql-hackers@lists.postgresql.org; Thu, 06 Feb 2020 19:36:34 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id E7F515E0; Thu, 6 Feb 2020 14:36:26 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Thu, 06 Feb 2020 14:36:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=gym68F dVZI6Crgb8SslUOQr4sMLV+cSP4t/MNhWH3hA=; b=F9iyRJWpJ2LexRvQD8pEhQ CIF9ZjJGgQE5cNPqShBUloJaMNXO9FhfX6QR2SIhbUcW1lM+yxv/U7veKcliwcE+ 1CF/kT9PVcrrEDumoOh3TXEDdbfvQeYy5LuLwq/3TS1SW3YHy9G/+8FhTIJMfWBP hxtFShV4i5lUWYHVdlx2g85nSVaG6pC7GYTRJjjX5MFObZwhGPipSj+9OFxS1o7y rtB0PTjJzRS6SxiHlelhbOmP7YkeRGy8u8xHEk0WsyfehtpvF1k86lpEVP8oact/ GaXHY19/VCiMP+O24E5bq+BMct3nrSab7tQBZgPxHshP6AwsvjHvPlxsZC2eol2A == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrheefgdduvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhfhokffffgggjggtsehmtd erredtfeejnecuhfhrohhmpefrvghtvghrucfgihhsvghnthhrrghuthcuoehpvghtvghr rdgvihhsvghnthhrrghuthesvdhnughquhgrughrrghnthdrtghomheqnecuffhomhgrih hnpedvnhguqhhurggurhgrnhhtrdgtohhmnecukfhppeelfedrvdegvddrvdehhedruddu vdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpvg htvghrrdgvihhsvghnthhrrghuthesvdhnughquhgrughrrghnthdrtghomh X-ME-Proxy: Received: from april.pezone.net (p5df2ff70.dip0.t-ipconnect.de [93.242.255.112]) by mail.messagingengine.com (Postfix) with ESMTPA id 961CF30606FB; Thu, 6 Feb 2020 14:36:25 -0500 (EST) Subject: Re: Dumping/restoring fails on inherited generated column To: Tom Lane References: <15830.1575468847@sss.pgh.pa.us> <31905.1575491779@sss.pgh.pa.us> <24369.1580758361@sss.pgh.pa.us> Cc: pgsql-hackers@lists.postgresql.org From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: Date: Thu, 6 Feb 2020 20:36:24 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <24369.1580758361@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="------------60DC5BDB2AD2E5C5FAC039C9" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------60DC5BDB2AD2E5C5FAC039C9 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 2020-02-03 20:32, Tom Lane wrote: > Things are evidently also going wrong for "gtest1_1". In that case > the generated property is inherited from the parent gtest1, so we > shouldn't be emitting anything ... how come the patch fails to > make it do that? This is fixed by the attached new patch. It needed an additional check in flagInhAttrs(). > This is showing us at least two distinct problems. Now as for > "gtest30_1", what we have is that in the parent table "gtest30", column b > exists but it has no default; the generated property is only added > at the child table gtest30_1. So we need to emit ALTER COLUMN SET > GENERATED ALWAYS for gtest30_1.b. HEAD is already doing the wrong > thing there (it's emitting the expression, but as a plain default > not GENERATED). And this patch makes it emit nothing, even worse. > I think the key point here is that "attislocal" refers to whether the > column itself is locally defined, not to whether its default is. This is a bit of a mess. Let me explain my thinking on generated columns versus inheritance. If a parent table has a generated column, then any inherited column must also be generated and use the same expression. (Otherwise querying the parent table would produce results that are inconsistent with the generation expression if the rows come from the child table.) If a parent table has a column that is not generated, then I think it would be semantically sound if a child table had that same column but generated. However, I think it would be very tricky to support this correctly, and it doesn't seem useful enough, so I'd rather not do it. That's what the gtest30_1 case above shows. It's not even clear whether it's possible to dump this correctly in all cases because the syntax that you allude to "turn this existing column into a generated column" does not exist. Note that the gtest30 test case is new in master. I'm a bit confused why things were done that way, and I'll need to revisit this. I've also found a few more issues with how certain combinations of DDL can create similar situations that arguably don't make sense, and I'll continue to look into those. Basically, my contention is that gtest30_1 should not be allowed to exist like that. However, the pg_dump issue is separate from those because it affects a case that is clearly legitimate. So assuming that we end up agreeing on a version of the attached pg_dump patch, I would like to get that into the next minor releases and then investigate the other issues separately. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------60DC5BDB2AD2E5C5FAC039C9 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="v3-0001-pg_dump-Fix-dumping-of-inherited-generated-column.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename*0="v3-0001-pg_dump-Fix-dumping-of-inherited-generated-column.pa"; filename*1="tch" RnJvbSA3NjI0OWM5YTY0Y2FhYWY0YzMyMDZkNWNhNGZmNzJjYzE4NmRjNDE2IE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBQZXRlciBFaXNlbnRyYXV0IDxwZXRlckBlaXNlbnRy YXV0Lm9yZz4KRGF0ZTogVGh1LCA2IEZlYiAyMDIwIDE0OjUwOjAxICswMTAwClN1YmplY3Q6 IFtQQVRDSCB2M10gcGdfZHVtcDogRml4IGR1bXBpbmcgb2YgaW5oZXJpdGVkIGdlbmVyYXRl ZCBjb2x1bW5zCgpHZW5lcmF0aW9uIGV4cHJlc3Npb25zIG9mIGdlbmVyYXRlZCBjb2x1bW5z IGFyZSBhbHdheXMgaW5oZXJpdGVkLCBzbwp0aGVyZSBpcyBubyBuZWVkIHRvIHNldCB0aGVt IHNlcGFyYXRlbHkgaW4gY2hpbGQgdGFibGVzLCBhbmQgdGhlcmUgaXMKbm8gc3ludGF4IHRv IGRvIHNvIGVpdGhlci4gIFRoZSBjb2RlIHByZXZpb3VzbHkgdXNlZCB0aGUgY29kZSBwYXRo cwpmb3IgdGhlIGhhbmRsaW5nIG9mIGRlZmF1bHQgdmFsdWVzLCBmb3Igd2hpY2ggZGlmZmVy ZW50IHJ1bGVzIGFwcGx5OwppbiBwYXJ0aWN1bGFyIGl0IG1pZ2h0IHdhbnQgdG8gc2V0IGEg ZGVmYXVsdCB2YWx1ZSBleHBsaWNpdGx5IGZvciBhbgppbmhlcml0ZWQgY29sdW1uLiAgRm9y IGdlbmVyYXRlZCBjb2x1bW5zLCBqdXN0IHNraXAgYWxsIHRoYXQuCgpEaXNjdXNza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