Commit bc93ac12 authored by Robert Haas's avatar Robert Haas

Require non-NULL pstate for all addRangeTableEntryFor* functions.

Per discussion, it's better to have a consistent coding rule here.

Michael Paquier, per a node from Greg Stark referencing an old post
from Tom Lane.
parent c6b3c939
...@@ -345,6 +345,7 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse) ...@@ -345,6 +345,7 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
List *new_rt; List *new_rt;
RangeTblEntry *rt_entry1, RangeTblEntry *rt_entry1,
*rt_entry2; *rt_entry2;
ParseState *pstate;
/* /*
* Make a copy of the given parsetree. It's not so much that we don't * Make a copy of the given parsetree. It's not so much that we don't
...@@ -356,6 +357,9 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse) ...@@ -356,6 +357,9 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
*/ */
viewParse = (Query *) copyObject(viewParse); viewParse = (Query *) copyObject(viewParse);
/* Create a dummy ParseState for addRangeTableEntryForRelation */
pstate = make_parsestate(NULL);
/* need to open the rel for addRangeTableEntryForRelation */ /* need to open the rel for addRangeTableEntryForRelation */
viewRel = relation_open(viewOid, AccessShareLock); viewRel = relation_open(viewOid, AccessShareLock);
...@@ -363,10 +367,10 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse) ...@@ -363,10 +367,10 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
* Create the 2 new range table entries and form the new range table... * Create the 2 new range table entries and form the new range table...
* OLD first, then NEW.... * OLD first, then NEW....
*/ */
rt_entry1 = addRangeTableEntryForRelation(NULL, viewRel, rt_entry1 = addRangeTableEntryForRelation(pstate, viewRel,
makeAlias("old", NIL), makeAlias("old", NIL),
false, false); false, false);
rt_entry2 = addRangeTableEntryForRelation(NULL, viewRel, rt_entry2 = addRangeTableEntryForRelation(pstate, viewRel,
makeAlias("new", NIL), makeAlias("new", NIL),
false, false); false, false);
/* Must override addRangeTableEntry's default access-check flags */ /* Must override addRangeTableEntry's default access-check flags */
......
...@@ -1233,6 +1233,7 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink, ...@@ -1233,6 +1233,7 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
RangeTblRef *rtr; RangeTblRef *rtr;
List *subquery_vars; List *subquery_vars;
Node *quals; Node *quals;
ParseState *pstate;
Assert(sublink->subLinkType == ANY_SUBLINK); Assert(sublink->subLinkType == ANY_SUBLINK);
...@@ -1264,6 +1265,9 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink, ...@@ -1264,6 +1265,9 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
if (contain_volatile_functions(sublink->testexpr)) if (contain_volatile_functions(sublink->testexpr))
return NULL; return NULL;
/* Create a dummy ParseState for addRangeTableEntryForSubquery */
pstate = make_parsestate(NULL);
/* /*
* Okay, pull up the sub-select into upper range table. * Okay, pull up the sub-select into upper range table.
* *
...@@ -1272,7 +1276,7 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink, ...@@ -1272,7 +1276,7 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
* below). Therefore this is a lot easier than what pull_up_subqueries has * below). Therefore this is a lot easier than what pull_up_subqueries has
* to go through. * to go through.
*/ */
rte = addRangeTableEntryForSubquery(NULL, rte = addRangeTableEntryForSubquery(pstate,
subselect, subselect,
makeAlias("ANY_subquery", NIL), makeAlias("ANY_subquery", NIL),
false, false,
......
...@@ -1245,6 +1245,8 @@ addRangeTableEntryForRelation(ParseState *pstate, ...@@ -1245,6 +1245,8 @@ addRangeTableEntryForRelation(ParseState *pstate,
RangeTblEntry *rte = makeNode(RangeTblEntry); RangeTblEntry *rte = makeNode(RangeTblEntry);
char *refname = alias ? alias->aliasname : RelationGetRelationName(rel); char *refname = alias ? alias->aliasname : RelationGetRelationName(rel);
Assert(pstate != NULL);
rte->rtekind = RTE_RELATION; rte->rtekind = RTE_RELATION;
rte->alias = alias; rte->alias = alias;
rte->relid = RelationGetRelid(rel); rte->relid = RelationGetRelid(rel);
...@@ -1276,7 +1278,6 @@ addRangeTableEntryForRelation(ParseState *pstate, ...@@ -1276,7 +1278,6 @@ addRangeTableEntryForRelation(ParseState *pstate,
* Add completed RTE to pstate's range table list, but not to join list * Add completed RTE to pstate's range table list, but not to join list
* nor namespace --- caller must do that if appropriate. * nor namespace --- caller must do that if appropriate.
*/ */
if (pstate != NULL)
pstate->p_rtable = lappend(pstate->p_rtable, rte); pstate->p_rtable = lappend(pstate->p_rtable, rte);
return rte; return rte;
...@@ -1302,6 +1303,8 @@ addRangeTableEntryForSubquery(ParseState *pstate, ...@@ -1302,6 +1303,8 @@ addRangeTableEntryForSubquery(ParseState *pstate,
int varattno; int varattno;
ListCell *tlistitem; ListCell *tlistitem;
Assert(pstate != NULL);
rte->rtekind = RTE_SUBQUERY; rte->rtekind = RTE_SUBQUERY;
rte->relid = InvalidOid; rte->relid = InvalidOid;
rte->subquery = subquery; rte->subquery = subquery;
...@@ -1354,7 +1357,6 @@ addRangeTableEntryForSubquery(ParseState *pstate, ...@@ -1354,7 +1357,6 @@ addRangeTableEntryForSubquery(ParseState *pstate,
* Add completed RTE to pstate's range table list, but not to join list * Add completed RTE to pstate's range table list, but not to join list
* nor namespace --- caller must do that if appropriate. * nor namespace --- caller must do that if appropriate.
*/ */
if (pstate != NULL)
pstate->p_rtable = lappend(pstate->p_rtable, rte); pstate->p_rtable = lappend(pstate->p_rtable, rte);
return rte; return rte;
...@@ -1391,6 +1393,8 @@ addRangeTableEntryForFunction(ParseState *pstate, ...@@ -1391,6 +1393,8 @@ addRangeTableEntryForFunction(ParseState *pstate,
int natts, int natts,
totalatts; totalatts;
Assert(pstate != NULL);
rte->rtekind = RTE_FUNCTION; rte->rtekind = RTE_FUNCTION;
rte->relid = InvalidOid; rte->relid = InvalidOid;
rte->subquery = NULL; rte->subquery = NULL;
...@@ -1608,7 +1612,6 @@ addRangeTableEntryForFunction(ParseState *pstate, ...@@ -1608,7 +1612,6 @@ addRangeTableEntryForFunction(ParseState *pstate,
* Add completed RTE to pstate's range table list, but not to join list * Add completed RTE to pstate's range table list, but not to join list
* nor namespace --- caller must do that if appropriate. * nor namespace --- caller must do that if appropriate.
*/ */
if (pstate != NULL)
pstate->p_rtable = lappend(pstate->p_rtable, rte); pstate->p_rtable = lappend(pstate->p_rtable, rte);
return rte; return rte;
...@@ -1633,6 +1636,8 @@ addRangeTableEntryForValues(ParseState *pstate, ...@@ -1633,6 +1636,8 @@ addRangeTableEntryForValues(ParseState *pstate,
int numaliases; int numaliases;
int numcolumns; int numcolumns;
Assert(pstate != NULL);
rte->rtekind = RTE_VALUES; rte->rtekind = RTE_VALUES;
rte->relid = InvalidOid; rte->relid = InvalidOid;
rte->subquery = NULL; rte->subquery = NULL;
...@@ -1680,7 +1685,6 @@ addRangeTableEntryForValues(ParseState *pstate, ...@@ -1680,7 +1685,6 @@ addRangeTableEntryForValues(ParseState *pstate,
* Add completed RTE to pstate's range table list, but not to join list * Add completed RTE to pstate's range table list, but not to join list
* nor namespace --- caller must do that if appropriate. * nor namespace --- caller must do that if appropriate.
*/ */
if (pstate != NULL)
pstate->p_rtable = lappend(pstate->p_rtable, rte); pstate->p_rtable = lappend(pstate->p_rtable, rte);
return rte; return rte;
...@@ -1703,6 +1707,8 @@ addRangeTableEntryForJoin(ParseState *pstate, ...@@ -1703,6 +1707,8 @@ addRangeTableEntryForJoin(ParseState *pstate,
Alias *eref; Alias *eref;
int numaliases; int numaliases;
Assert(pstate != NULL);
/* /*
* Fail if join has too many columns --- we must be able to reference any * Fail if join has too many columns --- we must be able to reference any
* of the columns with an AttrNumber. * of the columns with an AttrNumber.
...@@ -1748,7 +1754,6 @@ addRangeTableEntryForJoin(ParseState *pstate, ...@@ -1748,7 +1754,6 @@ addRangeTableEntryForJoin(ParseState *pstate,
* Add completed RTE to pstate's range table list, but not to join list * Add completed RTE to pstate's range table list, but not to join list
* nor namespace --- caller must do that if appropriate. * nor namespace --- caller must do that if appropriate.
*/ */
if (pstate != NULL)
pstate->p_rtable = lappend(pstate->p_rtable, rte); pstate->p_rtable = lappend(pstate->p_rtable, rte);
return rte; return rte;
...@@ -1774,6 +1779,8 @@ addRangeTableEntryForCTE(ParseState *pstate, ...@@ -1774,6 +1779,8 @@ addRangeTableEntryForCTE(ParseState *pstate,
int varattno; int varattno;
ListCell *lc; ListCell *lc;
Assert(pstate != NULL);
rte->rtekind = RTE_CTE; rte->rtekind = RTE_CTE;
rte->ctename = cte->ctename; rte->ctename = cte->ctename;
rte->ctelevelsup = levelsup; rte->ctelevelsup = levelsup;
...@@ -1848,7 +1855,6 @@ addRangeTableEntryForCTE(ParseState *pstate, ...@@ -1848,7 +1855,6 @@ addRangeTableEntryForCTE(ParseState *pstate,
* Add completed RTE to pstate's range table list, but not to join list * Add completed RTE to pstate's range table list, but not to join list
* nor namespace --- caller must do that if appropriate. * nor namespace --- caller must do that if appropriate.
*/ */
if (pstate != NULL)
pstate->p_rtable = lappend(pstate->p_rtable, rte); pstate->p_rtable = lappend(pstate->p_rtable, rte);
return rte; return rte;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment