aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-01-26 22:09:34 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2017-01-26 22:09:34 -0500
commit7afd56c3c6d8360a5bfdfb2de30038b239fd756b (patch)
treedf9eb70bc951cdfe35629861285d5c6f31789ad7 /src/backend/utils/cache
parent9ba8a9ce4548bb34b7136b7463a61b2c499979a3 (diff)
downloadpostgresql-7afd56c3c6d8360a5bfdfb2de30038b239fd756b.tar.gz
postgresql-7afd56c3c6d8360a5bfdfb2de30038b239fd756b.zip
Use castNode() in a bunch of statement-list-related code.
When I wrote commit ab1f0c822, I really missed the castNode() macro that Peter E. had proposed shortly before. This back-fills the uses I would have put it to. It's probably not all that significant, but there are more assertions here than there were before, and conceivably they will help catch any bugs associated with those representation changes. I left behind a number of usages like "(Query *) copyObject(query_var)". Those could have been converted as well, but Peter has proposed another notational improvement that would handle copyObject cases automatically, so I let that be for now.
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r--src/backend/utils/cache/plancache.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index c31c603fbf5..dffc92762bc 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -975,7 +975,7 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
is_transient = false;
foreach(lc, plist)
{
- PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc);
+ PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */
@@ -1070,7 +1070,7 @@ cached_plan_cost(CachedPlan *plan, bool include_planner)
foreach(lc, plan->stmt_list)
{
- PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc);
+ PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */
@@ -1457,9 +1457,7 @@ QueryListGetPrimaryStmt(List *stmts)
foreach(lc, stmts)
{
- Query *stmt = (Query *) lfirst(lc);
-
- Assert(IsA(stmt, Query));
+ Query *stmt = castNode(Query, lfirst(lc));
if (stmt->canSetTag)
return stmt;
@@ -1478,12 +1476,10 @@ AcquireExecutorLocks(List *stmt_list, bool acquire)
foreach(lc1, stmt_list)
{
- PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc1);
+ PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc1));
int rt_index;
ListCell *lc2;
- Assert(IsA(plannedstmt, PlannedStmt));
-
if (plannedstmt->commandType == CMD_UTILITY)
{
/*
@@ -1549,9 +1545,7 @@ AcquirePlannerLocks(List *stmt_list, bool acquire)
foreach(lc, stmt_list)
{
- Query *query = (Query *) lfirst(lc);
-
- Assert(IsA(query, Query));
+ Query *query = castNode(Query, lfirst(lc));
if (query->commandType == CMD_UTILITY)
{
@@ -1618,9 +1612,9 @@ ScanQueryForLocks(Query *parsetree, bool acquire)
/* Recurse into subquery-in-WITH */
foreach(lc, parsetree->cteList)
{
- CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc);
+ CommonTableExpr *cte = castNode(CommonTableExpr, lfirst(lc));
- ScanQueryForLocks((Query *) cte->ctequery, acquire);
+ ScanQueryForLocks(castNode(Query, cte->ctequery), acquire);
}
/*
@@ -1648,7 +1642,7 @@ ScanQueryWalker(Node *node, bool *acquire)
SubLink *sub = (SubLink *) node;
/* Do what we came for */
- ScanQueryForLocks((Query *) sub->subselect, *acquire);
+ ScanQueryForLocks(castNode(Query, sub->subselect), *acquire);
/* Fall through to process lefthand args of SubLink */
}
@@ -1676,8 +1670,7 @@ PlanCacheComputeResultDesc(List *stmt_list)
{
case PORTAL_ONE_SELECT:
case PORTAL_ONE_MOD_WITH:
- query = (Query *) linitial(stmt_list);
- Assert(IsA(query, Query));
+ query = castNode(Query, linitial(stmt_list));
return ExecCleanTypeFromTL(query->targetList, false);
case PORTAL_ONE_RETURNING:
@@ -1686,8 +1679,7 @@ PlanCacheComputeResultDesc(List *stmt_list)
return ExecCleanTypeFromTL(query->returningList, false);
case PORTAL_UTIL_SELECT:
- query = (Query *) linitial(stmt_list);
- Assert(IsA(query, Query));
+ query = castNode(Query, linitial(stmt_list));
Assert(query->utilityStmt);
return UtilityTupleDescriptor(query->utilityStmt);
@@ -1744,7 +1736,7 @@ PlanCacheRelCallback(Datum arg, Oid relid)
foreach(lc, plansource->gplan->stmt_list)
{
- PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc);
+ PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */
@@ -1817,7 +1809,7 @@ PlanCacheFuncCallback(Datum arg, int cacheid, uint32 hashvalue)
{
foreach(lc, plansource->gplan->stmt_list)
{
- PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc);
+ PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
ListCell *lc3;
if (plannedstmt->commandType == CMD_UTILITY)
@@ -1890,9 +1882,8 @@ ResetPlanCache(void)
*/
foreach(lc, plansource->query_list)
{
- Query *query = (Query *) lfirst(lc);
+ Query *query = castNode(Query, lfirst(lc));
- Assert(IsA(query, Query));
if (query->commandType != CMD_UTILITY ||
UtilityContainsQuery(query->utilityStmt))
{