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

Commitf9c655d

Browse files
committed
Fix alias matching in transformLockingClause().
When locking a specific named relation for a FOR [KEY] UPDATE/SHAREclause, transformLockingClause() finds the relation to lock byscanning the rangetable for an RTE with a matching eref->aliasname.However, it failed to account for the visibility rules of a join RTE.If a join RTE doesn't have a user-supplied alias, it will have agenerated eref->aliasname of "unnamed_join" that is not visible as arelation name in the parse namespace. Such an RTE needs to be skipped,otherwise it might be found in preference to a regular base relationwith a user-supplied alias of "unnamed_join", preventing it from beinglocked.In addition, if a join RTE doesn't have a user-supplied alias, butdoes have a join_using_alias, then the RTE needs to be matched usingthat alias rather than the generated eref->aliasname, otherwise amisleading "relation not found" error will be reported rather than a"join cannot be locked" error.Backpatch all the way, except for the second part which only goes backto 14, where JOIN USING aliases were added.Dean Rasheed, reviewed by Tom Lane.Discussion:https://postgr.es/m/CAEZATCUY_KOBnqxbTSPf=7fz9HWPnZ5Xgb9SwYzZ8rFXe7nb=w@mail.gmail.com
1 parent7c2b79c commitf9c655d

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

‎src/backend/parser/analyze.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,6 +2809,15 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc,
28092809
++i;
28102810
if (!rte->inFromCl)
28112811
continue;
2812+
2813+
/*
2814+
* A join RTE without an alias is not visible as a relation
2815+
* name and needs to be skipped (otherwise it might hide a
2816+
* base relation with the same name).
2817+
*/
2818+
if (rte->rtekind==RTE_JOIN&&rte->alias==NULL)
2819+
continue;
2820+
28122821
if (strcmp(rte->eref->aliasname,thisrel->relname)==0)
28132822
{
28142823
switch (rte->rtekind)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,14 @@ ERROR: column t1.x does not exist
24492449
LINE 1: select t1.x from t1 join t3 on (t1.a = t3.x);
24502450
^
24512451
HINT: Perhaps you meant to reference the column "t3.x".
2452+
-- Test matching of locking clause with wrong alias
2453+
select t1.*, t2.*, unnamed_join.* from
2454+
t1 join t2 on (t1.a = t2.a), t3 as unnamed_join
2455+
for update of unnamed_join;
2456+
a | b | a | b | x | y
2457+
---+---+---+---+---+---
2458+
(0 rows)
2459+
24522460
--
24532461
-- regression test for 8.1 merge right join bug
24542462
--

‎src/test/regress/sql/join.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ select * from t1 left join t2 on (t1.a = t2.a);
509509

510510
selectt1.xfrom t1join t3on (t1.a=t3.x);
511511

512+
-- Test matching of locking clause with wrong alias
513+
514+
select t1.*, t2.*, unnamed_join.*from
515+
t1join t2on (t1.a=t2.a), t3as unnamed_join
516+
forupdate of unnamed_join;
517+
512518
--
513519
-- regression test for 8.1 merge right join bug
514520
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp