Re: Virtual generated columns

From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>, jian he <jian(dot)universality(at)gmail(dot)com>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Virtual generated columns
Date: 2025-02-10 05:15:58
Message-ID: 12d5cce9-917f-4a99-86d3-715bb3b363bb@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Feb 10, 2025 at 12:53 +0800, jian he <jian(dot)universality(at)gmail(dot)com>, wrote:
>
> please check attached.
>
> > BTW, I was curious about what happens if the replacement expression is
> > constant, so I tried running the query below.
> >
> > CREATE TABLE t (a int, b int GENERATED ALWAYS AS (1 + 1));
> > INSERT INTO t VALUES (1);
> > INSERT INTO t VALUES (2);
> >
> > # SELECT t2.a, t2.b FROM t t1 LEFT JOIN t t2 ON FALSE;
> > a | b
> > ---+---
> > | 2
> > | 2
> > (2 rows)
> >
> > Is this the expected behavior? I was expecting that t2.b should be
> > all NULLs.
> >
> SELECT t2.a, t2.b FROM t t1 LEFT JOIN t t2 ON FALSE;
> should be same as
> SELECT t2.a, 2 as b FROM t t1 LEFT JOIN t t2 ON FALSE;
> so i think this is expected.
Hi,

I believe virtual columns should behave like stored columns, except they don't actually use storage.
Virtual columns are computed when the table is read, and they should adhere to the same rules of join semantics.
I agree with Richard, the result seems incorrect. The right outcome should be:
gpadmin=# SELECT t2.a, t2.b FROM t t1 LEFT JOIN t t2 ON FALSE;
 a | b
------+------
 NULL | NULL
 NULL | NULL
(2 rows)

--
Zhang Mingli
HashData

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrei Lepikhov 2025-02-10 05:19:49 Re: Removing unneeded self joins
Previous Message Suraj Kharage 2025-02-10 05:13:18 Re: Support for NO INHERIT to INHERIT state change with named NOT NULL constraints