Skip to content

Commit 4688869

Browse files
committed
Tweak the order of processing of WITH clauses so that they are processed
before we start analyzing the parent statement. This is to make it more clear that the WITH isn't affected by anything in the parent. I don't believe there's any actual bug here, because the stuff that was being done before WITH didn't affect subqueries; but it's certainly a potential for error (and apparently misled Marko into committing some real errors...).
1 parent 1b3a437 commit 4688869

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/backend/parser/analyze.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
20-
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.400 2010/01/15 22:36:33 tgl Exp $
20+
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.401 2010/02/12 22:48:56 tgl Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -783,19 +783,19 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
783783

784784
qry->commandType = CMD_SELECT;
785785

786-
/* make FOR UPDATE/FOR SHARE info available to addRangeTableEntry */
787-
pstate->p_locking_clause = stmt->lockingClause;
788-
789-
/* make WINDOW info available for window functions, too */
790-
pstate->p_windowdefs = stmt->windowClause;
791-
792-
/* process the WITH clause */
786+
/* process the WITH clause independently of all else */
793787
if (stmt->withClause)
794788
{
795789
qry->hasRecursive = stmt->withClause->recursive;
796790
qry->cteList = transformWithClause(pstate, stmt->withClause);
797791
}
798792

793+
/* make FOR UPDATE/FOR SHARE info available to addRangeTableEntry */
794+
pstate->p_locking_clause = stmt->lockingClause;
795+
796+
/* make WINDOW info available for window functions, too */
797+
pstate->p_windowdefs = stmt->windowClause;
798+
799799
/* process the FROM clause */
800800
transformFromClause(pstate, stmt->fromClause);
801801

@@ -929,7 +929,7 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
929929
Assert(stmt->windowClause == NIL);
930930
Assert(stmt->op == SETOP_NONE);
931931

932-
/* process the WITH clause */
932+
/* process the WITH clause independently of all else */
933933
if (stmt->withClause)
934934
{
935935
qry->hasRecursive = stmt->withClause->recursive;
@@ -1149,6 +1149,13 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
11491149

11501150
qry->commandType = CMD_SELECT;
11511151

1152+
/* process the WITH clause independently of all else */
1153+
if (stmt->withClause)
1154+
{
1155+
qry->hasRecursive = stmt->withClause->recursive;
1156+
qry->cteList = transformWithClause(pstate, stmt->withClause);
1157+
}
1158+
11521159
/*
11531160
* Find leftmost leaf SelectStmt; extract the one-time-only items from it
11541161
* and from the top-level node.
@@ -1188,13 +1195,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
11881195
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
11891196
errmsg("SELECT FOR UPDATE/SHARE is not allowed with UNION/INTERSECT/EXCEPT")));
11901197

1191-
/* process the WITH clause */
1192-
if (stmt->withClause)
1193-
{
1194-
qry->hasRecursive = stmt->withClause->recursive;
1195-
qry->cteList = transformWithClause(pstate, stmt->withClause);
1196-
}
1197-
11981198
/*
11991199
* Recursively transform the components of the tree.
12001200
*/

0 commit comments

Comments
 (0)