Re: Fix tuple deformation with virtual generated NOT NULL columns

From: cca5507 <cca5507(at)qq(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>
Subject: Re: Fix tuple deformation with virtual generated NOT NULL columns
Date: 2026-06-04 09:32:17
Message-ID: tencent_A50A880C0C5ED0818A9D66E84DA15F6D6106@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> While testing "Optimize tuple deformation”, I found a bug:
> ```
> evantest=# create table t (a int not null,
> evantest(# g int generated always as (a+1) virtual not null,
> evantest(# b int not null);
> CREATE TABLE
> evantest=# insert into t (a, b) values (10, 20);
> INSERT 0 1
> evantest=# select a, g, b from t;
>  a  | g  | b
> ----+----+---
>  10 | 11 | 0
> (1 row)
> ```

Nice catch! I can reproduce this bug on master. Some comments about the fix:

I find that a virtual generated column is stored as a null in heap tuple, so I think
we should stop setting 'attcacheoff' when we see a virtual generated column in
TupleDescFinalize(), or we will set wrong 'attcacheoff' value. But it seems that
we don't use these wrong value because we can only use 'attcacheoff' up until
the first NULL.

--
Regards,
ChangAo Chen

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2026-06-04 09:55:05 Re: GRAPH_TABLE: lateral reference with label disjunction fails with "plan should not reference subplan's variable"
Previous Message Ashutosh Sharma 2026-06-04 09:26:59 Re: synchronized_standby_slots behavior inconsistent with quorum-based synchronous replication