mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Make more use of castNode()
This commit is contained in:
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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.
|
||||
*
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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));
|
||||
|
@@ -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 */
|
||||
|
@@ -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)
|
||||
|
@@ -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))
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user