Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit38d1037

Browse files
committed
Make more use of castNode()
1 parent4e5ce3c commit38d1037

37 files changed

+121
-222
lines changed

‎src/backend/commands/copy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ ProcessCopyOptions(ParseState *pstate,
11231123
if (defel->arg&&IsA(defel->arg,A_Star))
11241124
cstate->force_quote_all= true;
11251125
elseif (defel->arg&&IsA(defel->arg,List))
1126-
cstate->force_quote= (List*)defel->arg;
1126+
cstate->force_quote=castNode(List,defel->arg);
11271127
else
11281128
ereport(ERROR,
11291129
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),

‎src/backend/nodes/nodeFuncs.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ exprType(const Node *expr)
111111

112112
if (!qtree|| !IsA(qtree,Query))
113113
elog(ERROR,"cannot get type for untransformed sublink");
114-
tent= (TargetEntry*)linitial(qtree->targetList);
115-
Assert(IsA(tent,TargetEntry));
114+
tent=castNode(TargetEntry,linitial(qtree->targetList));
116115
Assert(!tent->resjunk);
117116
type=exprType((Node*)tent->expr);
118117
if (sublink->subLinkType==ARRAY_SUBLINK)
@@ -322,8 +321,7 @@ exprTypmod(const Node *expr)
322321

323322
if (!qtree|| !IsA(qtree,Query))
324323
elog(ERROR,"cannot get type for untransformed sublink");
325-
tent= (TargetEntry*)linitial(qtree->targetList);
326-
Assert(IsA(tent,TargetEntry));
324+
tent=castNode(TargetEntry,linitial(qtree->targetList));
327325
Assert(!tent->resjunk);
328326
returnexprTypmod((Node*)tent->expr);
329327
/* note we don't need to care if it's an array */
@@ -381,9 +379,8 @@ exprTypmod(const Node *expr)
381379
return-1;/* no point in trying harder */
382380
foreach(arg,cexpr->args)
383381
{
384-
CaseWhen*w= (CaseWhen*)lfirst(arg);
382+
CaseWhen*w=castNode(CaseWhen,lfirst(arg));
385383

386-
Assert(IsA(w,CaseWhen));
387384
if (exprType((Node*)w->result)!=casetype)
388385
return-1;
389386
if (exprTypmod((Node*)w->result)!=typmod)
@@ -809,8 +806,7 @@ exprCollation(const Node *expr)
809806

810807
if (!qtree|| !IsA(qtree,Query))
811808
elog(ERROR,"cannot get collation for untransformed sublink");
812-
tent= (TargetEntry*)linitial(qtree->targetList);
813-
Assert(IsA(tent,TargetEntry));
809+
tent=castNode(TargetEntry,linitial(qtree->targetList));
814810
Assert(!tent->resjunk);
815811
coll=exprCollation((Node*)tent->expr);
816812
/* collation doesn't change if it's converted to array */
@@ -1052,8 +1048,7 @@ exprSetCollation(Node *expr, Oid collation)
10521048

10531049
if (!qtree|| !IsA(qtree,Query))
10541050
elog(ERROR,"cannot set collation for untransformed sublink");
1055-
tent= (TargetEntry*)linitial(qtree->targetList);
1056-
Assert(IsA(tent,TargetEntry));
1051+
tent=castNode(TargetEntry,linitial(qtree->targetList));
10571052
Assert(!tent->resjunk);
10581053
Assert(collation==exprCollation((Node*)tent->expr));
10591054
}
@@ -2050,9 +2045,8 @@ expression_tree_walker(Node *node,
20502045
/* we assume walker doesn't care about CaseWhens, either */
20512046
foreach(temp,caseexpr->args)
20522047
{
2053-
CaseWhen*when= (CaseWhen*)lfirst(temp);
2048+
CaseWhen*when=castNode(CaseWhen,lfirst(temp));
20542049

2055-
Assert(IsA(when,CaseWhen));
20562050
if (walker(when->expr,context))
20572051
return true;
20582052
if (walker(when->result,context))
@@ -3261,9 +3255,8 @@ raw_expression_tree_walker(Node *node,
32613255
/* we assume walker doesn't care about CaseWhens, either */
32623256
foreach(temp,caseexpr->args)
32633257
{
3264-
CaseWhen*when= (CaseWhen*)lfirst(temp);
3258+
CaseWhen*when=castNode(CaseWhen,lfirst(temp));
32653259

3266-
Assert(IsA(when,CaseWhen));
32673260
if (walker(when->expr,context))
32683261
return true;
32693262
if (walker(when->result,context))
@@ -3735,9 +3728,8 @@ planstate_walk_subplans(List *plans,
37353728

37363729
foreach(lc,plans)
37373730
{
3738-
SubPlanState*sps= (SubPlanState*)lfirst(lc);
3731+
SubPlanState*sps=castNode(SubPlanState,lfirst(lc));
37393732

3740-
Assert(IsA(sps,SubPlanState));
37413733
if (walker(sps->planstate,context))
37423734
return true;
37433735
}

‎src/backend/optimizer/path/allpaths.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,8 +2382,8 @@ subquery_is_pushdown_safe(Query *subquery, Query *topquery,
23822382
if (subquery->setOperations!=NULL)
23832383
return false;
23842384
/* Check whether setop component output types match top level */
2385-
topop= (SetOperationStmt*)topquery->setOperations;
2386-
Assert(topop&&IsA(topop,SetOperationStmt));
2385+
topop=castNode(SetOperationStmt,topquery->setOperations);
2386+
Assert(topop);
23872387
compare_tlist_datatypes(subquery->targetList,
23882388
topop->colTypes,
23892389
safetyInfo);

‎src/backend/optimizer/path/costsize.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,8 @@ extract_nonindex_conditions(List *qual_clauses, List *indexquals)
682682

683683
foreach(lc,qual_clauses)
684684
{
685-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
685+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(lc));
686686

687-
Assert(IsA(rinfo,RestrictInfo));
688687
if (rinfo->pseudoconstant)
689688
continue;/* we may drop pseudoconstants here */
690689
if (list_member_ptr(indexquals,rinfo))
@@ -1804,12 +1803,10 @@ cost_windowagg(Path *path, PlannerInfo *root,
18041803
*/
18051804
foreach(lc,windowFuncs)
18061805
{
1807-
WindowFunc*wfunc= (WindowFunc*)lfirst(lc);
1806+
WindowFunc*wfunc=castNode(WindowFunc,lfirst(lc));
18081807
Costwfunccost;
18091808
QualCostargcosts;
18101809

1811-
Assert(IsA(wfunc,WindowFunc));
1812-
18131810
wfunccost=get_func_cost(wfunc->winfnoid)*cpu_operator_cost;
18141811

18151812
/* also add the input expressions' cost to per-input-row costs */
@@ -2843,11 +2840,9 @@ final_cost_hashjoin(PlannerInfo *root, HashPath *path,
28432840
innerbucketsize=1.0;
28442841
foreach(hcl,hashclauses)
28452842
{
2846-
RestrictInfo*restrictinfo= (RestrictInfo*)lfirst(hcl);
2843+
RestrictInfo*restrictinfo=castNode(RestrictInfo,lfirst(hcl));
28472844
Selectivitythisbucketsize;
28482845

2849-
Assert(IsA(restrictinfo,RestrictInfo));
2850-
28512846
/*
28522847
* First we have to figure out which side of the hashjoin clause
28532848
* is the inner side.
@@ -3537,9 +3532,8 @@ compute_semi_anti_join_factors(PlannerInfo *root,
35373532
joinquals=NIL;
35383533
foreach(l,restrictlist)
35393534
{
3540-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(l);
3535+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(l));
35413536

3542-
Assert(IsA(rinfo,RestrictInfo));
35433537
if (!rinfo->is_pushed_down)
35443538
joinquals=lappend(joinquals,rinfo);
35453539
}
@@ -3970,9 +3964,8 @@ calc_joinrel_size_estimate(PlannerInfo *root,
39703964
/* Grovel through the clauses to separate into two lists */
39713965
foreach(l,restrictlist)
39723966
{
3973-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(l);
3967+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(l));
39743968

3975-
Assert(IsA(rinfo,RestrictInfo));
39763969
if (rinfo->is_pushed_down)
39773970
pushedquals=lappend(pushedquals,rinfo);
39783971
else
@@ -4345,11 +4338,10 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
43454338
*/
43464339
foreach(lc,subroot->parse->targetList)
43474340
{
4348-
TargetEntry*te= (TargetEntry*)lfirst(lc);
4341+
TargetEntry*te=castNode(TargetEntry,lfirst(lc));
43494342
Node*texpr= (Node*)te->expr;
43504343
int32item_width=0;
43514344

4352-
Assert(IsA(te,TargetEntry));
43534345
/* junk columns aren't visible to upper query */
43544346
if (te->resjunk)
43554347
continue;

‎src/backend/optimizer/path/indxpath.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,12 +1273,11 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
12731273

12741274
foreach(lc,clauses)
12751275
{
1276-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
1276+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(lc));
12771277
List*pathlist;
12781278
Path*bitmapqual;
12791279
ListCell*j;
12801280

1281-
Assert(IsA(rinfo,RestrictInfo));
12821281
/* Ignore RestrictInfos that aren't ORs */
12831282
if (!restriction_is_or_clause(rinfo))
12841283
continue;
@@ -1310,10 +1309,10 @@ generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
13101309
}
13111310
else
13121311
{
1312+
RestrictInfo*rinfo=castNode(RestrictInfo,orarg);
13131313
List*orargs;
13141314

1315-
Assert(IsA(orarg,RestrictInfo));
1316-
Assert(!restriction_is_or_clause((RestrictInfo*)orarg));
1315+
Assert(!restriction_is_or_clause(rinfo));
13171316
orargs=list_make1(orarg);
13181317

13191318
indlist=build_paths_for_OR(root,rel,
@@ -2174,9 +2173,8 @@ match_clauses_to_index(IndexOptInfo *index,
21742173

21752174
foreach(lc,clauses)
21762175
{
2177-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
2176+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(lc));
21782177

2179-
Assert(IsA(rinfo,RestrictInfo));
21802178
match_clause_to_index(index,rinfo,clauseset);
21812179
}
21822180
}

‎src/backend/optimizer/path/joinrels.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,8 @@ restriction_is_constant_false(List *restrictlist, bool only_pushed_down)
12301230
*/
12311231
foreach(lc,restrictlist)
12321232
{
1233-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
1233+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(lc));
12341234

1235-
Assert(IsA(rinfo,RestrictInfo));
12361235
if (only_pushed_down&& !rinfo->is_pushed_down)
12371236
continue;
12381237

‎src/backend/optimizer/plan/analyzejoins.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ rel_is_distinct_for(PlannerInfo *root, RelOptInfo *rel, List *clause_list)
596596
*/
597597
foreach(l,clause_list)
598598
{
599-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(l);
599+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(l));
600600
Oidop;
601601
Var*var;
602602

@@ -608,8 +608,7 @@ rel_is_distinct_for(PlannerInfo *root, RelOptInfo *rel, List *clause_list)
608608
* caller's mergejoinability test should have selected only
609609
* OpExprs.
610610
*/
611-
Assert(IsA(rinfo->clause,OpExpr));
612-
op= ((OpExpr*)rinfo->clause)->opno;
611+
op=castNode(OpExpr,rinfo->clause)->opno;
613612

614613
/* caller identified the inner side for us */
615614
if (rinfo->outer_is_left)
@@ -782,9 +781,8 @@ query_is_distinct_for(Query *query, List *colnos, List *opids)
782781
*/
783782
if (query->setOperations)
784783
{
785-
SetOperationStmt*topop= (SetOperationStmt*)query->setOperations;
784+
SetOperationStmt*topop=castNode(SetOperationStmt,query->setOperations);
786785

787-
Assert(IsA(topop,SetOperationStmt));
788786
Assert(topop->op!=SETOP_NONE);
789787

790788
if (!topop->all)

‎src/backend/optimizer/plan/createplan.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,7 @@ create_scan_plan(PlannerInfo *root, Path *best_path, int flags)
508508
{
509509
caseT_IndexScan:
510510
caseT_IndexOnlyScan:
511-
Assert(IsA(best_path,IndexPath));
512-
scan_clauses= ((IndexPath*)best_path)->indexinfo->indrestrictinfo;
511+
scan_clauses=castNode(IndexPath,best_path)->indexinfo->indrestrictinfo;
513512
break;
514513
default:
515514
scan_clauses=rel->baserestrictinfo;
@@ -2450,9 +2449,8 @@ create_indexscan_plan(PlannerInfo *root,
24502449
qpqual=NIL;
24512450
foreach(l,scan_clauses)
24522451
{
2453-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(l);
2452+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(l));
24542453

2455-
Assert(IsA(rinfo,RestrictInfo));
24562454
if (rinfo->pseudoconstant)
24572455
continue;/* we may drop pseudoconstants here */
24582456
if (list_member_ptr(indexquals,rinfo))
@@ -2608,10 +2606,9 @@ create_bitmap_scan_plan(PlannerInfo *root,
26082606
qpqual=NIL;
26092607
foreach(l,scan_clauses)
26102608
{
2611-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(l);
2609+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(l));
26122610
Node*clause= (Node*)rinfo->clause;
26132611

2614-
Assert(IsA(rinfo,RestrictInfo));
26152612
if (rinfo->pseudoconstant)
26162613
continue;/* we may drop pseudoconstants here */
26172614
if (list_member(indexquals,clause))
@@ -2820,9 +2817,9 @@ create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,
28202817
ListCell*l;
28212818

28222819
/* Use the regular indexscan plan build machinery... */
2823-
iscan= (IndexScan*)create_indexscan_plan(root,ipath,
2824-
NIL,NIL, false);
2825-
Assert(IsA(iscan,IndexScan));
2820+
iscan=castNode(IndexScan,
2821+
create_indexscan_plan(root,ipath,
2822+
NIL,NIL, false));
28262823
/* then convert to a bitmap indexscan */
28272824
plan= (Plan*)make_bitmap_indexscan(iscan->scan.scanrelid,
28282825
iscan->indexid,
@@ -3391,13 +3388,13 @@ create_customscan_plan(PlannerInfo *root, CustomPath *best_path,
33913388
* Invoke custom plan provider to create the Plan node represented by the
33923389
* CustomPath.
33933390
*/
3394-
cplan= (CustomScan*)best_path->methods->PlanCustomPath(root,
3395-
rel,
3396-
best_path,
3397-
tlist,
3398-
scan_clauses,
3399-
custom_plans);
3400-
Assert(IsA(cplan,CustomScan));
3391+
cplan=castNode(CustomScan,
3392+
best_path->methods->PlanCustomPath(root,
3393+
rel,
3394+
best_path,
3395+
tlist,
3396+
scan_clauses,
3397+
custom_plans));
34013398

34023399
/*
34033400
* Copy cost data from Path to Plan; no need to make custom-plan providers
@@ -3683,7 +3680,7 @@ create_mergejoin_plan(PlannerInfo *root,
36833680
i=0;
36843681
foreach(lc,best_path->path_mergeclauses)
36853682
{
3686-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
3683+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(lc));
36873684
EquivalenceClass*oeclass;
36883685
EquivalenceClass*ieclass;
36893686
PathKey*opathkey;
@@ -3693,7 +3690,6 @@ create_mergejoin_plan(PlannerInfo *root,
36933690
ListCell*l2;
36943691

36953692
/* fetch outer/inner eclass from mergeclause */
3696-
Assert(IsA(rinfo,RestrictInfo));
36973693
if (rinfo->outer_is_left)
36983694
{
36993695
oeclass=rinfo->left_ec;
@@ -4228,12 +4224,10 @@ fix_indexqual_references(PlannerInfo *root, IndexPath *index_path)
42284224

42294225
forboth(lcc,index_path->indexquals,lci,index_path->indexqualcols)
42304226
{
4231-
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lcc);
4227+
RestrictInfo*rinfo=castNode(RestrictInfo,lfirst(lcc));
42324228
intindexcol=lfirst_int(lci);
42334229
Node*clause;
42344230

4235-
Assert(IsA(rinfo,RestrictInfo));
4236-
42374231
/*
42384232
* Replace any outer-relation variables with nestloop params.
42394233
*

‎src/backend/optimizer/plan/planner.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,9 +3963,8 @@ create_one_window_path(PlannerInfo *root,
39633963
window_target=copy_pathtarget(window_target);
39643964
foreach(lc2,wflists->windowFuncs[wc->winref])
39653965
{
3966-
WindowFunc*wfunc= (WindowFunc*)lfirst(lc2);
3966+
WindowFunc*wfunc=castNode(WindowFunc,lfirst(lc2));
39673967

3968-
Assert(IsA(wfunc,WindowFunc));
39693968
add_column_to_pathtarget(window_target, (Expr*)wfunc,0);
39703969
window_target->width+=get_typavgwidth(wfunc->wintype,-1);
39713970
}

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,9 @@ set_plan_references(PlannerInfo *root, Plan *plan)
224224
*/
225225
foreach(lc,root->rowMarks)
226226
{
227-
PlanRowMark*rc= (PlanRowMark*)lfirst(lc);
227+
PlanRowMark*rc=castNode(PlanRowMark,lfirst(lc));
228228
PlanRowMark*newrc;
229229

230-
Assert(IsA(rc,PlanRowMark));
231-
232230
/* flat copy is enough since all fields are scalars */
233231
newrc= (PlanRowMark*)palloc(sizeof(PlanRowMark));
234232
memcpy(newrc,rc,sizeof(PlanRowMark));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp