Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bc93ac1

Browse files
committed
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.
1 parent c6b3c93 commit bc93ac1

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/backend/commands/view.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
345345
List *new_rt;
346346
RangeTblEntry *rt_entry1,
347347
*rt_entry2;
348+
ParseState *pstate;
348349

349350
/*
350351
* Make a copy of the given parsetree. It's not so much that we don't
@@ -356,17 +357,20 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
356357
*/
357358
viewParse = (Query *) copyObject(viewParse);
358359

360+
/* Create a dummy ParseState for addRangeTableEntryForRelation */
361+
pstate = make_parsestate(NULL);
362+
359363
/* need to open the rel for addRangeTableEntryForRelation */
360364
viewRel = relation_open(viewOid, AccessShareLock);
361365

362366
/*
363367
* Create the 2 new range table entries and form the new range table...
364368
* OLD first, then NEW....
365369
*/
366-
rt_entry1 = addRangeTableEntryForRelation(NULL, viewRel,
370+
rt_entry1 = addRangeTableEntryForRelation(pstate, viewRel,
367371
makeAlias("old", NIL),
368372
false, false);
369-
rt_entry2 = addRangeTableEntryForRelation(NULL, viewRel,
373+
rt_entry2 = addRangeTableEntryForRelation(pstate, viewRel,
370374
makeAlias("new", NIL),
371375
false, false);
372376
/* Must override addRangeTableEntry's default access-check flags */

src/backend/optimizer/plan/subselect.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
12331233
RangeTblRef *rtr;
12341234
List *subquery_vars;
12351235
Node *quals;
1236+
ParseState *pstate;
12361237

12371238
Assert(sublink->subLinkType == ANY_SUBLINK);
12381239

@@ -1264,6 +1265,9 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
12641265
if (contain_volatile_functions(sublink->testexpr))
12651266
return NULL;
12661267

1268+
/* Create a dummy ParseState for addRangeTableEntryForSubquery */
1269+
pstate = make_parsestate(NULL);
1270+
12671271
/*
12681272
* Okay, pull up the sub-select into upper range table.
12691273
*
@@ -1272,7 +1276,7 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
12721276
* below). Therefore this is a lot easier than what pull_up_subqueries has
12731277
* to go through.
12741278
*/
1275-
rte = addRangeTableEntryForSubquery(NULL,
1279+
rte = addRangeTableEntryForSubquery(pstate,
12761280
subselect,
12771281
makeAlias("ANY_subquery", NIL),
12781282
false,

src/backend/parser/parse_relation.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,8 @@ addRangeTableEntryForRelation(ParseState *pstate,
12451245
RangeTblEntry *rte = makeNode(RangeTblEntry);
12461246
char *refname = alias ? alias->aliasname : RelationGetRelationName(rel);
12471247

1248+
Assert(pstate != NULL);
1249+
12481250
rte->rtekind = RTE_RELATION;
12491251
rte->alias = alias;
12501252
rte->relid = RelationGetRelid(rel);
@@ -1276,8 +1278,7 @@ addRangeTableEntryForRelation(ParseState *pstate,
12761278
* Add completed RTE to pstate's range table list, but not to join list
12771279
* nor namespace --- caller must do that if appropriate.
12781280
*/
1279-
if (pstate != NULL)
1280-
pstate->p_rtable = lappend(pstate->p_rtable, rte);
1281+
pstate->p_rtable = lappend(pstate->p_rtable, rte);
12811282

12821283
return rte;
12831284
}
@@ -1302,6 +1303,8 @@ addRangeTableEntryForSubquery(ParseState *pstate,
13021303
int varattno;
13031304
ListCell *tlistitem;
13041305

1306+
Assert(pstate != NULL);
1307+
13051308
rte->rtekind = RTE_SUBQUERY;
13061309
rte->relid = InvalidOid;
13071310
rte->subquery = subquery;
@@ -1354,8 +1357,7 @@ addRangeTableEntryForSubquery(ParseState *pstate,
13541357
* Add completed RTE to pstate's range table list, but not to join list
13551358
* nor namespace --- caller must do that if appropriate.
13561359
*/
1357-
if (pstate != NULL)
1358-
pstate->p_rtable = lappend(pstate->p_rtable, rte);
1360+
pstate->p_rtable = lappend(pstate->p_rtable, rte);
13591361

13601362
return rte;
13611363
}
@@ -1391,6 +1393,8 @@ addRangeTableEntryForFunction(ParseState *pstate,
13911393
int natts,
13921394
totalatts;
13931395

1396+
Assert(pstate != NULL);
1397+
13941398
rte->rtekind = RTE_FUNCTION;
13951399
rte->relid = InvalidOid;
13961400
rte->subquery = NULL;
@@ -1608,8 +1612,7 @@ addRangeTableEntryForFunction(ParseState *pstate,
16081612
* Add completed RTE to pstate's range table list, but not to join list
16091613
* nor namespace --- caller must do that if appropriate.
16101614
*/
1611-
if (pstate != NULL)
1612-
pstate->p_rtable = lappend(pstate->p_rtable, rte);
1615+
pstate->p_rtable = lappend(pstate->p_rtable, rte);
16131616

16141617
return rte;
16151618
}
@@ -1633,6 +1636,8 @@ addRangeTableEntryForValues(ParseState *pstate,
16331636
int numaliases;
16341637
int numcolumns;
16351638

1639+
Assert(pstate != NULL);
1640+
16361641
rte->rtekind = RTE_VALUES;
16371642
rte->relid = InvalidOid;
16381643
rte->subquery = NULL;
@@ -1680,8 +1685,7 @@ addRangeTableEntryForValues(ParseState *pstate,
16801685
* Add completed RTE to pstate's range table list, but not to join list
16811686
* nor namespace --- caller must do that if appropriate.
16821687
*/
1683-
if (pstate != NULL)
1684-
pstate->p_rtable = lappend(pstate->p_rtable, rte);
1688+
pstate->p_rtable = lappend(pstate->p_rtable, rte);
16851689

16861690
return rte;
16871691
}
@@ -1703,6 +1707,8 @@ addRangeTableEntryForJoin(ParseState *pstate,
17031707
Alias *eref;
17041708
int numaliases;
17051709

1710+
Assert(pstate != NULL);
1711+
17061712
/*
17071713
* Fail if join has too many columns --- we must be able to reference any
17081714
* of the columns with an AttrNumber.
@@ -1748,8 +1754,7 @@ addRangeTableEntryForJoin(ParseState *pstate,
17481754
* Add completed RTE to pstate's range table list, but not to join list
17491755
* nor namespace --- caller must do that if appropriate.
17501756
*/
1751-
if (pstate != NULL)
1752-
pstate->p_rtable = lappend(pstate->p_rtable, rte);
1757+
pstate->p_rtable = lappend(pstate->p_rtable, rte);
17531758

17541759
return rte;
17551760
}
@@ -1774,6 +1779,8 @@ addRangeTableEntryForCTE(ParseState *pstate,
17741779
int varattno;
17751780
ListCell *lc;
17761781

1782+
Assert(pstate != NULL);
1783+
17771784
rte->rtekind = RTE_CTE;
17781785
rte->ctename = cte->ctename;
17791786
rte->ctelevelsup = levelsup;
@@ -1848,8 +1855,7 @@ addRangeTableEntryForCTE(ParseState *pstate,
18481855
* Add completed RTE to pstate's range table list, but not to join list
18491856
* nor namespace --- caller must do that if appropriate.
18501857
*/
1851-
if (pstate != NULL)
1852-
pstate->p_rtable = lappend(pstate->p_rtable, rte);
1858+
pstate->p_rtable = lappend(pstate->p_rtable, rte);
18531859

18541860
return rte;
18551861
}

0 commit comments

Comments
 (0)