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.98.2) (envelope-from ) id 1xSG1p-00000001iaF-3Y5L for pgsql-hackers@arkaria.postgresql.org; Sat, 14 Nov 2026 15:50:58 +0000 Received: from localhost ([127.0.0.1]:54310 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xSG1n-0000000Dgbm-3Y0n for pgsql-hackers@arkaria.postgresql.org; Sat, 14 Nov 2026 15:50:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:48938) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xSG1n-0000000Dgbc-1ndJ for pgsql-hackers@lists.postgresql.org; Sat, 14 Nov 2026 15:50:55 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xSG1l-00000000vkq-3trj for pgsql-hackers@postgresql.org; Sat, 14 Nov 2026 15:50:54 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4a2d6d01ecbso14779345e9.0 for ; Sat, 14 Nov 2026 07:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794671452; x=1795276252; darn=postgresql.org; h=in-reply-to:references:to:from:cc:subject:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=NnLhzt1E3/1jph5BFTjtUwKtkh0PfOmm61e8RD+umFA=; b=OPI3Bo0+VPq0OhF6OxNjHgDoKW5nTOqHGhDuwavWGdUbaN9EEaYRyewfJvarhsV6BQ tQjpTUyYkMFbFWP33NpaKg4YJ45tESC4642Yswmkr/a/lz7Lm3MiC6Jt0V0PR/2h7pro AzCQ7iGTRfTSrkkEfmdMCf5Me5bC68rXsVh1AV+tP1b70gw3x8KvqVwLsMWeW3SE3xmu /usnfphEAzAS3mBWg/FPLjJFZPz57tob3bTY7e7XT9ThG2paC7RtApYyGovlmedFnOyx ehyw6LUUrlDADKS5Lb2p1EPq4K4tH444FIX/o3VRh3kOXAXj4jw1v27lXB+FKt6G/5VS J6nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794671452; x=1795276252; h=in-reply-to:references:to:from:cc:subject:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=NnLhzt1E3/1jph5BFTjtUwKtkh0PfOmm61e8RD+umFA=; b=mIEyJmPwuTbX4C55ktasiMPfYdqvB2JoaDeWaz+JioHJ75aUTRj0PQ9puWcLTQAErp aveahduZBXKfo523sLOjWPuddw8MocHaVWMh9oQB/8zq9tawly7cyRWmhivBDwjMMW0+ /BbOHI+PAgQP6nJWp0+ta1zCng9eNM/GNlB75YWUv46jXvFGRZpyIagcvf8WgWxW6iju c8oNiyWS3WZqchmMm/+KaIxTbwQH3fmiJoVGDk2j4P5F1HKxPgOQnO0o+B61pEgRFTDn +vhmDPqM9onlgnKoWpi4g8jVl+6SbxEyNHHOoRmg0FEW3bFaKfLRETdTeDgDuT9nfsz9 i7+Q== X-Forwarded-Encrypted: i=1; AL+hErHetqY32KITZHoWNOgpD8CB0hGDN3rgZvX7fkvv4uQmNpOI6LJXUf9YQyI/YfNSc5+TN2vbsCRrt7o/i5nR@postgresql.org X-Gm-Message-State: APuU4Z+EN2DSq8Gn1Xz/dy9Dhlm07j6Lc9is4L4x+dLf5E4i0kugTOEi nihl3QntaufBWqtJ493LqdGGQT9gG2+chP7Eiad63qw9UVcgAYAnHTuC X-Gm-Gg: AYBFou1wokC+Tq4JDO9kdk2oXzQWxOjT9yKdpvqZlVj53KdBYNWZ3HqRSsJ3GXfYsQi GZeUnSES5KlweW/5yLFgzEV6xTydolgomPGi6Lt4X225ObdiuOSA1CPO3U40lZeqNu/fdM2uqo4 BjuUgSVrFFNB4QJcMj16w/UzdXksWec48LUAyePX18R33dY5ec52hRNrl1wIXLrC3mYwu06KbLz 2cutG+yOLu2jEhRYMa+Nz1gp2U6LlqPizBfjbLSDNV3qj4fQ+MtRKuckgZA7e59wlpCHo3IDMDu 6bIyDKrswSzE5dGqdbSJTGUTSFuPiSFECKEn/0MIlV1Vu6XW3Nc5W9waLMOWHEX/wGNsmMRE+4n qenDzUwt7XjbxTFxvkVSGxJGF0XAgPt1VUp/PsFaIOCCLexCJz1N5OH4pFXT2eopMsmlWAlNJeD jsGCbZHvD+zmdgrmPRT9VGX7C59nu+Mb0ACK0eFDeRsi6OWgqeBYuhxvaoRS9TcEQVRXV063xmc wSXU4eZNew9XYswlWO9ypu+8NQQRekYESQsS7ReZZe7qv2FY/+2Dvtow3goq2DtE9N26+hEXiZv bZpAvJ/14gLuYjQqi/NrodKzXv6LTXUZkAKXZSsRvyYsSAyeb0bi1WwB/1Yf94WPqMGVkn8bAyO ThfEaz1nVhe0p6odU2cP+Y08YESvnPA== X-Received: by 2002:a05:600c:83ca:b0:4aa:2339:a375 with SMTP id 5b1f17b1804b1-4bb55a4d9b3mr130094725e9.13.1794671451901; Sat, 14 Nov 2026 07:50:51 -0800 (PST) Received: from localhost ([2a02:169:191:0:c7e:b8:14a6:4e75]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb675200e4sm26950045e9.0.2026.11.14.07.50.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Nov 2026 07:50:51 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 14 Nov 2026 16:50:50 +0100 Message-Id: Subject: Re: Adding a stored generated column without long-lived locks Cc: "Laurenz Albe" , "Matthias van de Meent" , =?utf-8?q?=C3=81lvaro_Herrera?= , From: "Alberto Piai" To: "Xiaoxuan Li" , "Alberto Piai" X-Mailer: aerc 0.21.0 References: In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Xiaoxuan, thank you for having a look at the patch! On Fri Nov 13, 2026 at 9:06 PM CET, Xiaoxuan Li wrote: > Hi Alberto, > > v12 (on e405a46c45b, Linux/aarch64, gcc 11, cassert) builds cleanly > and passes the regression tests, but this new change loses data: > >> - clear atthasmissing and attmissingval for consistency with CREATE >> TABLE: a column that was GENERATED since the beginning can't have >> those set, so let's be consistent. > > A column added with a constant default has no stored value in the rows > that existed before; they read attmissingval. The constraint is > validated against those values, and then the command removes them: Oops, nice catch, and what an embarassing thinko on my side. The property I'd like to establish here is that a stored generated column added with this command should be indistinguishable from one that was defined with CREATE TABLE or ALTER TABLE ... ADD COLUMN. So when I noticed the different atthasmissing/attmissingval, I thought I'd just drop those. Your test case shows an even bigger problem: in the presence of a previous default value, the CHECK constraint is not sufficient to prove that the column was completely backfilled with the correct data. My first thought now would be to have the command bail if the column has atthasmissing/attmissingval, and document that it must be added without a DEFAULT value. The (not so small, but not terrible and maybe unavoidable) downside is that this can't be detected early, so a user who's doing this migration and oversees the note in the docs will only notice at the very end, and will have to start from scratch and do the work of backfilling the data again. Or alternatively, I give up on trying to preserve such a property. A column which was added with a default value and freshly migrated with this command will have atthasmissing/attmissingval. Since the constraint has been validated aginst the missingval, we are sure that if/when the table is eventually rewritten (for example with REPACK), the correct value will be stored (and atthasmissing/attmissingval will be cleared). This might allow saving some work in the backfilling phase if most rows would end up with the default value anyway. WDYT? (I am inclined to go for the latter, but I want to spend some more time thinking about this.) Regards, Alberto --=20 Alberto Piai Sensational AG Z=C3=BCrich, Switzerland