querytree_list = NIL;
foreach(lc, raw_parsetree_list)
{
- RawStmt *parsetree = (RawStmt *) lfirst(lc);
+ RawStmt *parsetree = castNode(RawStmt, lfirst(lc));
List *querytree_sublist;
querytree_sublist = pg_analyze_and_rewrite_params(parsetree,
elog(ERROR, "unexpected rewrite result for %s",
is_matview ? "CREATE MATERIALIZED VIEW" :
"CREATE TABLE AS SELECT");
- query = (Query *) linitial(rewritten);
+ query = castNode(Query, linitial(rewritten));
Assert(query->commandType == CMD_SELECT);
/* plan the query --- note we disallow parallelism */
* executed repeatedly. (See also the same hack in DECLARE CURSOR and
* PREPARE.) XXX FIXME someday.
*/
- Assert(IsA(stmt->query, Query));
- rewritten = QueryRewrite((Query *) copyObject(stmt->query));
+ rewritten = QueryRewrite(castNode(Query, copyObject(stmt->query)));
/* emit opening boilerplate */
ExplainBeginOutput(es);
/* Explain every plan */
foreach(l, rewritten)
{
- ExplainOneQuery((Query *) lfirst(l),
+ ExplainOneQuery(castNode(Query, lfirst(l)),
CURSOR_OPT_PARALLEL_OK, NULL, es,
queryString, params);
CreateTableAsStmt *ctas = (CreateTableAsStmt *) utilityStmt;
List *rewritten;
- Assert(IsA(ctas->query, Query));
- rewritten = QueryRewrite((Query *) copyObject(ctas->query));
+ rewritten = QueryRewrite(castNode(Query, copyObject(ctas->query)));
Assert(list_length(rewritten) == 1);
- ExplainOneQuery((Query *) linitial(rewritten),
+ ExplainOneQuery(castNode(Query, linitial(rewritten)),
0, ctas->into, es,
queryString, params);
}
DeclareCursorStmt *dcs = (DeclareCursorStmt *) utilityStmt;
List *rewritten;
- Assert(IsA(dcs->query, Query));
- rewritten = QueryRewrite((Query *) copyObject(dcs->query));
+ rewritten = QueryRewrite(castNode(Query, copyObject(dcs->query)));
Assert(list_length(rewritten) == 1);
- ExplainOneQuery((Query *) linitial(rewritten),
+ ExplainOneQuery(castNode(Query, linitial(rewritten)),
dcs->options, NULL, es,
queryString, params);
}
*/
foreach(lc1, raw_parsetree_list)
{
- RawStmt *parsetree = (RawStmt *) lfirst(lc1);
+ RawStmt *parsetree = castNode(RawStmt, lfirst(lc1));
List *stmt_list;
ListCell *lc2;
foreach(lc2, stmt_list)
{
- PlannedStmt *stmt = (PlannedStmt *) lfirst(lc2);
+ PlannedStmt *stmt = castNode(PlannedStmt, lfirst(lc2));
CommandCounterIncrement();
*/
foreach(lc2, raw_parsetree_list)
{
- RawStmt *rs = (RawStmt *) lfirst(lc2);
+ RawStmt *rs = castNode(RawStmt, lfirst(lc2));
CreateForeignTableStmt *cstmt = (CreateForeignTableStmt *) rs->stmt;
PlannedStmt *pstmt;
PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params,
const char *queryString, bool isTopLevel)
{
- Query *query = (Query *) cstmt->query;
+ Query *query = castNode(Query, cstmt->query);
List *rewritten;
PlannedStmt *plan;
Portal portal;
MemoryContext oldContext;
- Assert(IsA(query, Query)); /* else parse analysis wasn't done */
-
/*
* Disallow empty-string cursor name (conflicts with protocol-level
* unnamed portal).
if (list_length(rewritten) != 1)
elog(ERROR, "non-SELECT statement in DECLARE CURSOR");
- query = (Query *) linitial(rewritten);
+ query = castNode(Query, linitial(rewritten));
if (query->commandType != CMD_SELECT)
elog(ERROR, "non-SELECT statement in DECLARE CURSOR");
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("prepared statement is not a SELECT")));
- pstmt = (PlannedStmt *) linitial(plan_list);
- Assert(IsA(pstmt, PlannedStmt));
+ pstmt = castNode(PlannedStmt, linitial(plan_list));
if (pstmt->commandType != CMD_SELECT)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
/* Explain each query */
foreach(p, plan_list)
{
- PlannedStmt *pstmt = (PlannedStmt *) lfirst(p);
+ PlannedStmt *pstmt = castNode(PlannedStmt, lfirst(p));
- Assert(IsA(pstmt, PlannedStmt));
if (pstmt->commandType != CMD_UTILITY)
ExplainOnePlan(pstmt, into, es, query_string, paramLI, NULL);
else
querytree_list = NIL;
foreach(list_item, raw_parsetree_list)
{
- RawStmt *rs = (RawStmt *) lfirst(list_item);
+ RawStmt *rs = castNode(RawStmt, lfirst(list_item));
Node *stmt = rs->stmt;
if (IsA(stmt, IndexStmt))
flat_query_list = NIL;
foreach(lc, raw_parsetree_list)
{
- RawStmt *parsetree = (RawStmt *) lfirst(lc);
+ RawStmt *parsetree = castNode(RawStmt, lfirst(lc));
List *queryTree_sublist;
queryTree_sublist = pg_analyze_and_rewrite_params(parsetree,
parse = NULL;
foreach(lc, queryTreeList)
{
- Query *q = (Query *) lfirst(lc);
+ Query *q = castNode(Query, lfirst(lc));
if (q->canSetTag)
parse = q;
if (!(portal->cursorOptions & (CURSOR_OPT_SCROLL | CURSOR_OPT_NO_SCROLL)))
{
if (list_length(stmt_list) == 1 &&
- ((PlannedStmt *) linitial(stmt_list))->commandType != CMD_UTILITY &&
- ((PlannedStmt *) linitial(stmt_list))->rowMarks == NIL &&
- ExecSupportsBackwardScan(((PlannedStmt *) linitial(stmt_list))->planTree))
+ castNode(PlannedStmt, linitial(stmt_list))->commandType != CMD_UTILITY &&
+ castNode(PlannedStmt, linitial(stmt_list))->rowMarks == NIL &&
+ ExecSupportsBackwardScan(castNode(PlannedStmt, linitial(stmt_list))->planTree))
portal->cursorOptions |= CURSOR_OPT_SCROLL;
else
portal->cursorOptions |= CURSOR_OPT_NO_SCROLL;
if (portal->cursorOptions & CURSOR_OPT_SCROLL)
{
if (list_length(stmt_list) == 1 &&
- ((PlannedStmt *) linitial(stmt_list))->commandType != CMD_UTILITY &&
- ((PlannedStmt *) linitial(stmt_list))->rowMarks != NIL)
+ castNode(PlannedStmt, linitial(stmt_list))->commandType != CMD_UTILITY &&
+ castNode(PlannedStmt, linitial(stmt_list))->rowMarks != NIL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("DECLARE SCROLL CURSOR ... FOR UPDATE/SHARE is not supported"),
foreach(lc, stmt_list)
{
- PlannedStmt *pstmt = (PlannedStmt *) lfirst(lc);
+ PlannedStmt *pstmt = castNode(PlannedStmt, lfirst(lc));
if (!CommandIsReadOnly(pstmt))
{
foreach(list_item, raw_parsetree_list)
{
- RawStmt *parsetree = (RawStmt *) lfirst(list_item);
+ RawStmt *parsetree = castNode(RawStmt, lfirst(list_item));
List *stmt_list;
CachedPlanSource *plansource;
foreach(list_item, raw_parsetree_list)
{
- RawStmt *parsetree = (RawStmt *) lfirst(list_item);
+ RawStmt *parsetree = castNode(RawStmt, lfirst(list_item));
CachedPlanSource *plansource;
plansource = CreateOneShotCachedPlan(parsetree,
foreach(lc2, stmt_list)
{
- PlannedStmt *stmt = (PlannedStmt *) lfirst(lc2);
+ PlannedStmt *stmt = castNode(PlannedStmt, lfirst(lc2));
bool canSetTag = stmt->canSetTag;
DestReceiver *dest;
if ($1 != NIL)
{
/* update length of previous stmt */
- updateRawStmtEnd((RawStmt *) llast($1), @2);
+ updateRawStmtEnd(castNode(RawStmt, llast($1)), @2);
}
if ($3 != NULL)
$$ = lappend($1, makeRawStmt($3, @2 + 1));
sublink = (SubLink *) transformExprRecurse(pstate,
(Node *) sublink);
- qtree = (Query *) sublink->subselect;
- Assert(IsA(qtree, Query));
+ qtree = castNode(Query, sublink->subselect);
/* Check subquery returns required number of columns */
if (count_nonjunk_tlist_entries(qtree->targetList) != maref->ncolumns)
sublink = (SubLink *) tle->expr;
Assert(sublink->subLinkType == MULTIEXPR_SUBLINK);
- qtree = (Query *) sublink->subselect;
- Assert(IsA(qtree, Query));
+ qtree = castNode(Query, sublink->subselect);
/* Build a Param representing the current subquery output column */
tle = (TargetEntry *) list_nth(qtree->targetList, maref->colno - 1);
*/
if (list_length(raw_parsetree_list) != 1)
goto fail;
- stmt = (SelectStmt *) ((RawStmt *) linitial(raw_parsetree_list))->stmt;
+ stmt = (SelectStmt *) castNode(RawStmt, linitial(raw_parsetree_list))->stmt;
if (stmt == NULL ||
!IsA(stmt, SelectStmt) ||
stmt->distinctClause != NIL ||
if (event_qual != NULL)
{
/* Find query containing OLD/NEW rtable entries */
- Query *qry = (Query *) linitial(action);
+ Query *qry = castNode(Query, linitial(action));
qry = getInsertSelectQuery(qry, NULL);
recordDependencyOnExpr(&myself, event_qual, qry->rtable,
*/
foreach(l, action)
{
- query = (Query *) lfirst(l);
+ query = castNode(Query, lfirst(l));
if (query->resultRelation == 0)
continue;
/* Don't be fooled by INSERT/SELECT */
/*
* ... the one action must be a SELECT, ...
*/
- query = (Query *) linitial(action);
+ query = castNode(Query, linitial(action));
if (!is_instead ||
query->commandType != CMD_SELECT)
ereport(ERROR,
foreach(l, action)
{
- query = (Query *) lfirst(l);
+ query = castNode(Query, lfirst(l));
if (!query->returningList)
continue;
{
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 */
*/
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];
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.
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 (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;
{
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;
* 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,
break;
case PORTAL_UTIL_SELECT:
- PortalRunUtility(portal, (PlannedStmt *) linitial(portal->stmts),
+ PortalRunUtility(portal, castNode(PlannedStmt, linitial(portal->stmts)),
isTopLevel, true, treceiver, completionTag);
break;
*/
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
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;
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 */
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 */
foreach(lc, stmts)
{
- Query *stmt = (Query *) lfirst(lc);
-
- Assert(IsA(stmt, Query));
+ Query *stmt = castNode(Query, lfirst(lc));
if (stmt->canSetTag)
return stmt;
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)
{
/*
foreach(lc, stmt_list)
{
- Query *query = (Query *) lfirst(lc);
-
- Assert(IsA(query, Query));
+ Query *query = castNode(Query, lfirst(lc));
if (query->commandType == CMD_UTILITY)
{
/* 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);
}
/*
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 */
}
{
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:
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);
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 */
{
foreach(lc, plansource->gplan->stmt_list)
{
- PlannedStmt *plannedstmt = (PlannedStmt *) lfirst(lc);
+ PlannedStmt *plannedstmt = castNode(PlannedStmt, lfirst(lc));
ListCell *lc3;
if (plannedstmt->commandType == CMD_UTILITY)
*/
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))
{
foreach(lc, portal->stmts)
{
- PlannedStmt *stmt = (PlannedStmt *) lfirst(lc);
-
- Assert(IsA(stmt, PlannedStmt));
+ PlannedStmt *stmt = castNode(PlannedStmt, lfirst(lc));
if (stmt->canSetTag)
return stmt;
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->commandType == CMD_INSERT ||
*/
if (list_length(cplan->stmt_list) != 1)
return;
- stmt = (PlannedStmt *) linitial(cplan->stmt_list);
- Assert(IsA(stmt, PlannedStmt));
+ stmt = castNode(PlannedStmt, linitial(cplan->stmt_list));
/*
* 2. It must be a RESULT plan --> no scan's required