1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-19 17:02:53 +03:00

Expand virtual generated columns before sublink pull-up

Currently, we expand virtual generated columns after we have pulled up
any SubLinks within the query's quals.  This ensures that the virtual
generated column references within SubLinks that should be transformed
into joins are correctly expanded.  This approach works well and has
posed no issues.

In an upcoming patch, we plan to centralize the collection of catalog
information needed early in the planner.  This will help avoid
repeated table_open/table_close calls for relations in the rangetable.
Since this information is required during sublink pull-up, we are
moving the expansion of virtual generated columns to occur beforehand.

To achieve this, if any EXISTS SubLinks can be pulled up, their
rangetables are processed just before pulling them up.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAMbWs4-bFJ1At4btk5wqbezdu8PLtQ3zv-aiaY3ry9Ymm=jgFQ@mail.gmail.com
This commit is contained in:
Richard Guo
2025-07-22 11:19:17 +09:00
parent 0810fbb02d
commit e0d0529526
6 changed files with 76 additions and 21 deletions

View File

@@ -1613,4 +1613,26 @@ select * from gtest32 t group by grouping sets (a, b, c, d, e) having c = 20;
-- Ensure that the virtual generated columns in ALTER COLUMN TYPE USING expression are expanded
alter table gtest32 alter column e type bigint using b;
-- Ensure that virtual generated column references within SubLinks that should
-- be transformed into joins can get expanded
explain (costs off)
select 1 from gtest32 t1 where exists
(select 1 from gtest32 t2 where t1.a > t2.a and t2.b = 2);
QUERY PLAN
-------------------------------------
Nested Loop Semi Join
Join Filter: (t1.a > t2.a)
-> Seq Scan on gtest32 t1
-> Materialize
-> Seq Scan on gtest32 t2
Filter: ((a * 2) = 2)
(6 rows)
select 1 from gtest32 t1 where exists
(select 1 from gtest32 t2 where t1.a > t2.a and t2.b = 2);
?column?
----------
1
(1 row)
drop table gtest32;

View File

@@ -858,4 +858,13 @@ select * from gtest32 t group by grouping sets (a, b, c, d, e) having c = 20;
-- Ensure that the virtual generated columns in ALTER COLUMN TYPE USING expression are expanded
alter table gtest32 alter column e type bigint using b;
-- Ensure that virtual generated column references within SubLinks that should
-- be transformed into joins can get expanded
explain (costs off)
select 1 from gtest32 t1 where exists
(select 1 from gtest32 t2 where t1.a > t2.a and t2.b = 2);
select 1 from gtest32 t1 where exists
(select 1 from gtest32 t2 where t1.a > t2.a and t2.b = 2);
drop table gtest32;