summaryrefslogtreecommitdiff
path: root/src/backend/tcop
diff options
context:
space:
mode:
authorTom Lane2017-01-27 03:09:34 +0000
committerTom Lane2017-01-27 03:09:34 +0000
commit7afd56c3c6d8360a5bfdfb2de30038b239fd756b (patch)
treedf9eb70bc951cdfe35629861285d5c6f31789ad7 /src/backend/tcop
parent9ba8a9ce4548bb34b7136b7463a61b2c499979a3 (diff)
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/tcop')
-rw-r--r--src/backend/tcop/postgres.c12
-rw-r--r--src/backend/tcop/pquery.c6
-rw-r--r--src/backend/tcop/utility.c9
3 files changed, 11 insertions, 16 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 62d49c8625..b07d6c6cb9 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -962,7 +962,7 @@ exec_simple_query(const char *query_string)
*/
foreach(parsetree_item, parsetree_list)
{
- RawStmt *parsetree = (RawStmt *) lfirst(parsetree_item);
+ RawStmt *parsetree = castNode(RawStmt, lfirst(parsetree_item));
bool snapshot_set = false;
const char *commandTag;
char completionTag[COMPLETION_TAG_BUFSIZE];
@@ -1286,7 +1286,7 @@ exec_parse_message(const char *query_string, /* string to execute */
bool snapshot_set = false;
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.
@@ -2148,7 +2148,7 @@ errdetail_execute(List *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))
{
@@ -2502,9 +2502,8 @@ IsTransactionExitStmtList(List *pstmts)
{
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 &&
IsTransactionExitStmt(pstmt->utilityStmt))
return true;
@@ -2518,9 +2517,8 @@ IsTransactionStmtList(List *pstmts)
{
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 &&
IsA(pstmt->utilityStmt, TransactionStmt))
return true;
diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
index 704be399cf..e64ea2ed76 100644
--- a/src/backend/tcop/pquery.c
+++ b/src/backend/tcop/pquery.c
@@ -487,7 +487,7 @@ PortalStart(Portal portal, ParamListInfo params,
* Create QueryDesc in portal's context; for the moment, set
* the destination to DestNone.
*/
- queryDesc = CreateQueryDesc((PlannedStmt *) linitial(portal->stmts),
+ queryDesc = CreateQueryDesc(castNode(PlannedStmt, linitial(portal->stmts)),
portal->sourceText,
GetActiveSnapshot(),
InvalidSnapshot,
@@ -1020,7 +1020,7 @@ FillPortalStore(Portal portal, bool isTopLevel)
break;
case PORTAL_UTIL_SELECT:
- PortalRunUtility(portal, (PlannedStmt *) linitial(portal->stmts),
+ PortalRunUtility(portal, castNode(PlannedStmt, linitial(portal->stmts)),
isTopLevel, true, treceiver, completionTag);
break;
@@ -1215,7 +1215,7 @@ PortalRunMulti(Portal portal,
*/
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
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 0306247177..801a9634dc 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -1829,22 +1829,19 @@ UtilityContainsQuery(Node *parsetree)
switch (nodeTag(parsetree))
{
case T_DeclareCursorStmt:
- qry = (Query *) ((DeclareCursorStmt *) parsetree)->query;
- Assert(IsA(qry, Query));
+ qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt);
return qry;
case T_ExplainStmt:
- qry = (Query *) ((ExplainStmt *) parsetree)->query;
- Assert(IsA(qry, Query));
+ qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt);
return qry;
case T_CreateTableAsStmt:
- qry = (Query *) ((CreateTableAsStmt *) parsetree)->query;
- Assert(IsA(qry, Query));
+ qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
if (qry->commandType == CMD_UTILITY)
return UtilityContainsQuery(qry->utilityStmt);
return qry;