|
17 | 17 | * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group |
18 | 18 | * Portions Copyright (c) 1994, Regents of the University of California |
19 | 19 | * |
20 | | - *$PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.393 2009/10/26 02:26:35 tgl Exp $ |
| 20 | + *$PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.394 2009/10/27 17:11:18 tgl Exp $ |
21 | 21 | * |
22 | 22 | *------------------------------------------------------------------------- |
23 | 23 | */ |
@@ -138,12 +138,14 @@ parse_analyze_varparams(Node *parseTree, const char *sourceText, |
138 | 138 | */ |
139 | 139 | Query* |
140 | 140 | parse_sub_analyze(Node*parseTree,ParseState*parentParseState, |
141 | | -CommonTableExpr*parentCTE) |
| 141 | +CommonTableExpr*parentCTE, |
| 142 | +boollocked_from_parent) |
142 | 143 | { |
143 | 144 | ParseState*pstate=make_parsestate(parentParseState); |
144 | 145 | Query*query; |
145 | 146 |
|
146 | 147 | pstate->p_parent_cte=parentCTE; |
| 148 | +pstate->p_locked_from_parent=locked_from_parent; |
147 | 149 |
|
148 | 150 | query=transformStmt(pstate,parseTree); |
149 | 151 |
|
@@ -1424,7 +1426,7 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt, |
1424 | 1426 | * of this sub-query, because they are not in the toplevel pstate's |
1425 | 1427 | * namespace list. |
1426 | 1428 | */ |
1427 | | -selectQuery=parse_sub_analyze((Node*)stmt,pstate,NULL); |
| 1429 | +selectQuery=parse_sub_analyze((Node*)stmt,pstate,NULL, false); |
1428 | 1430 |
|
1429 | 1431 | /* |
1430 | 1432 | * Check for bogus references to Vars on the current query level (but |
@@ -2051,7 +2053,7 @@ CheckSelectLocking(Query *qry) |
2051 | 2053 | * This basically involves replacing names by integer relids. |
2052 | 2054 | * |
2053 | 2055 | * NB: if you need to change this, see also markQueryForLocking() |
2054 | | - * in rewriteHandler.c, andisLockedRel() in parse_relation.c. |
| 2056 | + * in rewriteHandler.c, andisLockedRefname() in parse_relation.c. |
2055 | 2057 | */ |
2056 | 2058 | staticvoid |
2057 | 2059 | transformLockingClause(ParseState*pstate,Query*qry,LockingClause*lc) |
@@ -2093,32 +2095,8 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc) |
2093 | 2095 | */ |
2094 | 2096 | transformLockingClause(pstate,rte->subquery,allrels); |
2095 | 2097 | break; |
2096 | | -caseRTE_CTE: |
2097 | | -{ |
2098 | | -/* |
2099 | | - * We allow FOR UPDATE/SHARE of a WITH query to be |
2100 | | - * propagated into the WITH, but it doesn't seem very |
2101 | | - * sane to allow this for a reference to an |
2102 | | - * outer-level WITH. And it definitely wouldn't work |
2103 | | - * for a self-reference, since we're not done |
2104 | | - * analyzing the CTE anyway. |
2105 | | - */ |
2106 | | -CommonTableExpr*cte; |
2107 | | - |
2108 | | -if (rte->ctelevelsup>0||rte->self_reference) |
2109 | | -ereport(ERROR, |
2110 | | -(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
2111 | | -errmsg("SELECT FOR UPDATE/SHARE cannot be applied to an outer-level WITH query"))); |
2112 | | -cte=GetCTEForRTE(pstate,rte,-1); |
2113 | | -/* should be analyzed by now */ |
2114 | | -Assert(IsA(cte->ctequery,Query)); |
2115 | | -transformLockingClause(pstate, |
2116 | | - (Query*)cte->ctequery, |
2117 | | -allrels); |
2118 | | -} |
2119 | | -break; |
2120 | 2098 | default: |
2121 | | -/* ignore JOIN, SPECIAL, FUNCTION RTEs */ |
| 2099 | +/* ignore JOIN, SPECIAL, FUNCTION, VALUES, CTE RTEs */ |
2122 | 2100 | break; |
2123 | 2101 | } |
2124 | 2102 | } |
@@ -2185,30 +2163,10 @@ transformLockingClause(ParseState *pstate, Query *qry, LockingClause *lc) |
2185 | 2163 | parser_errposition(pstate,thisrel->location))); |
2186 | 2164 | break; |
2187 | 2165 | caseRTE_CTE: |
2188 | | -{ |
2189 | | -/* |
2190 | | - * We allow FOR UPDATE/SHARE of a WITH query |
2191 | | - * to be propagated into the WITH, but it |
2192 | | - * doesn't seem very sane to allow this for a |
2193 | | - * reference to an outer-level WITH. And it |
2194 | | - * definitely wouldn't work for a |
2195 | | - * self-reference, since we're not done |
2196 | | - * analyzing the CTE anyway. |
2197 | | - */ |
2198 | | -CommonTableExpr*cte; |
2199 | | - |
2200 | | -if (rte->ctelevelsup>0||rte->self_reference) |
2201 | | -ereport(ERROR, |
2202 | | - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
2203 | | -errmsg("SELECT FOR UPDATE/SHARE cannot be applied to an outer-level WITH query"), |
2204 | | -parser_errposition(pstate,thisrel->location))); |
2205 | | -cte=GetCTEForRTE(pstate,rte,-1); |
2206 | | -/* should be analyzed by now */ |
2207 | | -Assert(IsA(cte->ctequery,Query)); |
2208 | | -transformLockingClause(pstate, |
2209 | | - (Query*)cte->ctequery, |
2210 | | -allrels); |
2211 | | -} |
| 2166 | +ereport(ERROR, |
| 2167 | +(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 2168 | +errmsg("SELECT FOR UPDATE/SHARE cannot be applied to a WITH query"), |
| 2169 | +parser_errposition(pstate,thisrel->location))); |
2212 | 2170 | break; |
2213 | 2171 | default: |
2214 | 2172 | elog(ERROR,"unrecognized RTE type: %d", |
|