Commit 7afd56c3 authored by Tom Lane's avatar Tom Lane

Use castNode() in a bunch of statement-list-related code.

When I wrote commit ab1f0c82, 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.
parent 9ba8a9ce
...@@ -930,7 +930,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS) ...@@ -930,7 +930,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
querytree_list = NIL; querytree_list = NIL;
foreach(lc, raw_parsetree_list) foreach(lc, raw_parsetree_list)
{ {
RawStmt *parsetree = (RawStmt *) lfirst(lc); RawStmt *parsetree = castNode(RawStmt, lfirst(lc));
List *querytree_sublist; List *querytree_sublist;
querytree_sublist = pg_analyze_and_rewrite_params(parsetree, querytree_sublist = pg_analyze_and_rewrite_params(parsetree,
......
...@@ -322,7 +322,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ...@@ -322,7 +322,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
elog(ERROR, "unexpected rewrite result for %s", elog(ERROR, "unexpected rewrite result for %s",
is_matview ? "CREATE MATERIALIZED VIEW" : is_matview ? "CREATE MATERIALIZED VIEW" :
"CREATE TABLE AS SELECT"); "CREATE TABLE AS SELECT");
query = (Query *) linitial(rewritten); query = castNode(Query, linitial(rewritten));
Assert(query->commandType == CMD_SELECT); Assert(query->commandType == CMD_SELECT);
/* plan the query --- note we disallow parallelism */ /* plan the query --- note we disallow parallelism */
......
...@@ -224,8 +224,7 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString, ...@@ -224,8 +224,7 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
* executed repeatedly. (See also the same hack in DECLARE CURSOR and * executed repeatedly. (See also the same hack in DECLARE CURSOR and
* PREPARE.) XXX FIXME someday. * PREPARE.) XXX FIXME someday.
*/ */
Assert(IsA(stmt->query, Query)); rewritten = QueryRewrite(castNode(Query, copyObject(stmt->query)));
rewritten = QueryRewrite((Query *) copyObject(stmt->query));
/* emit opening boilerplate */ /* emit opening boilerplate */
ExplainBeginOutput(es); ExplainBeginOutput(es);
...@@ -246,7 +245,7 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString, ...@@ -246,7 +245,7 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
/* Explain every plan */ /* Explain every plan */
foreach(l, rewritten) foreach(l, rewritten)
{ {
ExplainOneQuery((Query *) lfirst(l), ExplainOneQuery(castNode(Query, lfirst(l)),
CURSOR_OPT_PARALLEL_OK, NULL, es, CURSOR_OPT_PARALLEL_OK, NULL, es,
queryString, params); queryString, params);
...@@ -395,10 +394,9 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, ...@@ -395,10 +394,9 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es,
CreateTableAsStmt *ctas = (CreateTableAsStmt *) utilityStmt; CreateTableAsStmt *ctas = (CreateTableAsStmt *) utilityStmt;
List *rewritten; List *rewritten;
Assert(IsA(ctas->query, Query)); rewritten = QueryRewrite(castNode(Query, copyObject(ctas->query)));
rewritten = QueryRewrite((Query *) copyObject(ctas->query));
Assert(list_length(rewritten) == 1); Assert(list_length(rewritten) == 1);
ExplainOneQuery((Query *) linitial(rewritten), ExplainOneQuery(castNode(Query, linitial(rewritten)),
0, ctas->into, es, 0, ctas->into, es,
queryString, params); queryString, params);
} }
...@@ -415,10 +413,9 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, ...@@ -415,10 +413,9 @@ ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es,
DeclareCursorStmt *dcs = (DeclareCursorStmt *) utilityStmt; DeclareCursorStmt *dcs = (DeclareCursorStmt *) utilityStmt;
List *rewritten; List *rewritten;
Assert(IsA(dcs->query, Query)); rewritten = QueryRewrite(castNode(Query, copyObject(dcs->query)));
rewritten = QueryRewrite((Query *) copyObject(dcs->query));
Assert(list_length(rewritten) == 1); Assert(list_length(rewritten) == 1);
ExplainOneQuery((Query *) linitial(rewritten), ExplainOneQuery(castNode(Query, linitial(rewritten)),
dcs->options, NULL, es, dcs->options, NULL, es,
queryString, params); queryString, params);
} }
......
...@@ -713,7 +713,7 @@ execute_sql_string(const char *sql, const char *filename) ...@@ -713,7 +713,7 @@ execute_sql_string(const char *sql, const char *filename)
*/ */
foreach(lc1, raw_parsetree_list) foreach(lc1, raw_parsetree_list)
{ {
RawStmt *parsetree = (RawStmt *) lfirst(lc1); RawStmt *parsetree = castNode(RawStmt, lfirst(lc1));
List *stmt_list; List *stmt_list;
ListCell *lc2; ListCell *lc2;
...@@ -725,7 +725,7 @@ execute_sql_string(const char *sql, const char *filename) ...@@ -725,7 +725,7 @@ execute_sql_string(const char *sql, const char *filename)
foreach(lc2, stmt_list) foreach(lc2, stmt_list)
{ {
PlannedStmt *stmt = (PlannedStmt *) lfirst(lc2); PlannedStmt *stmt = castNode(PlannedStmt, lfirst(lc2));
CommandCounterIncrement(); CommandCounterIncrement();
......
...@@ -1572,7 +1572,7 @@ ImportForeignSchema(ImportForeignSchemaStmt *stmt) ...@@ -1572,7 +1572,7 @@ ImportForeignSchema(ImportForeignSchemaStmt *stmt)
*/ */
foreach(lc2, raw_parsetree_list) foreach(lc2, raw_parsetree_list)
{ {
RawStmt *rs = (RawStmt *) lfirst(lc2); RawStmt *rs = castNode(RawStmt, lfirst(lc2));
CreateForeignTableStmt *cstmt = (CreateForeignTableStmt *) rs->stmt; CreateForeignTableStmt *cstmt = (CreateForeignTableStmt *) rs->stmt;
PlannedStmt *pstmt; PlannedStmt *pstmt;
......
...@@ -42,14 +42,12 @@ void ...@@ -42,14 +42,12 @@ void
PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params, PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params,
const char *queryString, bool isTopLevel) const char *queryString, bool isTopLevel)
{ {
Query *query = (Query *) cstmt->query; Query *query = castNode(Query, cstmt->query);
List *rewritten; List *rewritten;
PlannedStmt *plan; PlannedStmt *plan;
Portal portal; Portal portal;
MemoryContext oldContext; MemoryContext oldContext;
Assert(IsA(query, Query)); /* else parse analysis wasn't done */
/* /*
* Disallow empty-string cursor name (conflicts with protocol-level * Disallow empty-string cursor name (conflicts with protocol-level
* unnamed portal). * unnamed portal).
...@@ -85,7 +83,7 @@ PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params, ...@@ -85,7 +83,7 @@ PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params,
if (list_length(rewritten) != 1) if (list_length(rewritten) != 1)
elog(ERROR, "non-SELECT statement in DECLARE CURSOR"); elog(ERROR, "non-SELECT statement in DECLARE CURSOR");
query = (Query *) linitial(rewritten); query = castNode(Query, linitial(rewritten));
if (query->commandType != CMD_SELECT) if (query->commandType != CMD_SELECT)
elog(ERROR, "non-SELECT statement in DECLARE CURSOR"); elog(ERROR, "non-SELECT statement in DECLARE CURSOR");
......
...@@ -265,8 +265,7 @@ ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause, ...@@ -265,8 +265,7 @@ ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause,
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE), (errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("prepared statement is not a SELECT"))); errmsg("prepared statement is not a SELECT")));
pstmt = (PlannedStmt *) linitial(plan_list); pstmt = castNode(PlannedStmt, linitial(plan_list));
Assert(IsA(pstmt, PlannedStmt));
if (pstmt->commandType != CMD_SELECT) if (pstmt->commandType != CMD_SELECT)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE), (errcode(ERRCODE_WRONG_OBJECT_TYPE),
...@@ -670,9 +669,8 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es, ...@@ -670,9 +669,8 @@ ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es,
/* Explain each query */ /* Explain each query */
foreach(p, plan_list) foreach(p, plan_list)
{ {
PlannedStmt *pstmt = (PlannedStmt *) lfirst(p); PlannedStmt *pstmt = castNode(PlannedStmt, lfirst(p));
Assert(IsA(pstmt, PlannedStmt));
if (pstmt->commandType != CMD_UTILITY) if (pstmt->commandType != CMD_UTILITY)
ExplainOnePlan(pstmt, into, es, query_string, paramLI, NULL); ExplainOnePlan(pstmt, into, es, query_string, paramLI, NULL);
else else
......
...@@ -9281,7 +9281,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd, ...@@ -9281,7 +9281,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
querytree_list = NIL; querytree_list = NIL;
foreach(list_item, raw_parsetree_list) foreach(list_item, raw_parsetree_list)
{ {
RawStmt *rs = (RawStmt *) lfirst(list_item); RawStmt *rs = castNode(RawStmt, lfirst(list_item));
Node *stmt = rs->stmt; Node *stmt = rs->stmt;
if (IsA(stmt, IndexStmt)) if (IsA(stmt, IndexStmt))
......
...@@ -707,7 +707,7 @@ init_sql_fcache(FmgrInfo *finfo, Oid collation, bool lazyEvalOK) ...@@ -707,7 +707,7 @@ init_sql_fcache(FmgrInfo *finfo, Oid collation, bool lazyEvalOK)
flat_query_list = NIL; flat_query_list = NIL;
foreach(lc, raw_parsetree_list) foreach(lc, raw_parsetree_list)
{ {
RawStmt *parsetree = (RawStmt *) lfirst(lc); RawStmt *parsetree = castNode(RawStmt, lfirst(lc));
List *queryTree_sublist; List *queryTree_sublist;
queryTree_sublist = pg_analyze_and_rewrite_params(parsetree, queryTree_sublist = pg_analyze_and_rewrite_params(parsetree,
...@@ -1551,7 +1551,7 @@ check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList, ...@@ -1551,7 +1551,7 @@ check_sql_fn_retval(Oid func_id, Oid rettype, List *queryTreeList,
parse = NULL; parse = NULL;
foreach(lc, queryTreeList) foreach(lc, queryTreeList)
{ {
Query *q = (Query *) lfirst(lc); Query *q = castNode(Query, lfirst(lc));
if (q->canSetTag) if (q->canSetTag)
parse = q; parse = q;
......
...@@ -1232,9 +1232,9 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan, ...@@ -1232,9 +1232,9 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
if (!(portal->cursorOptions & (CURSOR_OPT_SCROLL | CURSOR_OPT_NO_SCROLL))) if (!(portal->cursorOptions & (CURSOR_OPT_SCROLL | CURSOR_OPT_NO_SCROLL)))
{ {
if (list_length(stmt_list) == 1 && if (list_length(stmt_list) == 1 &&
((PlannedStmt *) linitial(stmt_list))->commandType != CMD_UTILITY && castNode(PlannedStmt, linitial(stmt_list))->commandType != CMD_UTILITY &&
((PlannedStmt *) linitial(stmt_list))->rowMarks == NIL && castNode(PlannedStmt, linitial(stmt_list))->rowMarks == NIL &&
ExecSupportsBackwardScan(((PlannedStmt *) linitial(stmt_list))->planTree)) ExecSupportsBackwardScan(castNode(PlannedStmt, linitial(stmt_list))->planTree))
portal->cursorOptions |= CURSOR_OPT_SCROLL; portal->cursorOptions |= CURSOR_OPT_SCROLL;
else else
portal->cursorOptions |= CURSOR_OPT_NO_SCROLL; portal->cursorOptions |= CURSOR_OPT_NO_SCROLL;
...@@ -1248,8 +1248,8 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan, ...@@ -1248,8 +1248,8 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
if (portal->cursorOptions & CURSOR_OPT_SCROLL) if (portal->cursorOptions & CURSOR_OPT_SCROLL)
{ {
if (list_length(stmt_list) == 1 && if (list_length(stmt_list) == 1 &&
((PlannedStmt *) linitial(stmt_list))->commandType != CMD_UTILITY && castNode(PlannedStmt, linitial(stmt_list))->commandType != CMD_UTILITY &&
((PlannedStmt *) linitial(stmt_list))->rowMarks != NIL) castNode(PlannedStmt, linitial(stmt_list))->rowMarks != NIL)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("DECLARE SCROLL CURSOR ... FOR UPDATE/SHARE is not supported"), errmsg("DECLARE SCROLL CURSOR ... FOR UPDATE/SHARE is not supported"),
...@@ -1270,7 +1270,7 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan, ...@@ -1270,7 +1270,7 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
foreach(lc, stmt_list) foreach(lc, stmt_list)
{ {
PlannedStmt *pstmt = (PlannedStmt *) lfirst(lc); PlannedStmt *pstmt = castNode(PlannedStmt, lfirst(lc));
if (!CommandIsReadOnly(pstmt)) if (!CommandIsReadOnly(pstmt))
{ {
...@@ -1757,7 +1757,7 @@ _SPI_prepare_plan(const char *src, SPIPlanPtr plan) ...@@ -1757,7 +1757,7 @@ _SPI_prepare_plan(const char *src, SPIPlanPtr plan)
foreach(list_item, raw_parsetree_list) foreach(list_item, raw_parsetree_list)
{ {
RawStmt *parsetree = (RawStmt *) lfirst(list_item); RawStmt *parsetree = castNode(RawStmt, lfirst(list_item));
List *stmt_list; List *stmt_list;
CachedPlanSource *plansource; CachedPlanSource *plansource;
...@@ -1859,7 +1859,7 @@ _SPI_prepare_oneshot_plan(const char *src, SPIPlanPtr plan) ...@@ -1859,7 +1859,7 @@ _SPI_prepare_oneshot_plan(const char *src, SPIPlanPtr plan)
foreach(list_item, raw_parsetree_list) foreach(list_item, raw_parsetree_list)
{ {
RawStmt *parsetree = (RawStmt *) lfirst(list_item); RawStmt *parsetree = castNode(RawStmt, lfirst(list_item));
CachedPlanSource *plansource; CachedPlanSource *plansource;
plansource = CreateOneShotCachedPlan(parsetree, plansource = CreateOneShotCachedPlan(parsetree,
...@@ -2018,7 +2018,7 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI, ...@@ -2018,7 +2018,7 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
foreach(lc2, stmt_list) foreach(lc2, stmt_list)
{ {
PlannedStmt *stmt = (PlannedStmt *) lfirst(lc2); PlannedStmt *stmt = castNode(PlannedStmt, lfirst(lc2));
bool canSetTag = stmt->canSetTag; bool canSetTag = stmt->canSetTag;
DestReceiver *dest; DestReceiver *dest;
......
...@@ -788,7 +788,7 @@ stmtmulti: stmtmulti ';' stmt ...@@ -788,7 +788,7 @@ stmtmulti: stmtmulti ';' stmt
if ($1 != NIL) if ($1 != NIL)
{ {
/* update length of previous stmt */ /* update length of previous stmt */
updateRawStmtEnd((RawStmt *) llast($1), @2); updateRawStmtEnd(castNode(RawStmt, llast($1)), @2);
} }
if ($3 != NULL) if ($3 != NULL)
$$ = lappend($1, makeRawStmt($3, @2 + 1)); $$ = lappend($1, makeRawStmt($3, @2 + 1));
......
...@@ -1502,8 +1502,7 @@ transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref) ...@@ -1502,8 +1502,7 @@ transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref)
sublink = (SubLink *) transformExprRecurse(pstate, sublink = (SubLink *) transformExprRecurse(pstate,
(Node *) sublink); (Node *) sublink);
qtree = (Query *) sublink->subselect; qtree = castNode(Query, sublink->subselect);
Assert(IsA(qtree, Query));
/* Check subquery returns required number of columns */ /* Check subquery returns required number of columns */
if (count_nonjunk_tlist_entries(qtree->targetList) != maref->ncolumns) if (count_nonjunk_tlist_entries(qtree->targetList) != maref->ncolumns)
...@@ -1578,8 +1577,7 @@ transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref) ...@@ -1578,8 +1577,7 @@ transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref)
sublink = (SubLink *) tle->expr; sublink = (SubLink *) tle->expr;
Assert(sublink->subLinkType == MULTIEXPR_SUBLINK); Assert(sublink->subLinkType == MULTIEXPR_SUBLINK);
qtree = (Query *) sublink->subselect; qtree = castNode(Query, sublink->subselect);
Assert(IsA(qtree, Query));
/* Build a Param representing the current subquery output column */ /* Build a Param representing the current subquery output column */
tle = (TargetEntry *) list_nth(qtree->targetList, maref->colno - 1); tle = (TargetEntry *) list_nth(qtree->targetList, maref->colno - 1);
......
...@@ -720,7 +720,7 @@ typeStringToTypeName(const char *str) ...@@ -720,7 +720,7 @@ typeStringToTypeName(const char *str)
*/ */
if (list_length(raw_parsetree_list) != 1) if (list_length(raw_parsetree_list) != 1)
goto fail; goto fail;
stmt = (SelectStmt *) ((RawStmt *) linitial(raw_parsetree_list))->stmt; stmt = (SelectStmt *) castNode(RawStmt, linitial(raw_parsetree_list))->stmt;
if (stmt == NULL || if (stmt == NULL ||
!IsA(stmt, SelectStmt) || !IsA(stmt, SelectStmt) ||
stmt->distinctClause != NIL || stmt->distinctClause != NIL ||
......
...@@ -173,7 +173,7 @@ InsertRule(char *rulname, ...@@ -173,7 +173,7 @@ InsertRule(char *rulname,
if (event_qual != NULL) if (event_qual != NULL)
{ {
/* Find query containing OLD/NEW rtable entries */ /* Find query containing OLD/NEW rtable entries */
Query *qry = (Query *) linitial(action); Query *qry = castNode(Query, linitial(action));
qry = getInsertSelectQuery(qry, NULL); qry = getInsertSelectQuery(qry, NULL);
recordDependencyOnExpr(&myself, event_qual, qry->rtable, recordDependencyOnExpr(&myself, event_qual, qry->rtable,
...@@ -286,7 +286,7 @@ DefineQueryRewrite(char *rulename, ...@@ -286,7 +286,7 @@ DefineQueryRewrite(char *rulename,
*/ */
foreach(l, action) foreach(l, action)
{ {
query = (Query *) lfirst(l); query = castNode(Query, lfirst(l));
if (query->resultRelation == 0) if (query->resultRelation == 0)
continue; continue;
/* Don't be fooled by INSERT/SELECT */ /* Don't be fooled by INSERT/SELECT */
...@@ -328,7 +328,7 @@ DefineQueryRewrite(char *rulename, ...@@ -328,7 +328,7 @@ DefineQueryRewrite(char *rulename,
/* /*
* ... the one action must be a SELECT, ... * ... the one action must be a SELECT, ...
*/ */
query = (Query *) linitial(action); query = castNode(Query, linitial(action));
if (!is_instead || if (!is_instead ||
query->commandType != CMD_SELECT) query->commandType != CMD_SELECT)
ereport(ERROR, ereport(ERROR,
...@@ -482,7 +482,7 @@ DefineQueryRewrite(char *rulename, ...@@ -482,7 +482,7 @@ DefineQueryRewrite(char *rulename,
foreach(l, action) foreach(l, action)
{ {
query = (Query *) lfirst(l); query = castNode(Query, lfirst(l));
if (!query->returningList) if (!query->returningList)
continue; continue;
...@@ -813,7 +813,7 @@ setRuleCheckAsUser_Query(Query *qry, Oid userid) ...@@ -813,7 +813,7 @@ setRuleCheckAsUser_Query(Query *qry, Oid userid)
{ {
CommonTableExpr *cte = (CommonTableExpr *) lfirst(l); CommonTableExpr *cte = (CommonTableExpr *) lfirst(l);
setRuleCheckAsUser_Query((Query *) cte->ctequery, userid); setRuleCheckAsUser_Query(castNode(Query, cte->ctequery), userid);
} }
/* If there are sublinks, search for them and process their RTEs */ /* If there are sublinks, search for them and process their RTEs */
......
...@@ -962,7 +962,7 @@ exec_simple_query(const char *query_string) ...@@ -962,7 +962,7 @@ exec_simple_query(const char *query_string)
*/ */
foreach(parsetree_item, parsetree_list) foreach(parsetree_item, parsetree_list)
{ {
RawStmt *parsetree = (RawStmt *) lfirst(parsetree_item); RawStmt *parsetree = castNode(RawStmt, lfirst(parsetree_item));
bool snapshot_set = false; bool snapshot_set = false;
const char *commandTag; const char *commandTag;
char completionTag[COMPLETION_TAG_BUFSIZE]; char completionTag[COMPLETION_TAG_BUFSIZE];
...@@ -1286,7 +1286,7 @@ exec_parse_message(const char *query_string, /* string to execute */ ...@@ -1286,7 +1286,7 @@ exec_parse_message(const char *query_string, /* string to execute */
bool snapshot_set = false; bool snapshot_set = false;
int i; int i;
raw_parse_tree = (RawStmt *) linitial(parsetree_list); raw_parse_tree = castNode(RawStmt, linitial(parsetree_list));
/* /*
* Get the command name for possible use in status display. * Get the command name for possible use in status display.
...@@ -2148,7 +2148,7 @@ errdetail_execute(List *raw_parsetree_list) ...@@ -2148,7 +2148,7 @@ errdetail_execute(List *raw_parsetree_list)
foreach(parsetree_item, raw_parsetree_list) foreach(parsetree_item, raw_parsetree_list)
{ {
RawStmt *parsetree = (RawStmt *) lfirst(parsetree_item); RawStmt *parsetree = castNode(RawStmt, lfirst(parsetree_item));
if (IsA(parsetree->stmt, ExecuteStmt)) if (IsA(parsetree->stmt, ExecuteStmt))
{ {
...@@ -2502,9 +2502,8 @@ IsTransactionExitStmtList(List *pstmts) ...@@ -2502,9 +2502,8 @@ IsTransactionExitStmtList(List *pstmts)
{ {
if (list_length(pstmts) == 1) if (list_length(pstmts) == 1)
{ {
PlannedStmt *pstmt = (PlannedStmt *) linitial(pstmts); PlannedStmt *pstmt = castNode(PlannedStmt, linitial(pstmts));
Assert(IsA(pstmt, PlannedStmt));
if (pstmt->commandType == CMD_UTILITY && if (pstmt->commandType == CMD_UTILITY &&
IsTransactionExitStmt(pstmt->utilityStmt)) IsTransactionExitStmt(pstmt->utilityStmt))
return true; return true;
...@@ -2518,9 +2517,8 @@ IsTransactionStmtList(List *pstmts) ...@@ -2518,9 +2517,8 @@ IsTransactionStmtList(List *pstmts)
{ {
if (list_length(pstmts) == 1) if (list_length(pstmts) == 1)
{ {
PlannedStmt *pstmt = (PlannedStmt *) linitial(pstmts); PlannedStmt *pstmt = castNode(PlannedStmt, linitial(pstmts));
Assert(IsA(pstmt, PlannedStmt));
if (pstmt->commandType == CMD_UTILITY && if (pstmt->commandType == CMD_UTILITY &&
IsA(pstmt->utilityStmt, TransactionStmt)) IsA(pstmt->utilityStmt, TransactionStmt))
return true; return true;
......
...@@ -487,7 +487,7 @@ PortalStart(Portal portal, ParamListInfo params, ...@@ -487,7 +487,7 @@ PortalStart(Portal portal, ParamListInfo params,
* Create QueryDesc in portal's context; for the moment, set * Create QueryDesc in portal's context; for the moment, set
* the destination to DestNone. * the destination to DestNone.
*/ */
queryDesc = CreateQueryDesc((PlannedStmt *) linitial(portal->stmts), queryDesc = CreateQueryDesc(castNode(PlannedStmt, linitial(portal->stmts)),
portal->sourceText, portal->sourceText,
GetActiveSnapshot(), GetActiveSnapshot(),
InvalidSnapshot, InvalidSnapshot,
...@@ -1020,7 +1020,7 @@ FillPortalStore(Portal portal, bool isTopLevel) ...@@ -1020,7 +1020,7 @@ FillPortalStore(Portal portal, bool isTopLevel)
break; break;
case PORTAL_UTIL_SELECT: case PORTAL_UTIL_SELECT:
PortalRunUtility(portal, (PlannedStmt *) linitial(portal->stmts), PortalRunUtility(portal, castNode(PlannedStmt, linitial(portal->stmts)),
isTopLevel, true, treceiver, completionTag); isTopLevel, true, treceiver, completionTag);
break; break;
...@@ -1215,7 +1215,7 @@ PortalRunMulti(Portal portal, ...@@ -1215,7 +1215,7 @@ PortalRunMulti(Portal portal,
*/ */
foreach(stmtlist_item, portal->stmts) foreach(stmtlist_item, portal->stmts)
{ {
PlannedStmt *pstmt = (PlannedStmt *) lfirst(stmtlist_item); PlannedStmt *pstmt = castNode(PlannedStmt, lfirst(stmtlist_item));
/* /*
* If we got a cancel signal in prior command, quit * If we got a cancel signal in prior command, quit
......
...@@ -1829,22 +1829,19 @@ UtilityContainsQuery(Node *parsetree) ...@@ -1829,22 +1829,19 @@ UtilityContainsQuery(Node *parsetree)
switch (nodeTag(parsetree)) switch (nodeTag(parsetree))
{ {
case T_DeclareCursorStmt: case T_DeclareCursorStmt:
qry = (Query *) ((DeclareCursorStmt *) parsetree)->query; qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
Assert(IsA(qry, Query));
if (qry->commandType == CMD_UTILITY) if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt); return UtilityContainsQuery(qry->utilityStmt);
return qry; return qry;
case T_ExplainStmt: case T_ExplainStmt:
qry = (Query *) ((ExplainStmt *) parsetree)->query; qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
Assert(IsA(qry, Query));
if (qry->commandType == CMD_UTILITY) if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt); return UtilityContainsQuery(qry->utilityStmt);
return qry; return qry;
case T_CreateTableAsStmt: case T_CreateTableAsStmt:
qry = (Query *) ((CreateTableAsStmt *) parsetree)->query; qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
Assert(IsA(qry, Query));
if (qry->commandType == CMD_UTILITY) if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt); return UtilityContainsQuery(qry->utilityStmt);
return qry; return qry;
......
...@@ -975,7 +975,7 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist, ...@@ -975,7 +975,7 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
is_transient = false; is_transient = false;
foreach(lc, plist) foreach(lc, plist)
{ {
PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc); PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
if (plannedstmt->commandType == CMD_UTILITY) if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */ continue; /* Ignore utility statements */
...@@ -1070,7 +1070,7 @@ cached_plan_cost(CachedPlan *plan, bool include_planner) ...@@ -1070,7 +1070,7 @@ cached_plan_cost(CachedPlan *plan, bool include_planner)
foreach(lc, plan->stmt_list) foreach(lc, plan->stmt_list)
{ {
PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc); PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
if (plannedstmt->commandType == CMD_UTILITY) if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */ continue; /* Ignore utility statements */
...@@ -1457,9 +1457,7 @@ QueryListGetPrimaryStmt(List *stmts) ...@@ -1457,9 +1457,7 @@ QueryListGetPrimaryStmt(List *stmts)
foreach(lc, stmts) foreach(lc, stmts)
{ {
Query *stmt = (Query *) lfirst(lc); Query *stmt = castNode(Query, lfirst(lc));
Assert(IsA(stmt, Query));
if (stmt->canSetTag) if (stmt->canSetTag)
return stmt; return stmt;
...@@ -1478,12 +1476,10 @@ AcquireExecutorLocks(List *stmt_list, bool acquire) ...@@ -1478,12 +1476,10 @@ AcquireExecutorLocks(List *stmt_list, bool acquire)
foreach(lc1, stmt_list) foreach(lc1, stmt_list)
{ {
PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc1); PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc1));
int rt_index; int rt_index;
ListCell *lc2; ListCell *lc2;
Assert(IsA(plannedstmt, PlannedStmt));
if (plannedstmt->commandType == CMD_UTILITY) if (plannedstmt->commandType == CMD_UTILITY)
{ {
/* /*
...@@ -1549,9 +1545,7 @@ AcquirePlannerLocks(List *stmt_list, bool acquire) ...@@ -1549,9 +1545,7 @@ AcquirePlannerLocks(List *stmt_list, bool acquire)
foreach(lc, stmt_list) foreach(lc, stmt_list)
{ {
Query *query = (Query *) lfirst(lc); Query *query = castNode(Query, lfirst(lc));
Assert(IsA(query, Query));
if (query->commandType == CMD_UTILITY) if (query->commandType == CMD_UTILITY)
{ {
...@@ -1618,9 +1612,9 @@ ScanQueryForLocks(Query *parsetree, bool acquire) ...@@ -1618,9 +1612,9 @@ ScanQueryForLocks(Query *parsetree, bool acquire)
/* Recurse into subquery-in-WITH */ /* Recurse into subquery-in-WITH */
foreach(lc, parsetree->cteList) 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) ...@@ -1648,7 +1642,7 @@ ScanQueryWalker(Node *node, bool *acquire)
SubLink *sub = (SubLink *) node; SubLink *sub = (SubLink *) node;
/* Do what we came for */ /* Do what we came for */
ScanQueryForLocks((Query *) sub->subselect, *acquire); ScanQueryForLocks(castNode(Query, sub->subselect), *acquire);
/* Fall through to process lefthand args of SubLink */ /* Fall through to process lefthand args of SubLink */
} }
...@@ -1676,8 +1670,7 @@ PlanCacheComputeResultDesc(List *stmt_list) ...@@ -1676,8 +1670,7 @@ PlanCacheComputeResultDesc(List *stmt_list)
{ {
case PORTAL_ONE_SELECT: case PORTAL_ONE_SELECT:
case PORTAL_ONE_MOD_WITH: case PORTAL_ONE_MOD_WITH:
query = (Query *) linitial(stmt_list); query = castNode(Query, linitial(stmt_list));
Assert(IsA(query, Query));
return ExecCleanTypeFromTL(query->targetList, false); return ExecCleanTypeFromTL(query->targetList, false);
case PORTAL_ONE_RETURNING: case PORTAL_ONE_RETURNING:
...@@ -1686,8 +1679,7 @@ PlanCacheComputeResultDesc(List *stmt_list) ...@@ -1686,8 +1679,7 @@ PlanCacheComputeResultDesc(List *stmt_list)
return ExecCleanTypeFromTL(query->returningList, false); return ExecCleanTypeFromTL(query->returningList, false);
case PORTAL_UTIL_SELECT: case PORTAL_UTIL_SELECT:
query = (Query *) linitial(stmt_list); query = castNode(Query, linitial(stmt_list));
Assert(IsA(query, Query));
Assert(query->utilityStmt); Assert(query->utilityStmt);
return UtilityTupleDescriptor(query->utilityStmt); return UtilityTupleDescriptor(query->utilityStmt);
...@@ -1744,7 +1736,7 @@ PlanCacheRelCallback(Datum arg, Oid relid) ...@@ -1744,7 +1736,7 @@ PlanCacheRelCallback(Datum arg, Oid relid)
foreach(lc, plansource->gplan->stmt_list) foreach(lc, plansource->gplan->stmt_list)
{ {
PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc); PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
if (plannedstmt->commandType == CMD_UTILITY) if (plannedstmt->commandType == CMD_UTILITY)
continue; /* Ignore utility statements */ continue; /* Ignore utility statements */
...@@ -1817,7 +1809,7 @@ PlanCacheFuncCallback(Datum arg, int cacheid, uint32 hashvalue) ...@@ -1817,7 +1809,7 @@ PlanCacheFuncCallback(Datum arg, int cacheid, uint32 hashvalue)
{ {
foreach(lc, plansource->gplan->stmt_list) foreach(lc, plansource->gplan->stmt_list)
{ {
PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc); PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
ListCell *lc3; ListCell *lc3;
if (plannedstmt->commandType == CMD_UTILITY) if (plannedstmt->commandType == CMD_UTILITY)
...@@ -1890,9 +1882,8 @@ ResetPlanCache(void) ...@@ -1890,9 +1882,8 @@ ResetPlanCache(void)
*/ */
foreach(lc, plansource->query_list) 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 || if (query->commandType != CMD_UTILITY ||
UtilityContainsQuery(query->utilityStmt)) UtilityContainsQuery(query->utilityStmt))
{ {
......
...@@ -153,9 +153,7 @@ PortalGetPrimaryStmt(Portal portal) ...@@ -153,9 +153,7 @@ PortalGetPrimaryStmt(Portal portal)
foreach(lc, portal->stmts) foreach(lc, portal->stmts)
{ {
PlannedStmt *stmt = (PlannedStmt *) lfirst(lc); PlannedStmt *stmt = castNode(PlannedStmt, lfirst(lc));
Assert(IsA(stmt, PlannedStmt));
if (stmt->canSetTag) if (stmt->canSetTag)
return stmt; return stmt;
......
...@@ -3634,9 +3634,8 @@ exec_stmt_execsql(PLpgSQL_execstate *estate, ...@@ -3634,9 +3634,8 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
foreach(l2, plansource->query_list) foreach(l2, plansource->query_list)
{ {
Query *q = (Query *) lfirst(l2); Query *q = castNode(Query, lfirst(l2));
Assert(IsA(q, Query));
if (q->canSetTag) if (q->canSetTag)
{ {
if (q->commandType == CMD_INSERT || if (q->commandType == CMD_INSERT ||
...@@ -6825,8 +6824,7 @@ exec_simple_recheck_plan(PLpgSQL_expr *expr, CachedPlan *cplan) ...@@ -6825,8 +6824,7 @@ exec_simple_recheck_plan(PLpgSQL_expr *expr, CachedPlan *cplan)
*/ */
if (list_length(cplan->stmt_list) != 1) if (list_length(cplan->stmt_list) != 1)
return; return;
stmt = (PlannedStmt *) linitial(cplan->stmt_list); stmt = castNode(PlannedStmt, linitial(cplan->stmt_list));
Assert(IsA(stmt, PlannedStmt));
/* /*
* 2. It must be a RESULT plan --> no scan's required * 2. It must be a RESULT plan --> no scan's required
......
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