Make more use of castNode()

This commit is contained in:
Peter Eisentraut 2017-02-21 11:33:07 -05:00
parent 4e5ce3c1ae
commit 38d103763d
37 changed files with 121 additions and 222 deletions

View File

@ -1123,7 +1123,7 @@ ProcessCopyOptions(ParseState *pstate,
if (defel->arg && IsA(defel->arg, A_Star))
cstate->force_quote_all = true;
else if (defel->arg && IsA(defel->arg, List))
cstate->force_quote = (List *) defel->arg;
cstate->force_quote = castNode(List, defel->arg);
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),

View File

@ -111,8 +111,7 @@ exprType(const Node *expr)
if (!qtree || !IsA(qtree, Query))
elog(ERROR, "cannot get type for untransformed sublink");
tent = (TargetEntry *) linitial(qtree->targetList);
Assert(IsA(tent, TargetEntry));
tent = castNode(TargetEntry, linitial(qtree->targetList));
Assert(!tent->resjunk);
type = exprType((Node *) tent->expr);
if (sublink->subLinkType == ARRAY_SUBLINK)
@ -322,8 +321,7 @@ exprTypmod(const Node *expr)
if (!qtree || !IsA(qtree, Query))
elog(ERROR, "cannot get type for untransformed sublink");
tent = (TargetEntry *) linitial(qtree->targetList);
Assert(IsA(tent, TargetEntry));
tent = castNode(TargetEntry, linitial(qtree->targetList));
Assert(!tent->resjunk);
return exprTypmod((Node *) tent->expr);
/* note we don't need to care if it's an array */
@ -381,9 +379,8 @@ exprTypmod(const Node *expr)
return -1; /* no point in trying harder */
foreach(arg, cexpr->args)
{
CaseWhen *w = (CaseWhen *) lfirst(arg);
CaseWhen *w = castNode(CaseWhen, lfirst(arg));
Assert(IsA(w, CaseWhen));
if (exprType((Node *) w->result) != casetype)
return -1;
if (exprTypmod((Node *) w->result) != typmod)
@ -809,8 +806,7 @@ exprCollation(const Node *expr)
if (!qtree || !IsA(qtree, Query))
elog(ERROR, "cannot get collation for untransformed sublink");
tent = (TargetEntry *) linitial(qtree->targetList);
Assert(IsA(tent, TargetEntry));
tent = castNode(TargetEntry, linitial(qtree->targetList));
Assert(!tent->resjunk);
coll = exprCollation((Node *) tent->expr);
/* collation doesn't change if it's converted to array */
@ -1052,8 +1048,7 @@ exprSetCollation(Node *expr, Oid collation)
if (!qtree || !IsA(qtree, Query))
elog(ERROR, "cannot set collation for untransformed sublink");
tent = (TargetEntry *) linitial(qtree->targetList);
Assert(IsA(tent, TargetEntry));
tent = castNode(TargetEntry, linitial(qtree->targetList));
Assert(!tent->resjunk);
Assert(collation == exprCollation((Node *) tent->expr));
}
@ -2050,9 +2045,8 @@ expression_tree_walker(Node *node,
/* we assume walker doesn't care about CaseWhens, either */
foreach(temp, caseexpr->args)
{
CaseWhen *when = (CaseWhen *) lfirst(temp);
CaseWhen *when = castNode(CaseWhen, lfirst(temp));
Assert(IsA(when, CaseWhen));
if (walker(when->expr, context))
return true;
if (walker(when->result, context))
@ -3261,9 +3255,8 @@ raw_expression_tree_walker(Node *node,
/* we assume walker doesn't care about CaseWhens, either */
foreach(temp, caseexpr->args)
{
CaseWhen *when = (CaseWhen *) lfirst(temp);
CaseWhen *when = castNode(CaseWhen, lfirst(temp));
Assert(IsA(when, CaseWhen));
if (walker(when->expr, context))
return true;
if (walker(when->result, context))
@ -3735,9 +3728,8 @@ planstate_walk_subplans(List *plans,
foreach(lc, plans)
{
SubPlanState *sps = (SubPlanState *) lfirst(lc);
SubPlanState *sps = castNode(SubPlanState, lfirst(lc));
Assert(IsA(sps, SubPlanState));
if (walker(sps->planstate, context))
return true;
}

View File

@ -2382,8 +2382,8 @@ subquery_is_pushdown_safe(Query *subquery, Query *topquery,
if (subquery->setOperations != NULL)
return false;
/* Check whether setop component output types match top level */
topop = (SetOperationStmt *) topquery->setOperations;
Assert(topop && IsA(topop, SetOperationStmt));
topop = castNode(SetOperationStmt, topquery->setOperations);
Assert(topop);
compare_tlist_datatypes(subquery->targetList,
topop->colTypes,
safetyInfo);

View File

@ -682,9 +682,8 @@ extract_nonindex_conditions(List *qual_clauses, List *indexquals)
foreach(lc, qual_clauses)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
Assert(IsA(rinfo, RestrictInfo));
if (rinfo->pseudoconstant)
continue; /* we may drop pseudoconstants here */
if (list_member_ptr(indexquals, rinfo))
@ -1804,12 +1803,10 @@ cost_windowagg(Path *path, PlannerInfo *root,
*/
foreach(lc, windowFuncs)
{
WindowFunc *wfunc = (WindowFunc *) lfirst(lc);
WindowFunc *wfunc = castNode(WindowFunc, lfirst(lc));
Cost wfunccost;
QualCost argcosts;
Assert(IsA(wfunc, WindowFunc));
wfunccost = get_func_cost(wfunc->winfnoid) * cpu_operator_cost;
/* also add the input expressions' cost to per-input-row costs */
@ -2843,11 +2840,9 @@ final_cost_hashjoin(PlannerInfo *root, HashPath *path,
innerbucketsize = 1.0;
foreach(hcl, hashclauses)
{
RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(hcl);
RestrictInfo *restrictinfo = castNode(RestrictInfo, lfirst(hcl));
Selectivity thisbucketsize;
Assert(IsA(restrictinfo, RestrictInfo));
/*
* First we have to figure out which side of the hashjoin clause
* is the inner side.
@ -3537,9 +3532,8 @@ compute_semi_anti_join_factors(PlannerInfo *root,
joinquals = NIL;
foreach(l, restrictlist)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Assert(IsA(rinfo, RestrictInfo));
if (!rinfo->is_pushed_down)
joinquals = lappend(joinquals, rinfo);
}
@ -3970,9 +3964,8 @@ calc_joinrel_size_estimate(PlannerInfo *root,
/* Grovel through the clauses to separate into two lists */
foreach(l, restrictlist)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Assert(IsA(rinfo, RestrictInfo));
if (rinfo->is_pushed_down)
pushedquals = lappend(pushedquals, rinfo);
else
@ -4345,11 +4338,10 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
*/
foreach(lc, subroot->parse->targetList)
{
TargetEntry *te = (TargetEntry *) lfirst(lc);
TargetEntry *te = castNode(TargetEntry, lfirst(lc));
Node *texpr = (Node *) te->expr;
int32 item_width = 0;
Assert(IsA(te, TargetEntry));
/* junk columns aren't visible to upper query */
if (te->resjunk)
continue;

View File

@ -1273,12 +1273,11 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
foreach(lc, clauses)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
List *pathlist;
Path *bitmapqual;
ListCell *j;
Assert(IsA(rinfo, RestrictInfo));
/* Ignore RestrictInfos that aren't ORs */
if (!restriction_is_or_clause(rinfo))
continue;
@ -1310,10 +1309,10 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
}
else
{
RestrictInfo *rinfo = castNode(RestrictInfo, orarg);
List *orargs;
Assert(IsA(orarg, RestrictInfo));
Assert(!restriction_is_or_clause((RestrictInfo *) orarg));
Assert(!restriction_is_or_clause(rinfo));
orargs = list_make1(orarg);
indlist = build_paths_for_OR(root, rel,
@ -2174,9 +2173,8 @@ match_clauses_to_index(IndexOptInfo *index,
foreach(lc, clauses)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
Assert(IsA(rinfo, RestrictInfo));
match_clause_to_index(index, rinfo, clauseset);
}
}

View File

@ -1230,9 +1230,8 @@ restriction_is_constant_false(List *restrictlist, bool only_pushed_down)
*/
foreach(lc, restrictlist)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
Assert(IsA(rinfo, RestrictInfo));
if (only_pushed_down && !rinfo->is_pushed_down)
continue;

View File

@ -596,7 +596,7 @@ rel_is_distinct_for(PlannerInfo *root, RelOptInfo *rel, List *clause_list)
*/
foreach(l, clause_list)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Oid op;
Var *var;
@ -608,8 +608,7 @@ rel_is_distinct_for(PlannerInfo *root, RelOptInfo *rel, List *clause_list)
* caller's mergejoinability test should have selected only
* OpExprs.
*/
Assert(IsA(rinfo->clause, OpExpr));
op = ((OpExpr *) rinfo->clause)->opno;
op = castNode(OpExpr, rinfo->clause)->opno;
/* caller identified the inner side for us */
if (rinfo->outer_is_left)
@ -782,9 +781,8 @@ query_is_distinct_for(Query *query, List *colnos, List *opids)
*/
if (query->setOperations)
{
SetOperationStmt *topop = (SetOperationStmt *) query->setOperations;
SetOperationStmt *topop = castNode(SetOperationStmt, query->setOperations);
Assert(IsA(topop, SetOperationStmt));
Assert(topop->op != SETOP_NONE);
if (!topop->all)

View File

@ -508,8 +508,7 @@ create_scan_plan(PlannerInfo *root, Path *best_path, int flags)
{
case T_IndexScan:
case T_IndexOnlyScan:
Assert(IsA(best_path, IndexPath));
scan_clauses = ((IndexPath *) best_path)->indexinfo->indrestrictinfo;
scan_clauses = castNode(IndexPath, best_path)->indexinfo->indrestrictinfo;
break;
default:
scan_clauses = rel->baserestrictinfo;
@ -2450,9 +2449,8 @@ create_indexscan_plan(PlannerInfo *root,
qpqual = NIL;
foreach(l, scan_clauses)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Assert(IsA(rinfo, RestrictInfo));
if (rinfo->pseudoconstant)
continue; /* we may drop pseudoconstants here */
if (list_member_ptr(indexquals, rinfo))
@ -2608,10 +2606,9 @@ create_bitmap_scan_plan(PlannerInfo *root,
qpqual = NIL;
foreach(l, scan_clauses)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Node *clause = (Node *) rinfo->clause;
Assert(IsA(rinfo, RestrictInfo));
if (rinfo->pseudoconstant)
continue; /* we may drop pseudoconstants here */
if (list_member(indexquals, clause))
@ -2820,9 +2817,9 @@ create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,
ListCell *l;
/* Use the regular indexscan plan build machinery... */
iscan = (IndexScan *) create_indexscan_plan(root, ipath,
NIL, NIL, false);
Assert(IsA(iscan, IndexScan));
iscan = castNode(IndexScan,
create_indexscan_plan(root, ipath,
NIL, NIL, false));
/* then convert to a bitmap indexscan */
plan = (Plan *) make_bitmap_indexscan(iscan->scan.scanrelid,
iscan->indexid,
@ -3391,13 +3388,13 @@ create_customscan_plan(PlannerInfo *root, CustomPath *best_path,
* Invoke custom plan provider to create the Plan node represented by the
* CustomPath.
*/
cplan = (CustomScan *) best_path->methods->PlanCustomPath(root,
rel,
best_path,
tlist,
scan_clauses,
custom_plans);
Assert(IsA(cplan, CustomScan));
cplan = castNode(CustomScan,
best_path->methods->PlanCustomPath(root,
rel,
best_path,
tlist,
scan_clauses,
custom_plans));
/*
* Copy cost data from Path to Plan; no need to make custom-plan providers
@ -3683,7 +3680,7 @@ create_mergejoin_plan(PlannerInfo *root,
i = 0;
foreach(lc, best_path->path_mergeclauses)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc));
EquivalenceClass *oeclass;
EquivalenceClass *ieclass;
PathKey *opathkey;
@ -3693,7 +3690,6 @@ create_mergejoin_plan(PlannerInfo *root,
ListCell *l2;
/* fetch outer/inner eclass from mergeclause */
Assert(IsA(rinfo, RestrictInfo));
if (rinfo->outer_is_left)
{
oeclass = rinfo->left_ec;
@ -4228,12 +4224,10 @@ fix_indexqual_references(PlannerInfo *root, IndexPath *index_path)
forboth(lcc, index_path->indexquals, lci, index_path->indexqualcols)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lcc);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lcc));
int indexcol = lfirst_int(lci);
Node *clause;
Assert(IsA(rinfo, RestrictInfo));
/*
* Replace any outer-relation variables with nestloop params.
*

View File

@ -3963,9 +3963,8 @@ create_one_window_path(PlannerInfo *root,
window_target = copy_pathtarget(window_target);
foreach(lc2, wflists->windowFuncs[wc->winref])
{
WindowFunc *wfunc = (WindowFunc *) lfirst(lc2);
WindowFunc *wfunc = castNode(WindowFunc, lfirst(lc2));
Assert(IsA(wfunc, WindowFunc));
add_column_to_pathtarget(window_target, (Expr *) wfunc, 0);
window_target->width += get_typavgwidth(wfunc->wintype, -1);
}

View File

@ -224,11 +224,9 @@ set_plan_references(PlannerInfo *root, Plan *plan)
*/
foreach(lc, root->rowMarks)
{
PlanRowMark *rc = (PlanRowMark *) lfirst(lc);
PlanRowMark *rc = castNode(PlanRowMark, lfirst(lc));
PlanRowMark *newrc;
Assert(IsA(rc, PlanRowMark));
/* flat copy is enough since all fields are scalars */
newrc = (PlanRowMark *) palloc(sizeof(PlanRowMark));
memcpy(newrc, rc, sizeof(PlanRowMark));

View File

@ -433,9 +433,8 @@ get_first_col_type(Plan *plan, Oid *coltype, int32 *coltypmod,
/* In cases such as EXISTS, tlist might be empty; arbitrarily use VOID */
if (plan->targetlist)
{
TargetEntry *tent = (TargetEntry *) linitial(plan->targetlist);
TargetEntry *tent = castNode(TargetEntry, linitial(plan->targetlist));
Assert(IsA(tent, TargetEntry));
if (!tent->resjunk)
{
*coltype = exprType((Node *) tent->expr);
@ -601,14 +600,14 @@ make_subplan(PlannerInfo *root, Query *orig_subquery,
AlternativeSubPlan *asplan;
/* OK, convert to SubPlan format. */
hashplan = (SubPlan *) build_subplan(root, plan, subroot,
plan_params,
ANY_SUBLINK, 0,
newtestexpr,
false, true,
best_path->parallel_safe);
hashplan = castNode(SubPlan,
build_subplan(root, plan, subroot,
plan_params,
ANY_SUBLINK, 0,
newtestexpr,
false, true,
best_path->parallel_safe));
/* Check we got what we expected */
Assert(IsA(hashplan, SubPlan));
Assert(hashplan->parParam == NIL);
Assert(hashplan->useHashTable);
/* build_subplan won't have filled in paramIds */

View File

@ -1748,10 +1748,9 @@ is_simple_union_all(Query *subquery)
elog(ERROR, "subquery is bogus");
/* Is it a set-operation query at all? */
topop = (SetOperationStmt *) subquery->setOperations;
topop = castNode(SetOperationStmt, subquery->setOperations);
if (!topop)
return false;
Assert(IsA(topop, SetOperationStmt));
/* Can't handle ORDER BY, LIMIT/OFFSET, locking, or WITH */
if (subquery->sortClause ||
@ -2323,8 +2322,8 @@ flatten_simple_union_all(PlannerInfo *root)
RangeTblRef *rtr;
/* Shouldn't be called unless query has setops */
topop = (SetOperationStmt *) parse->setOperations;
Assert(topop && IsA(topop, SetOperationStmt));
topop = castNode(SetOperationStmt, parse->setOperations);
Assert(topop);
/* Can't optimize away a recursive UNION */
if (root->hasRecursion)

View File

@ -129,7 +129,7 @@ RelOptInfo *
plan_set_operations(PlannerInfo *root)
{
Query *parse = root->parse;
SetOperationStmt *topop = (SetOperationStmt *) parse->setOperations;
SetOperationStmt *topop = castNode(SetOperationStmt, parse->setOperations);
Node *node;
RangeTblEntry *leftmostRTE;
Query *leftmostQuery;
@ -137,7 +137,7 @@ plan_set_operations(PlannerInfo *root)
Path *path;
List *top_tlist;
Assert(topop && IsA(topop, SetOperationStmt));
Assert(topop);
/* check for unsupported stuff */
Assert(parse->jointree->fromlist == NIL);
@ -1701,12 +1701,11 @@ translate_col_privs(const Bitmapset *parent_privs,
attno = InvalidAttrNumber;
foreach(lc, translated_vars)
{
Var *var = (Var *) lfirst(lc);
Var *var = castNode(Var, lfirst(lc));
attno++;
if (var == NULL) /* ignore dropped columns */
continue;
Assert(IsA(var, Var));
if (whole_row ||
bms_is_member(attno - FirstLowInvalidHeapAttributeNumber,
parent_privs))

View File

@ -2700,9 +2700,8 @@ eval_const_expressions_mutator(Node *node,
* Since the underlying operator is "=", must negate
* its result
*/
Const *csimple = (Const *) simple;
Const *csimple = castNode(Const, simple);
Assert(IsA(csimple, Const));
csimple->constvalue =
BoolGetDatum(!DatumGetBool(csimple->constvalue));
return (Node *) csimple;
@ -3091,12 +3090,10 @@ eval_const_expressions_mutator(Node *node,
const_true_cond = false;
foreach(arg, caseexpr->args)
{
CaseWhen *oldcasewhen = (CaseWhen *) lfirst(arg);
CaseWhen *oldcasewhen = castNode(CaseWhen, lfirst(arg));
Node *casecond;
Node *caseresult;
Assert(IsA(oldcasewhen, CaseWhen));
/* Simplify this alternative's test condition */
casecond = eval_const_expressions_mutator((Node *) oldcasewhen->expr,
context);
@ -4081,8 +4078,7 @@ fetch_function_defaults(HeapTuple func_tuple)
if (isnull)
elog(ERROR, "not enough default arguments");
str = TextDatumGetCString(proargdefaults);
defaults = (List *) stringToNode(str);
Assert(IsA(defaults, List));
defaults = castNode(List, stringToNode(str));
pfree(str);
return defaults;
}

View File

@ -188,9 +188,8 @@ extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel)
foreach(lc2, andargs)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc2);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lc2));
Assert(IsA(rinfo, RestrictInfo));
if (restriction_is_or_clause(rinfo))
{
/*
@ -211,11 +210,11 @@ extract_or_clause(RestrictInfo *or_rinfo, RelOptInfo *rel)
}
else
{
Assert(IsA(orarg, RestrictInfo));
Assert(!restriction_is_or_clause((RestrictInfo *) orarg));
if (is_safe_restriction_clause_for((RestrictInfo *) orarg, rel))
subclauses = lappend(subclauses,
((RestrictInfo *) orarg)->clause);
RestrictInfo *rinfo = castNode(RestrictInfo, orarg);
Assert(!restriction_is_or_clause(rinfo));
if (is_safe_restriction_clause_for(rinfo, rel))
subclauses = lappend(subclauses, rinfo->clause);
}
/*

View File

@ -335,9 +335,7 @@ get_actual_clauses(List *restrictinfo_list)
foreach(l, restrictinfo_list)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
Assert(IsA(rinfo, RestrictInfo));
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
Assert(!rinfo->pseudoconstant);
@ -361,9 +359,7 @@ extract_actual_clauses(List *restrictinfo_list,
foreach(l, restrictinfo_list)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
Assert(IsA(rinfo, RestrictInfo));
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
if (rinfo->pseudoconstant == pseudoconstant)
result = lappend(result, rinfo->clause);
@ -393,9 +389,7 @@ extract_actual_join_clauses(List *restrictinfo_list,
foreach(l, restrictinfo_list)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
Assert(IsA(rinfo, RestrictInfo));
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(l));
if (rinfo->is_pushed_down)
{

View File

@ -824,8 +824,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
AttrNumber attr_num;
TargetEntry *tle;
col = (ResTarget *) lfirst(icols);
Assert(IsA(col, ResTarget));
col = castNode(ResTarget, lfirst(icols));
attr_num = (AttrNumber) lfirst_int(attnos);
tle = makeTargetEntry(expr,
@ -950,8 +949,7 @@ transformInsertRow(ParseState *pstate, List *exprlist,
Expr *expr = (Expr *) lfirst(lc);
ResTarget *col;
col = (ResTarget *) lfirst(icols);
Assert(IsA(col, ResTarget));
col = castNode(ResTarget, lfirst(icols));
expr = transformAssignedExpr(pstate, expr,
EXPR_KIND_INSERT_TARGET,
@ -1633,10 +1631,9 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
/*
* Recursively transform the components of the tree.
*/
sostmt = (SetOperationStmt *) transformSetOperationTree(pstate, stmt,
true,
NULL);
Assert(sostmt && IsA(sostmt, SetOperationStmt));
sostmt = castNode(SetOperationStmt,
transformSetOperationTree(pstate, stmt, true, NULL));
Assert(sostmt);
qry->setOperations = (Node *) sostmt;
/*
@ -2298,8 +2295,7 @@ transformUpdateTargetList(ParseState *pstate, List *origTlist)
}
if (orig_tl == NULL)
elog(ERROR, "UPDATE target count mismatch --- internal error");
origTarget = (ResTarget *) lfirst(orig_tl);
Assert(IsA(origTarget, ResTarget));
origTarget = castNode(ResTarget, lfirst(orig_tl));
attrno = attnameAttNum(pstate->p_target_relation,
origTarget->name, true);

View File

@ -3249,8 +3249,7 @@ ColQualList:
ColConstraint:
CONSTRAINT name ColConstraintElem
{
Constraint *n = (Constraint *) $3;
Assert(IsA(n, Constraint));
Constraint *n = castNode(Constraint, $3);
n->conname = $2;
n->location = @1;
$$ = (Node *) n;
@ -3442,8 +3441,7 @@ TableLikeOption:
TableConstraint:
CONSTRAINT name ConstraintElem
{
Constraint *n = (Constraint *) $3;
Assert(IsA(n, Constraint));
Constraint *n = castNode(Constraint, $3);
n->conname = $2;
n->location = @1;
$$ = (Node *) n;
@ -12845,8 +12843,7 @@ c_expr: columnref { $$ = $1; }
}
| ARRAY array_expr
{
A_ArrayExpr *n = (A_ArrayExpr *) $2;
Assert(IsA(n, A_ArrayExpr));
A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
/* point outermost A_ArrayExpr to the ARRAY keyword */
n->location = @1;
$$ = (Node *)n;

View File

@ -903,8 +903,7 @@ transformFromClauseItem(ParseState *pstate, Node *n,
rel = transformFromClauseItem(pstate, rts->relation,
top_rte, top_rti, namespace);
/* Currently, grammar could only return a RangeVar as contained rel */
Assert(IsA(rel, RangeTblRef));
rtr = (RangeTblRef *) rel;
rtr = castNode(RangeTblRef, rel);
rte = rt_fetch(rtr->rtindex, pstate->p_rtable);
/* We only support this on plain relations and matviews */
if (rte->relkind != RELKIND_RELATION &&

View File

@ -514,8 +514,7 @@ assign_collations_walker(Node *node, assign_collations_context *context)
if (qtree->targetList == NIL)
return false;
tent = (TargetEntry *) linitial(qtree->targetList);
Assert(IsA(tent, TargetEntry));
tent = castNode(TargetEntry, linitial(qtree->targetList));
if (tent->resjunk)
return false;
@ -650,9 +649,7 @@ assign_collations_walker(Node *node, assign_collations_context *context)
foreach(lc, expr->args)
{
CaseWhen *when = (CaseWhen *) lfirst(lc);
Assert(IsA(when, CaseWhen));
CaseWhen *when = castNode(CaseWhen, lfirst(lc));
/*
* The condition expressions mustn't affect
@ -868,9 +865,8 @@ assign_aggregate_collations(Aggref *aggref,
/* Process aggregated args, holding resjunk ones at arm's length */
foreach(lc, aggref->args)
{
TargetEntry *tle = (TargetEntry *) lfirst(lc);
TargetEntry *tle = castNode(TargetEntry, lfirst(lc));
Assert(IsA(tle, TargetEntry));
if (tle->resjunk)
assign_expr_collations(loccontext->pstate, (Node *) tle);
else
@ -913,9 +909,8 @@ assign_ordered_set_collations(Aggref *aggref,
/* Process aggregated args appropriately */
foreach(lc, aggref->args)
{
TargetEntry *tle = (TargetEntry *) lfirst(lc);
TargetEntry *tle = castNode(TargetEntry, lfirst(lc));
Assert(IsA(tle, TargetEntry));
if (merge_sort_collations)
(void) assign_collations_walker((Node *) tle, loccontext);
else

View File

@ -917,13 +917,11 @@ transformAExprOp(ParseState *pstate, A_Expr *a)
/* ROW() op ROW() is handled specially */
lexpr = transformExprRecurse(pstate, lexpr);
rexpr = transformExprRecurse(pstate, rexpr);
Assert(IsA(lexpr, RowExpr));
Assert(IsA(rexpr, RowExpr));
result = make_row_comparison_op(pstate,
a->name,
((RowExpr *) lexpr)->args,
((RowExpr *) rexpr)->args,
castNode(RowExpr, lexpr)->args,
castNode(RowExpr, rexpr)->args,
a->location);
}
else
@ -1296,8 +1294,7 @@ transformAExprBetween(ParseState *pstate, A_Expr *a)
/* Deconstruct A_Expr into three subexprs */
aexpr = a->lexpr;
Assert(IsA(a->rexpr, List));
args = (List *) a->rexpr;
args = castNode(List, a->rexpr);
Assert(list_length(args) == 2);
bexpr = (Node *) linitial(args);
cexpr = (Node *) lsecond(args);
@ -1672,12 +1669,10 @@ transformCaseExpr(ParseState *pstate, CaseExpr *c)
resultexprs = NIL;
foreach(l, c->args)
{
CaseWhen *w = (CaseWhen *) lfirst(l);
CaseWhen *w = castNode(CaseWhen, lfirst(l));
CaseWhen *neww = makeNode(CaseWhen);
Node *warg;
Assert(IsA(w, CaseWhen));
warg = (Node *) w->expr;
if (placeholder)
{
@ -2339,12 +2334,10 @@ transformXmlExpr(ParseState *pstate, XmlExpr *x)
foreach(lc, x->named_args)
{
ResTarget *r = (ResTarget *) lfirst(lc);
ResTarget *r = castNode(ResTarget, lfirst(lc));
Node *expr;
char *argname;
Assert(IsA(r, ResTarget));
expr = transformExprRecurse(pstate, r->val);
if (r->name)
@ -2800,8 +2793,7 @@ make_row_comparison_op(ParseState *pstate, List *opname,
Node *rarg = (Node *) lfirst(r);
OpExpr *cmp;
cmp = (OpExpr *) make_op(pstate, opname, larg, rarg, location);
Assert(IsA(cmp, OpExpr));
cmp = castNode(OpExpr, make_op(pstate, opname, larg, rarg, location));
/*
* We don't use coerce_to_boolean here because we insist on the

View File

@ -1515,8 +1515,7 @@ func_get_detail(List *funcname,
&isnull);
Assert(!isnull);
str = TextDatumGetCString(proargdefaults);
defaults = (List *) stringToNode(str);
Assert(IsA(defaults, List));
defaults = castNode(List, stringToNode(str));
pfree(str);
/* Delete any unused defaults from the returned list */

View File

@ -335,10 +335,9 @@ transformArraySubscripts(ParseState *pstate,
*/
foreach(idx, indirection)
{
A_Indices *ai = (A_Indices *) lfirst(idx);
A_Indices *ai = castNode(A_Indices, lfirst(idx));
Node *subexpr;
Assert(IsA(ai, A_Indices));
if (isSlice)
{
if (ai->lidx)

View File

@ -910,12 +910,11 @@ markRTEForSelectPriv(ParseState *pstate, RangeTblEntry *rte,
JoinExpr *j;
if (rtindex > 0 && rtindex <= list_length(pstate->p_joinexprs))
j = (JoinExpr *) list_nth(pstate->p_joinexprs, rtindex - 1);
j = castNode(JoinExpr, list_nth(pstate->p_joinexprs, rtindex - 1));
else
j = NULL;
if (j == NULL)
elog(ERROR, "could not find JoinExpr for whole-row reference");
Assert(IsA(j, JoinExpr));
/* Note: we can't see FromExpr here */
if (IsA(j->larg, RangeTblRef))

View File

@ -478,9 +478,8 @@ TypeNameListToString(List *typenames)
initStringInfo(&string);
foreach(l, typenames)
{
TypeName *typeName = (TypeName *) lfirst(l);
TypeName *typeName = castNode(TypeName, lfirst(l));
Assert(IsA(typeName, TypeName));
if (l != list_head(typenames))
appendStringInfoChar(&string, ',');
appendTypeNameToBuffer(typeName, &string);

View File

@ -543,8 +543,7 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
foreach(clist, column->constraints)
{
constraint = lfirst(clist);
Assert(IsA(constraint, Constraint));
constraint = castNode(Constraint, lfirst(clist));
switch (constraint->contype)
{
@ -1520,9 +1519,8 @@ transformIndexConstraints(CreateStmtContext *cxt)
*/
foreach(lc, cxt->ixconstraints)
{
Constraint *constraint = (Constraint *) lfirst(lc);
Constraint *constraint = castNode(Constraint, lfirst(lc));
Assert(IsA(constraint, Constraint));
Assert(constraint->contype == CONSTR_PRIMARY ||
constraint->contype == CONSTR_UNIQUE ||
constraint->contype == CONSTR_EXCLUSION);
@ -1842,10 +1840,8 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
List *opname;
Assert(list_length(pair) == 2);
elem = (IndexElem *) linitial(pair);
Assert(IsA(elem, IndexElem));
opname = (List *) lsecond(pair);
Assert(IsA(opname, List));
elem = castNode(IndexElem, linitial(pair));
opname = castNode(List, lsecond(pair));
index->indexParams = lappend(index->indexParams, elem);
index->excludeOpNames = lappend(index->excludeOpNames, opname);
@ -1872,8 +1868,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
foreach(columns, cxt->columns)
{
column = (ColumnDef *) lfirst(columns);
Assert(IsA(column, ColumnDef));
column = castNode(ColumnDef, lfirst(columns));
if (strcmp(column->colname, key) == 0)
{
found = true;
@ -1902,11 +1897,10 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
foreach(inher, cxt->inhRelations)
{
RangeVar *inh = (RangeVar *) lfirst(inher);
RangeVar *inh = castNode(RangeVar, lfirst(inher));
Relation rel;
int count;
Assert(IsA(inh, RangeVar));
rel = heap_openrv(inh, AccessShareLock);
/* check user requested inheritance from valid relkind */
if (rel->rd_rel->relkind != RELKIND_RELATION &&
@ -2586,9 +2580,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
case AT_AddColumn:
case AT_AddColumnToView:
{
ColumnDef *def = (ColumnDef *) cmd->def;
ColumnDef *def = castNode(ColumnDef, cmd->def);
Assert(IsA(def, ColumnDef));
transformColumnDefinition(&cxt, def);
/*
@ -2693,9 +2686,8 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
*/
foreach(l, cxt.alist)
{
IndexStmt *idxstmt = (IndexStmt *) lfirst(l);
IndexStmt *idxstmt = castNode(IndexStmt, lfirst(l));
Assert(IsA(idxstmt, IndexStmt));
idxstmt = transformIndexStmt(relid, idxstmt, queryString);
newcmd = makeNode(AlterTableCmd);
newcmd->subtype = OidIsValid(idxstmt->indexOid) ? AT_AddIndexConstraint : AT_AddIndex;

View File

@ -2320,8 +2320,7 @@ view_cols_are_auto_updatable(Query *viewquery,
* there should be a single base relation.
*/
Assert(list_length(viewquery->jointree->fromlist) == 1);
rtr = (RangeTblRef *) linitial(viewquery->jointree->fromlist);
Assert(IsA(rtr, RangeTblRef));
rtr = castNode(RangeTblRef, linitial(viewquery->jointree->fromlist));
/* Initialize the optional return values */
if (updatable_cols != NULL)
@ -2578,8 +2577,7 @@ adjust_view_column_set(Bitmapset *cols, List *targetlist)
if (tle->resjunk)
continue;
var = (Var *) tle->expr;
Assert(IsA(var, Var));
var = castNode(Var, tle->expr);
result = bms_add_member(result,
var->varattno - FirstLowInvalidHeapAttributeNumber);
}
@ -2761,8 +2759,7 @@ rewriteTargetView(Query *parsetree, Relation view)
* view contains a single base relation.
*/
Assert(list_length(viewquery->jointree->fromlist) == 1);
rtr = (RangeTblRef *) linitial(viewquery->jointree->fromlist);
Assert(IsA(rtr, RangeTblRef));
rtr = castNode(RangeTblRef, linitial(viewquery->jointree->fromlist));
base_rt_index = rtr->rtindex;
base_rte = rt_fetch(base_rt_index, viewquery->rtable);
@ -3119,11 +3116,9 @@ RewriteQuery(Query *parsetree, List *rewrite_events)
foreach(lc1, parsetree->cteList)
{
CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc1);
Query *ctequery = (Query *) cte->ctequery;
Query *ctequery = castNode(Query, cte->ctequery);
List *newstuff;
Assert(IsA(ctequery, Query));
if (ctequery->commandType == CMD_SELECT)
continue;
@ -3137,8 +3132,7 @@ RewriteQuery(Query *parsetree, List *rewrite_events)
if (list_length(newstuff) == 1)
{
/* Push the single Query back into the CTE node */
ctequery = (Query *) linitial(newstuff);
Assert(IsA(ctequery, Query));
ctequery = castNode(Query, linitial(newstuff));
/* WITH queries should never be canSetTag */
Assert(!ctequery->canSetTag);
cte->ctequery = (Node *) ctequery;

View File

@ -4591,11 +4591,10 @@ CheckDateTokenTables(void)
Node *
TemporalTransform(int32 max_precis, Node *node)
{
FuncExpr *expr = (FuncExpr *) node;
FuncExpr *expr = castNode(FuncExpr, node);
Node *ret = NULL;
Node *typmod;
Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);

View File

@ -889,11 +889,10 @@ numeric_send(PG_FUNCTION_ARGS)
Datum
numeric_transform(PG_FUNCTION_ARGS)
{
FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
FuncExpr *expr = castNode(FuncExpr, PG_GETARG_POINTER(0));
Node *ret = NULL;
Node *typmod;
Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);

View File

@ -2569,8 +2569,7 @@ print_function_arguments(StringInfo buf, HeapTuple proctup,
List *argdefaults;
str = TextDatumGetCString(proargdefaults);
argdefaults = (List *) stringToNode(str);
Assert(IsA(argdefaults, List));
argdefaults = castNode(List, stringToNode(str));
pfree(str);
nextargdefault = list_head(argdefaults);
/* nlackdefaults counts only *input* arguments lacking defaults */
@ -2762,8 +2761,7 @@ pg_get_function_arg_default(PG_FUNCTION_ARGS)
}
str = TextDatumGetCString(proargdefaults);
argdefaults = (List *) stringToNode(str);
Assert(IsA(argdefaults, List));
argdefaults = castNode(List, stringToNode(str));
pfree(str);
proc = (Form_pg_proc) GETSTRUCT(proctup);
@ -7654,9 +7652,8 @@ get_rule_expr(Node *node, deparse_context *context,
appendStringInfoString(buf, "(alternatives: ");
foreach(lc, asplan->subplans)
{
SubPlan *splan = (SubPlan *) lfirst(lc);
SubPlan *splan = castNode(SubPlan, lfirst(lc));
Assert(IsA(splan, SubPlan));
if (splan->useHashTable)
appendStringInfo(buf, "hashed %s", splan->plan_name);
else
@ -8210,8 +8207,7 @@ get_rule_expr(Node *node, deparse_context *context,
get_rule_expr((Node *) linitial(xexpr->args),
context, true);
con = (Const *) lsecond(xexpr->args);
Assert(IsA(con, Const));
con = castNode(Const, lsecond(xexpr->args));
Assert(!con->constisnull);
if (DatumGetBool(con->constvalue))
appendStringInfoString(buf,
@ -8234,8 +8230,7 @@ get_rule_expr(Node *node, deparse_context *context,
else
get_rule_expr((Node *) con, context, false);
con = (Const *) lthird(xexpr->args);
Assert(IsA(con, Const));
con = castNode(Const, lthird(xexpr->args));
if (con->constisnull)
/* suppress STANDALONE NO VALUE */ ;
else
@ -8743,10 +8738,9 @@ get_agg_expr(Aggref *aggref, deparse_context *context,
*/
if (DO_AGGSPLIT_COMBINE(aggref->aggsplit))
{
TargetEntry *tle = linitial(aggref->args);
TargetEntry *tle = castNode(TargetEntry, linitial(aggref->args));
Assert(list_length(aggref->args) == 1);
Assert(IsA(tle, TargetEntry));
resolve_special_varno((Node *) tle->expr, context, original_aggref,
get_agg_combine_expr);
return;
@ -9205,9 +9199,8 @@ get_sublink_expr(SubLink *sublink, deparse_context *context)
sep = "";
foreach(l, ((BoolExpr *) sublink->testexpr)->args)
{
OpExpr *opexpr = (OpExpr *) lfirst(l);
OpExpr *opexpr = castNode(OpExpr, lfirst(l));
Assert(IsA(opexpr, OpExpr));
appendStringInfoString(buf, sep);
get_rule_expr(linitial(opexpr->args), context, true);
if (!opname)

View File

@ -6087,14 +6087,13 @@ deconstruct_indexquals(IndexPath *path)
forboth(lcc, path->indexquals, lci, path->indexqualcols)
{
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lcc);
RestrictInfo *rinfo = castNode(RestrictInfo, lfirst(lcc));
int indexcol = lfirst_int(lci);
Expr *clause;
Node *leftop,
*rightop;
IndexQualInfo *qinfo;
Assert(IsA(rinfo, RestrictInfo));
clause = rinfo->clause;
qinfo = (IndexQualInfo *) palloc(sizeof(IndexQualInfo));

View File

@ -1309,11 +1309,10 @@ intervaltypmodleastfield(int32 typmod)
Datum
interval_transform(PG_FUNCTION_ARGS)
{
FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
FuncExpr *expr = castNode(FuncExpr, PG_GETARG_POINTER(0));
Node *ret = NULL;
Node *typmod;
Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);

View File

@ -679,11 +679,10 @@ varbit_send(PG_FUNCTION_ARGS)
Datum
varbit_transform(PG_FUNCTION_ARGS)
{
FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
FuncExpr *expr = castNode(FuncExpr, PG_GETARG_POINTER(0));
Node *ret = NULL;
Node *typmod;
Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);

View File

@ -554,11 +554,10 @@ varcharsend(PG_FUNCTION_ARGS)
Datum
varchar_transform(PG_FUNCTION_ARGS)
{
FuncExpr *expr = (FuncExpr *) PG_GETARG_POINTER(0);
FuncExpr *expr = castNode(FuncExpr, PG_GETARG_POINTER(0));
Node *ret = NULL;
Node *typmod;
Assert(IsA(expr, FuncExpr));
Assert(list_length(expr->args) >= 2);
typmod = (Node *) lsecond(expr->args);

View File

@ -7322,7 +7322,7 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
}
else if (strcmp(stmt->name, "TRANSACTION SNAPSHOT") == 0)
{
A_Const *con = (A_Const *) linitial(stmt->args);
A_Const *con = castNode(A_Const, linitial(stmt->args));
if (stmt->is_local)
ereport(ERROR,
@ -7330,7 +7330,6 @@ ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
WarnNoTransactionChain(isTopLevel, "SET TRANSACTION");
Assert(IsA(con, A_Const));
Assert(nodeTag(&con->val) == T_String);
ImportSnapshot(strVal(&con->val));
}

View File

@ -288,7 +288,7 @@ PG_FUNCTION_INFO_V1(plpgsql_inline_handler);
Datum
plpgsql_inline_handler(PG_FUNCTION_ARGS)
{
InlineCodeBlock *codeblock = (InlineCodeBlock *) DatumGetPointer(PG_GETARG_DATUM(0));
InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0)));
PLpgSQL_function *func;
FunctionCallInfoData fake_fcinfo;
FmgrInfo flinfo;
@ -296,8 +296,6 @@ plpgsql_inline_handler(PG_FUNCTION_ARGS)
Datum retval;
int rc;
Assert(IsA(codeblock, InlineCodeBlock));
/*
* Connect to SPI manager
*/

View File

@ -94,11 +94,9 @@ get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
foreach(cell, cmd->d.alterTable.subcmds)
{
CollectedATSubcmd *sub = lfirst(cell);
AlterTableCmd *subcmd = (AlterTableCmd *) sub->parsetree;
AlterTableCmd *subcmd = castNode(AlterTableCmd, sub->parsetree);
const char *strtype;
Assert(IsA(subcmd, AlterTableCmd));
switch (subcmd->subtype)
{
case AT_AddColumn: