1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-17 17:02:08 +03:00

Fix GetCTEForRTE() to deal with the possibility that the RTE it's given came

from a query level above the current ParseState.
This commit is contained in:
Tom Lane
2008-10-06 15:15:22 +00:00
parent 5f853c6556
commit e64bb65aff
4 changed files with 23 additions and 12 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.137 2008/10/06 02:12:56 tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.138 2008/10/06 15:15:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -371,15 +371,23 @@ GetRTEByRangeTablePosn(ParseState *pstate,
/*
* Fetch the CTE for a CTE-reference RTE.
*
* rtelevelsup is the number of query levels above the given pstate that the
* RTE came from. Callers that don't have this information readily available
* may pass -1 instead.
*/
CommonTableExpr *
GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte)
GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, int rtelevelsup)
{
Index levelsup;
ListCell *lc;
/* Determine RTE's levelsup if caller didn't know it */
if (rtelevelsup < 0)
(void) RTERangeTablePosn(pstate, rte, &rtelevelsup);
Assert(rte->rtekind == RTE_CTE);
levelsup = rte->ctelevelsup;
levelsup = rte->ctelevelsup + rtelevelsup;
while (levelsup-- > 0)
{
pstate = pstate->parentParseState;