mirror of
https://github.com/postgres/postgres.git
synced 2025-12-07 12:02:30 +03:00
Restructure representation of join alias variables. An explicit JOIN
now has an RTE of its own, and references to its outputs now are Vars referencing the JOIN RTE, rather than CASE-expressions. This allows reverse-listing in ruleutils.c to use the correct alias easily, rather than painfully reverse-engineering the alias namespace as it used to do. Also, nested FULL JOINs work correctly, because the result of the inner joins are simple Vars that the planner can cope with. This fixes a bug reported a couple times now, notably by Tatsuo on 18-Nov-01. The alias Vars are expanded into COALESCE expressions where needed at the very end of planning, rather than during parsing. Also, beginnings of support for showing plan qualifier expressions in EXPLAIN. There are probably still cases that need work. initdb forced due to change of stored-rule representation.
This commit is contained in:
@@ -1846,8 +1846,33 @@ SELECT '' AS "xxx", *
|
||||
SELECT '' AS "xxx", *
|
||||
FROM J1_TBL UNION JOIN J2_TBL;
|
||||
ERROR: UNION JOIN is not implemented yet
|
||||
--
|
||||
-- Multiway full join
|
||||
--
|
||||
CREATE TABLE t1 (name TEXT, n INTEGER);
|
||||
CREATE TABLE t2 (name TEXT, n INTEGER);
|
||||
CREATE TABLE t3 (name TEXT, n INTEGER);
|
||||
INSERT INTO t1 VALUES ( 'aa', 11 );
|
||||
INSERT INTO t2 VALUES ( 'aa', 12 );
|
||||
INSERT INTO t2 VALUES ( 'bb', 22 );
|
||||
INSERT INTO t2 VALUES ( 'dd', 42 );
|
||||
INSERT INTO t3 VALUES ( 'aa', 13 );
|
||||
INSERT INTO t3 VALUES ( 'bb', 23 );
|
||||
INSERT INTO t3 VALUES ( 'cc', 33 );
|
||||
SELECT * FROM t1 FULL JOIN t2 USING (name) FULL JOIN t3 USING (name);
|
||||
name | n | n | n
|
||||
------+----+----+----
|
||||
aa | 11 | 12 | 13
|
||||
bb | | 22 | 23
|
||||
cc | | | 33
|
||||
dd | | 42 |
|
||||
(4 rows)
|
||||
|
||||
--
|
||||
-- Clean up
|
||||
--
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t3;
|
||||
DROP TABLE J1_TBL;
|
||||
DROP TABLE J2_TBL;
|
||||
|
||||
@@ -198,10 +198,31 @@ SELECT '' AS "xxx", *
|
||||
SELECT '' AS "xxx", *
|
||||
FROM J1_TBL UNION JOIN J2_TBL;
|
||||
|
||||
--
|
||||
-- Multiway full join
|
||||
--
|
||||
|
||||
CREATE TABLE t1 (name TEXT, n INTEGER);
|
||||
CREATE TABLE t2 (name TEXT, n INTEGER);
|
||||
CREATE TABLE t3 (name TEXT, n INTEGER);
|
||||
|
||||
INSERT INTO t1 VALUES ( 'aa', 11 );
|
||||
INSERT INTO t2 VALUES ( 'aa', 12 );
|
||||
INSERT INTO t2 VALUES ( 'bb', 22 );
|
||||
INSERT INTO t2 VALUES ( 'dd', 42 );
|
||||
INSERT INTO t3 VALUES ( 'aa', 13 );
|
||||
INSERT INTO t3 VALUES ( 'bb', 23 );
|
||||
INSERT INTO t3 VALUES ( 'cc', 33 );
|
||||
|
||||
SELECT * FROM t1 FULL JOIN t2 USING (name) FULL JOIN t3 USING (name);
|
||||
|
||||
--
|
||||
-- Clean up
|
||||
--
|
||||
|
||||
DROP TABLE t1;
|
||||
DROP TABLE t2;
|
||||
DROP TABLE t3;
|
||||
|
||||
DROP TABLE J1_TBL;
|
||||
DROP TABLE J2_TBL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user