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.96) (envelope-from ) id 1wWm4U-002qfV-1d for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jun 2026 02:20:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wWm4T-004Yeg-1O for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jun 2026 02:20:05 +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.96) (envelope-from ) id 1wWm4T-004YeY-03 for pgsql-hackers@lists.postgresql.org; Tue, 09 Jun 2026 02:20:05 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wWm4Q-000000024fx-34i1 for pgsql-hackers@lists.postgresql.org; Tue, 09 Jun 2026 02:20:04 +0000 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-36baec934b6so3325463a91.0 for ; Mon, 08 Jun 2026 19:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780971600; x=1781576400; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=fep6KEQ1q3o5DsQzPws1X2n97cH2d8YGrL5EH9/jGNk=; b=ZqqjkPoWarWCvNYZkT+AT+TfEdoGzpdlGQ0rfLhMC0PrT1j9sKjD69Vgjttrf/2zs9 3b6PvE2+rbKgb3pBbrr47J9kZ9rrqdkmT8pnNXSh2F3mlTOD+fodYMAuuusa+hJEAQDI S9hTuIAwYRC+Q/E5qz5Ju2yqDp2Fwcm3DpJCLp4eGGEyFbYsC7EviMc2FOdF5lWbB8Lm qB9kXRrPL4LopCZ7jb1iKUl9kr/iXYZJuFk6tJuWuDCgaIJ3kSPIcOZERTccQTsBcfac BxpyB9sRBlP3YCE/KLAhrGYZa2EMnzyyUH2j85Q0xQHA3XDmcocm09L8y7yX//EMSt84 MxtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780971600; x=1781576400; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fep6KEQ1q3o5DsQzPws1X2n97cH2d8YGrL5EH9/jGNk=; b=rLmNAZ9R0GGG3J2tHnqfxjfJZRTYXSSWJf9ki8fGM5WqYrxmKay7v7kl7bj3Da7pZJ 7gGSWwuot2lZu9hd6R+FEV/im+GCnF8CcwU6S++UvzFwxLSlqagS8Tr1G3xSGQOw1n9V S9aebmpHZAKNLbS0Or7gZ3rHJWFzRuFlaaKPCwpsxkEgeNdf6pU/+tKB2NvJEKJfYu1j usNgh8I3GH+/UFQ2DNe52ifW8L8Xas4o1gfxTRCyx/aDxMFuMbPaY8rxDn/mShbeqqm1 Fv3KtYiCAFlP1WAM4IUDgu38gN+gg7xnV03O6k/R7S/wD+xWgQlHBuzRuqUxX3F5rJCU kvxQ== X-Forwarded-Encrypted: i=1; AFNElJ+4SSaV7TxO7QX9qrUIPCENSw2n4DuuDMqbuS1WvxZz0YhNUkFuNgfUNCm52selj7s0ANL7iUs2iTB/bqDV@lists.postgresql.org X-Gm-Message-State: AOJu0Yy520KKpgXV9YImfD+0nMgXbfNy0a390HTjERU9UKdZQDDO/V/s ToG5I3JQ3fcEFh3qc8ymf9udbw9rQBftlkcEkHHXjnsj2li1PeOVLnbU X-Gm-Gg: Acq92OEODAnxcvBEbhqXLxnbs6hokeHVB3QLKOJjZ6rt7TretCxkwFd8uuTvQVoDFla LTt2oixQBSeoDLd+2Ezo1sOPE9ju3dJ4G4yQIgOzzyoXvDAQaqRha83OAJf8A5vOWVe9ThT9q/O eXa/r0/fhAkbJXy6KYxzcf31ZKDW40BQJ216IpyM1gIU6j5XQeV4XcGK5SPwGCGKaWy6xSfJWvI f3/UWPbpQsJMwdByxeemjWo6Egk72X5Ofy7Pxs9e0IZFD3DBcc/gf6t29KaP0bH18QC5vFhcsrq fhiSiQ6NGXoI+Tt/jyMR8JFYdbOiVxhCH4+6xo+kY9rV656Yhbx14Vt4Ylq956xc0ZdWIPoS/W8 H3I69GBoDF9AgDr5sT4QxKGWnckHnxf/d5AqQ6C4/m04Rh4RTpy9NpxP9JCILXxu1bn0QNOqq3H u/gZtnihUMOS+QgbsrArsei/ndrccIWNZ3iJg5NpUN6A== X-Received: by 2002:a17:90b:3b90:b0:369:742a:4259 with SMTP id 98e67ed59e1d1-3712cd07461mr14210880a91.0.1780971600292; Mon, 08 Jun 2026 19:20:00 -0700 (PDT) Received: from smtpclient.apple ([203.76.245.26]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36f6bf82841sm20786485a91.2.2026.06.08.19.19.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jun 2026 19:19:59 -0700 (PDT) From: Chao Li Message-Id: Content-Type: multipart/mixed; boundary="Apple-Mail=_4BC10C56-98F9-470C-861E-830388C69665" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: Fix tuple deformation with virtual generated NOT NULL columns Date: Tue, 9 Jun 2026 10:19:25 +0800 In-Reply-To: Cc: David Rowley , Postgres hackers To: Andres Freund References: X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_4BC10C56-98F9-470C-861E-830388C69665 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jun 8, 2026, at 21:01, Andres Freund wrote: >=20 > Hi, >=20 > On 2026-06-06 16:50:29 +1200, David Rowley wrote: >> On Thu, 4 Jun 2026 at 17:57, Chao Li wrote: >>> While testing "Optimize tuple deformation=E2=80=9D, I found a bug: >>=20 >>> I think the problem is in finding the first non-guaranteed attribute = where virtual generated attributes are not considered: >>=20 >> Thanks for the report and fix. I pushed a slightly adjusted version. >> Form_pg_attribute.attgenerated is '\0' for non-generated columns, so >> there's no point in checking cattr->attgenerated as well as that. >>=20 >> I also added an Assert() to help catch any other reason that the >> guaranteed column gets set incorrectly again in TupleDescFinalize(). >=20 > Seems like a test for some of this would be good too? >=20 > Greetings, >=20 > Andres Freund Okay, I tried to add a test matching my repro. With this test in place, = I reverted the fix and ran make check; it failed by hitting the Assert = David added: ``` TRAP: failed Assert("first_null_attr(tup->t_bits, natts) >=3D = firstNullAttr"), File: "execTuples.c", Line: 1083, PID: 65804 0 postgres 0x0000000104e883b8 = ExceptionalCondition + 216 1 postgres 0x00000001048e5ebc = slot_deform_heap_tuple + 456 2 postgres 0x00000001048e2a18 = tts_buffer_heap_getsomeattrs + 112 3 postgres 0x00000001048c5044 = slot_getsomeattrs + 68 4 postgres 0x00000001048b97a4 = ExecInterpExpr + 416 5 postgres 0x00000001048b8ea0 = ExecInterpExprStillValid + 76 6 postgres 0x000000010492ec68 = ExecEvalExprNoReturn + 44 7 postgres 0x000000010492ec28 = ExecEvalExprNoReturnSwitchContext + 48 8 postgres 0x000000010492eb20 ExecProject + = 72 9 postgres 0x000000010492e680 = ExecScanExtended + 288 10 postgres 0x000000010492d7cc = ExecSeqScanWithProject + 220 11 postgres 0x00000001048db508 = ExecProcNodeFirst + 92 12 postgres 0x00000001048d1eb8 ExecProcNode = + 60 ``` See the attached patch for details. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_4BC10C56-98F9-470C-861E-830388C69665 Content-Disposition: attachment; filename=v1-0001-Add-regression-test-for-virtual-generated-column-.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-Add-regression-test-for-virtual-generated-column-.patch" Content-Transfer-Encoding: quoted-printable =46rom=20944e72ad211a9ac694e7fdeb9361f9fe3e2a01d4=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Tue,=209=20Jun=202026=2009:58:44=20+0800=0ASubject:=20[PATCH=20= v1]=20Add=20regression=20test=20for=20virtual=20generated=20column=0A=20= deformation=0A=0AAdd=20coverage=20for=20a=20virtual=20generated=20NOT=20= NULL=20column=20followed=20by=20a=0Aphysically=20stored=20NOT=20NULL=20= column.=20This=20exercises=20the=20tuple=20deformation=0Acase=20fixed=20= by=2089eafad297a,=20where=20TupleDescFinalize()=20could=20incorrectly=0A= treat=20a=20virtual=20generated=20column=20as=20part=20of=20the=20= guaranteed=20physical=20column=0Aprefix=20and=20compute=20cached=20= offsets=20past=20it.=0A=0AWithout=20that=20fix,=20deforming=20the=20= following=20column=20could=20read=20from=20the=20wrong=0Atuple=20offset.=0A= =0ASuggested-by:=20Andres=20Freund=20=0AAuthor:=20= Chao=20Li=20=0ADiscussion:=20= https://postgr.es/m/A4BC563C-0CA3-4EF3-952A-EA41F9E5BF1E%40gmail.com=0A= ---=0A=20src/test/regress/expected/generated_virtual.out=20|=209=20= +++++++++=0A=20src/test/regress/sql/generated_virtual.sql=20=20=20=20=20=20= |=205=20+++++=0A=202=20files=20changed,=2014=20insertions(+)=0A=0Adiff=20= --git=20a/src/test/regress/expected/generated_virtual.out=20= b/src/test/regress/expected/generated_virtual.out=0Aindex=20= 24d5dbf46ca..7a5788146f5=20100644=0A---=20= a/src/test/regress/expected/generated_virtual.out=0A+++=20= b/src/test/regress/expected/generated_virtual.out=0A@@=20-727,6=20= +727,15=20@@=20ERROR:=20=20null=20value=20in=20column=20"b"=20of=20= relation=20"gtest21b"=20violates=20not-null=20constr=0A=20DETAIL:=20=20= Failing=20row=20contains=20(null,=20virtual).=0A=20ALTER=20TABLE=20= gtest21b=20ALTER=20COLUMN=20b=20DROP=20NOT=20NULL;=0A=20INSERT=20INTO=20= gtest21b=20(a)=20VALUES=20(0);=20=20--=20ok=20now=0A+--=20virtual=20= generated=20columns=20are=20not=20physically=20stored,=20even=20when=20= not=20null=0A+CREATE=20TABLE=20gtest21c=20(a=20int=20NOT=20NULL,=20b=20= int=20GENERATED=20ALWAYS=20AS=20(a=20*=202)=20VIRTUAL=20NOT=20NULL,=20c=20= int=20NOT=20NULL);=0A+INSERT=20INTO=20gtest21c=20(a,=20c)=20VALUES=20= (10,=2042);=0A+SELECT=20a,=20b,=20c=20FROM=20gtest21c;=0A+=20a=20=20|=20= b=20=20|=20c=20=20=0A+----+----+----=0A+=2010=20|=2020=20|=2042=0A+(1=20= row)=0A+=0A=20--=20not-null=20constraint=20with=20partitioned=20table=0A=20= CREATE=20TABLE=20gtestnn_parent=20(=0A=20=20=20=20=20f1=20int,=0Adiff=20= --git=20a/src/test/regress/sql/generated_virtual.sql=20= b/src/test/regress/sql/generated_virtual.sql=0Aindex=20= 9c2bb6590b3..126ae3ecda9=20100644=0A---=20= a/src/test/regress/sql/generated_virtual.sql=0A+++=20= b/src/test/regress/sql/generated_virtual.sql=0A@@=20-374,6=20+374,11=20= @@=20INSERT=20INTO=20gtest21b=20(a)=20VALUES=20(NULL);=20=20--=20error=0A= =20ALTER=20TABLE=20gtest21b=20ALTER=20COLUMN=20b=20DROP=20NOT=20NULL;=0A=20= INSERT=20INTO=20gtest21b=20(a)=20VALUES=20(0);=20=20--=20ok=20now=0A=20=0A= +--=20virtual=20generated=20columns=20are=20not=20physically=20stored,=20= even=20when=20not=20null=0A+CREATE=20TABLE=20gtest21c=20(a=20int=20NOT=20= NULL,=20b=20int=20GENERATED=20ALWAYS=20AS=20(a=20*=202)=20VIRTUAL=20NOT=20= NULL,=20c=20int=20NOT=20NULL);=0A+INSERT=20INTO=20gtest21c=20(a,=20c)=20= VALUES=20(10,=2042);=0A+SELECT=20a,=20b,=20c=20FROM=20gtest21c;=0A+=0A=20= --=20not-null=20constraint=20with=20partitioned=20table=0A=20CREATE=20= TABLE=20gtestnn_parent=20(=0A=20=20=20=20=20f1=20int,=0A--=20=0A2.50.1=20= (Apple=20Git-155)=0A=0A= --Apple-Mail=_4BC10C56-98F9-470C-861E-830388C69665--