Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d99a81

Browse files
committed
Fix incorrect printing of queries with duplicated join names.
Given a query in which multiple JOIN nodes used the same alias(which'd necessarily be in different sub-SELECTs), ruleutils.cwould assign the JOIN nodes distinct aliases for clarity ...but then it forgot to print the modified aliases when dumpingthe JOIN nodes themselves. This results in a dump/reload hazardfor views, because the emitted query is flat-out incorrect:Vars will be printed with table names that have no referent.This has been wrong for a long time, so back-patch to all supportedbranches.Philip DubéDiscussion:https://postgr.es/m/CY4PR2101MB080246F2955FF58A6ED1FEAC98140@CY4PR2101MB0802.namprd21.prod.outlook.com
1 parentddc053d commit3d99a81

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10309,8 +10309,16 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
1030910309
/* Yes, it's correct to put alias after the right paren ... */
1031010310
if (j->alias!=NULL)
1031110311
{
10312+
/*
10313+
* Note that it's correct to emit an alias clause if and only if
10314+
* there was one originally. Otherwise we'd be converting a named
10315+
* join to unnamed or vice versa, which creates semantic
10316+
* subtleties we don't want. However, we might print a different
10317+
* alias name than was there originally.
10318+
*/
1031210319
appendStringInfo(buf," %s",
10313-
quote_identifier(j->alias->aliasname));
10320+
quote_identifier(get_rtable_name(j->rtindex,
10321+
context)));
1031410322
get_column_alias_list(colinfo,context);
1031510323
}
1031610324
}

‎src/test/regress/expected/create_view.out

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,41 @@ View definition:
769769
FROM temp_view_test.tx1 tx1_1
770770
WHERE tx1.y1 = tx1_1.f1));
771771

772+
-- Test aliasing of joins
773+
create view view_of_joins as
774+
select * from
775+
(select * from (tbl1 cross join tbl2) same) ss,
776+
(tbl3 cross join tbl4) same;
777+
\d+ view_of_joins
778+
View "testviewschm2.view_of_joins"
779+
Column | Type | Collation | Nullable | Default | Storage | Description
780+
--------+---------+-----------+----------+---------+---------+-------------
781+
a | integer | | | | plain |
782+
b | integer | | | | plain |
783+
c | integer | | | | plain |
784+
d | integer | | | | plain |
785+
e | integer | | | | plain |
786+
f | integer | | | | plain |
787+
g | integer | | | | plain |
788+
h | integer | | | | plain |
789+
View definition:
790+
SELECT ss.a,
791+
ss.b,
792+
ss.c,
793+
ss.d,
794+
same.e,
795+
same.f,
796+
same.g,
797+
same.h
798+
FROM ( SELECT same_1.a,
799+
same_1.b,
800+
same_1.c,
801+
same_1.d
802+
FROM (tbl1
803+
CROSS JOIN tbl2) same_1) ss,
804+
(tbl3
805+
CROSS JOIN tbl4) same;
806+
772807
-- Test view decompilation in the face of column addition/deletion/renaming
773808
create table tt2 (a int, b int, c int);
774809
create table tt3 (ax int8, b int2, c numeric);
@@ -1747,7 +1782,7 @@ drop cascades to view aliased_view_2
17471782
drop cascades to view aliased_view_3
17481783
drop cascades to view aliased_view_4
17491784
DROP SCHEMA testviewschm2 CASCADE;
1750-
NOTICE: drop cascades to62 other objects
1785+
NOTICE: drop cascades to63 other objects
17511786
DETAIL: drop cascades to table t1
17521787
drop cascades to view temporal1
17531788
drop cascades to view temporal2
@@ -1771,6 +1806,7 @@ drop cascades to view mysecview4
17711806
drop cascades to view unspecified_types
17721807
drop cascades to table tt1
17731808
drop cascades to table tx1
1809+
drop cascades to view view_of_joins
17741810
drop cascades to table tt2
17751811
drop cascades to table tt3
17761812
drop cascades to table tt4

‎src/test/regress/sql/create_view.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ ALTER TABLE tmp1 RENAME TO tx1;
319319
\d+ aliased_view_3
320320
\d+ aliased_view_4
321321

322+
-- Test aliasing of joins
323+
324+
createviewview_of_joinsas
325+
select*from
326+
(select*from (tbl1cross join tbl2) same) ss,
327+
(tbl3cross join tbl4) same;
328+
329+
\d+ view_of_joins
330+
322331
-- Test view decompilation in the face of column addition/deletion/renaming
323332

324333
createtablett2 (aint, bint, cint);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp