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 1wa5k2-001WYq-1M for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2026 05:56:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wa5k1-009nST-0O for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2026 05:56:41 +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 1wa5k0-009nSL-2e for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2026 05:56:40 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wa5jy-000000012hO-2Kxb for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2026 05:56:40 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-c89ab9a9f6cso96260a12.2 for ; Wed, 17 Jun 2026 22:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781762196; x=1782366996; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZOcAiWG9IvlsizO3hyXkAnyZVg01evnlvb1bqu3f/L8=; b=pACEOe6UjxbTY7MsInOtMer9EfSlBlFJyuh9rNP5sXJcHlHM8vZgf9e57zmrGYUXNn 6kNl0nPKrE9qfRgJ7hvSU31bIkji1E5ncFNgYW/aA3UXvWySpQG2AWRJBg2XBJxRIqjM 63otue6KjCRsVORtLAytQF3e0ALPLN18MtUU2PYOehwF4vKgJP0aMyLHtId73/soAjbU Fu9lkTvkM15bFvfOnDmGIXlK6SBBwYjj1D3zQcbgIMbIwROepy8Jnj4ycY6bGJEzp1Ev izX8SyoKyc2Qr9xuiDXIx6PGnZU1NrLvMbCFeKhawETVVIKYeBHGLxvQRi9ZbYJ5Ieaw nSEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781762196; x=1782366996; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZOcAiWG9IvlsizO3hyXkAnyZVg01evnlvb1bqu3f/L8=; b=XEIelrV7Nwiyuc++JpD6IiwYV50eJNFqP3il/GT7U4YVArI0Yo/PXqV2Tf+GK0QKSW c1Chhc4pVbuc92iYOl91v8RPrSNpHx/C/g97mL0KFzRE0mveG2f61PUbNsEYzzxhtuOu it+VnZAIXYKnFPOGjCt3Zn1xfZpsmRWaPyNn5wGiOh7vZmjhaW6Kmrf9VaO/lQEyf7tq NsanpIurccegqvr1pLE+79LYV3pfU5SoksSaxdHxAM/V3Q1jKPxfTZhf8KpSMQsjWQJx 8PvP1l4+/RDsues2gimikHAmqZLOHqT2CsUADgLg5edv4+SHuvDm+wvjk6BsQgLWjRfz obKQ== X-Forwarded-Encrypted: i=1; AFNElJ9iblO1vQqBRH7wok9P0Rd8eXIxgyWp7kDNBYjy62XwOqnsTi6lNwITL+wAGTrVABqbbhGy+AzCOOYuioBJ@lists.postgresql.org X-Gm-Message-State: AOJu0Yx4KPn9YzNMEE1PIJzw0/dX1Mbyc2NLXnlgOr7VEUw71qUtXAdd /8dgG7qf54Gz+UDkHvPHHaAUc5WFbrV/UetPPzSPldHOYYd/ywEU9Y+n X-Gm-Gg: Acq92OFax0+xbCqhK3PsmZkmVGYGuO9rh4fLnBjDIMoJashqskViw1+GB5BrVPtTE6k MmF3g7duas3uky4Aw4AdG5zzQ7H24jgCpZWCBr21bs6E6cwR0kKkdkb+V0HvftnIAo/R7EX8S1E zGPmzB9ai8UcWasM57iWj9D4UPBA24SFMClNN5r9yCVtHM/6Lm1aJpdBA2bO/laKGxUUX51SW4W gqSn+N6qTeBGlLNg0pyKJMpOVLazjtVEPDRzLsKu/pe4uNjsHKK/O1zHOz9hF1D1Phe7PjRIUzt pbYzyNt5bM3tkCqmovo6hDCA2TL+ruy99JFdlPsmpEFjSUnslc8RhuekMzC36iLtR2fH5hyONZK cq1b6nUS0N8iQYKFfExVHBZ4xbxSlFyuQdvmLin6aJAr+fYVAmEZnzrvSNxCuZAVPIlI1tYwrte syUwtSHOeVCibRJy8gEu5D/g== X-Received: by 2002:a05:6a20:244a:b0:3b4:7aae:1ef4 with SMTP id adf61e73a8af0-3b8b5b282d0mr8375969637.9.1781762196006; Wed, 17 Jun 2026 22:56:36 -0700 (PDT) Received: from smtpclient.apple ([185.135.79.161]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c86651adc16sm14868586a12.31.2026.06.17.22.56.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jun 2026 22:56:35 -0700 (PDT) Content-Type: text/plain; charset=utf-8 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 From: Chao Li In-Reply-To: Date: Thu, 18 Jun 2026 13:55:58 +0800 Cc: Tom Lane , Peter Eisentraut , Andres Freund , Postgres hackers Content-Transfer-Encoding: quoted-printable Message-Id: <03C47613-5C89-4E69-BB72-3B2912BDDDA8@gmail.com> References: <1151393.1781734980@sss.pgh.pa.us> <1174236.1781736349@sss.pgh.pa.us> <2A622929-A45C-4370-943A-BC76FF4CC433@gmail.com> To: David Rowley 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 > On Jun 18, 2026, at 13:18, David Rowley wrote: >=20 > On Thu, 18 Jun 2026 at 14:36, Chao Li wrote: >> I tested the fix, and it seems to work. While tracing the code, I = wondered about this part: >> ``` >> - if (att->attnullability =3D=3D ATTNULLABLE_VALID && >> - !att->atthasmissing && >> - !att->attisdropped) >> + if (attr->attgenerated =3D=3D = ATTRIBUTE_GENERATED_VIRTUAL) >> + break; >> + >> + if (catt->attnullability =3D=3D ATTNULLABLE_VALID && >> + !catt->atthasmissing && >> + !catt->attisdropped) >> guaranteed_column_number =3D attnum; >> ``` >>=20 >> When computing guaranteed_column_number, I think we can just skip the = virtual generated column rather than break. Using the test from Tom=E2=80=99= s email: >=20 > Yeah, I was confused at first as I'd done a similar optimisation in > the non-JIT deform code, but there "guaranteed" means guaranteed to be > present in the tuple data, whereas with the JIT code it means > guaranteed in the tuple data or its NULL bitmap. >=20 > I've attached v2 which includes a test that exercises deforming with > tuples which have various natts counts. I propose to backpatch > 1f7dfe8c8 to v18 before applying the attached to master and v18. >=20 > David > This version looks good to me. Only a small comment: ``` +-- try adding a virtual generated column to an existing table with = tuples, +-- then try adding an atthasmissing column before adding a normal = nullable +-- column. +--CREATE TABLE gtest21d (a int NOT NULL); +--INSERT INTO gtest21d (a) VALUES(10); +--ALTER TABLE gtest21d ADD COLUMN b INT GENERATED ALWAYS AS (a * 10) = VIRTUAL NOT NULL; +--SELECT * FROM gtest21c ORDER BY a; +--INSERT INTO gtest21d (a) VALUES(20); +--ALTER TABLE gtest21d ADD COLUMN c INT NOT NULL DEFAULT 1234; +--SELECT * FROM gtest21c ORDER BY a; +--ALTER TABLE gtest21d ADD COLUMN d INT; +--INSERT INTO gtest21d (a, c, d) VALUES(30, 12345, 100); +--SELECT * FROM gtest21c ORDER BY a; +--DROP TABLE gtest21d; ``` I don=E2=80=99t know why you added these commented SQL statements, I = guess you have your reason. The problem is, in the 3 SELECTs, gtest21c = should probably be gtest21d. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/