Re: Virtual generated columns - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: Virtual generated columns
Date
Msg-id CAEZATCWsKqCtZ=ud26-gGV3zHt-hjS4OKG43GCBhSaYUWyfKiw@mail.gmail.com
Whole thread Raw
In response to Virtual generated columns  (Peter Eisentraut <peter@eisentraut.org>)
Responses Re: Virtual generated columns
Re: Virtual generated columns
Re: Virtual generated columns
List pgsql-hackers
On Wed, 19 Feb 2025 at 01:42, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
>
> One thing I don't like about this is that it's introducing more code
> duplication between pullup_replace_vars() and
> ReplaceVarsFromTargetList(). Those already had a lot of code in common
> before RETURNING OLD/NEW was added, and this is duplicating even more
> code. I think it'd be better to refactor so that they share common
> code, since it has become quite complex, and it would be better to
> have just one place to maintain. Attached is an updated patch doing
> that.
>

I've been doing some more testing of this, and attached is another
update, improving a few comments and adding regression tests based on
the cases discussed so far here.

One of the new regression tests fails, which actually appears to be a
pre-existing grouping sets bug, due to the fact that only non-Vars are
wrapped in PHVs. This bug can be triggered without virtual generated
columns:

CREATE TABLE t (a int, b int);
INSERT INTO t VALUES (1, 1);

SELECT * FROM (SELECT a, a AS b FROM t) AS vt
GROUP BY GROUPING SETS (a, b)
HAVING b = 1;

 a | b
---+---
 1 |
(1 row)

whereas the result should be

 a | b
---+---
   |  1
(1 row)

For reference, this code dates back to 90947674fc.

Regards,
Dean

Attachment

pgsql-hackers by date:

Previous
From: Aleksander Alekseev
Date:
Subject: Re: new commitfest transition guidance
Next
From: Jelte Fennema-Nio
Date:
Subject: Re: new commitfest transition guidance