mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Use l*_node() family of functions where appropriate
Instead of castNode(…, lfoo(…)) Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> Discussion: https://www.postgresql.org/message-id/flat/87eecahraj.fsf@wibble.ilmari.org
This commit is contained in:
parent
29abde637b
commit
2b00db4fb0
@ -514,7 +514,7 @@ OpenTableList(List *tables)
|
|||||||
*/
|
*/
|
||||||
foreach(lc, tables)
|
foreach(lc, tables)
|
||||||
{
|
{
|
||||||
RangeVar *rv = castNode(RangeVar, lfirst(lc));
|
RangeVar *rv = lfirst_node(RangeVar, lc);
|
||||||
bool recurse = rv->inh;
|
bool recurse = rv->inh;
|
||||||
Relation rel;
|
Relation rel;
|
||||||
Oid myrelid;
|
Oid myrelid;
|
||||||
|
@ -4770,7 +4770,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
|
|||||||
|
|
||||||
foreach(lcmd, subcmds)
|
foreach(lcmd, subcmds)
|
||||||
ATExecCmd(wqueue, tab,
|
ATExecCmd(wqueue, tab,
|
||||||
castNode(AlterTableCmd, lfirst(lcmd)),
|
lfirst_node(AlterTableCmd, lcmd),
|
||||||
lockmode, pass, context);
|
lockmode, pass, context);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -12842,7 +12842,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
|
|||||||
|
|
||||||
foreach(lcmd, stmt->cmds)
|
foreach(lcmd, stmt->cmds)
|
||||||
{
|
{
|
||||||
AlterTableCmd *cmd = castNode(AlterTableCmd, lfirst(lcmd));
|
AlterTableCmd *cmd = lfirst_node(AlterTableCmd, lcmd);
|
||||||
|
|
||||||
if (cmd->subtype == AT_AddIndex)
|
if (cmd->subtype == AT_AddIndex)
|
||||||
{
|
{
|
||||||
@ -16671,7 +16671,7 @@ transformPartitionSpec(Relation rel, PartitionSpec *partspec, char *strategy)
|
|||||||
/* take care of any partition expressions */
|
/* take care of any partition expressions */
|
||||||
foreach(l, partspec->partParams)
|
foreach(l, partspec->partParams)
|
||||||
{
|
{
|
||||||
PartitionElem *pelem = castNode(PartitionElem, lfirst(l));
|
PartitionElem *pelem = lfirst_node(PartitionElem, l);
|
||||||
|
|
||||||
if (pelem->expr)
|
if (pelem->expr)
|
||||||
{
|
{
|
||||||
@ -16708,7 +16708,7 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
|
|||||||
attn = 0;
|
attn = 0;
|
||||||
foreach(lc, partParams)
|
foreach(lc, partParams)
|
||||||
{
|
{
|
||||||
PartitionElem *pelem = castNode(PartitionElem, lfirst(lc));
|
PartitionElem *pelem = lfirst_node(PartitionElem, lc);
|
||||||
Oid atttype;
|
Oid atttype;
|
||||||
Oid attcollation;
|
Oid attcollation;
|
||||||
|
|
||||||
|
@ -585,7 +585,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate,
|
|||||||
|
|
||||||
foreach(ll, wcoList)
|
foreach(ll, wcoList)
|
||||||
{
|
{
|
||||||
WithCheckOption *wco = castNode(WithCheckOption, lfirst(ll));
|
WithCheckOption *wco = lfirst_node(WithCheckOption, ll);
|
||||||
ExprState *wcoExpr = ExecInitQual(castNode(List, wco->qual),
|
ExprState *wcoExpr = ExecInitQual(castNode(List, wco->qual),
|
||||||
&mtstate->ps);
|
&mtstate->ps);
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags)
|
|||||||
i = 0;
|
i = 0;
|
||||||
foreach(vtl, node->values_lists)
|
foreach(vtl, node->values_lists)
|
||||||
{
|
{
|
||||||
List *exprs = castNode(List, lfirst(vtl));
|
List *exprs = lfirst_node(List, vtl);
|
||||||
|
|
||||||
scanstate->exprlists[i] = exprs;
|
scanstate->exprlists[i] = exprs;
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ process_subquery_nestloop_params(PlannerInfo *root, List *subplan_params)
|
|||||||
|
|
||||||
foreach(lc, subplan_params)
|
foreach(lc, subplan_params)
|
||||||
{
|
{
|
||||||
PlannerParamItem *pitem = castNode(PlannerParamItem, lfirst(lc));
|
PlannerParamItem *pitem = lfirst_node(PlannerParamItem, lc);
|
||||||
|
|
||||||
if (IsA(pitem->item, Var))
|
if (IsA(pitem->item, Var))
|
||||||
{
|
{
|
||||||
|
@ -2807,7 +2807,7 @@ transformWindowDefinitions(ParseState *pstate,
|
|||||||
(errcode(ERRCODE_WINDOWING_ERROR),
|
(errcode(ERRCODE_WINDOWING_ERROR),
|
||||||
errmsg("RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column"),
|
errmsg("RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column"),
|
||||||
parser_errposition(pstate, windef->location)));
|
parser_errposition(pstate, windef->location)));
|
||||||
sortcl = castNode(SortGroupClause, linitial(wc->orderClause));
|
sortcl = linitial_node(SortGroupClause, wc->orderClause);
|
||||||
sortkey = get_sortgroupclause_expr(sortcl, *targetlist);
|
sortkey = get_sortgroupclause_expr(sortcl, *targetlist);
|
||||||
/* Find the sort operator in pg_amop */
|
/* Find the sort operator in pg_amop */
|
||||||
if (!get_ordering_op_properties(sortcl->sortop,
|
if (!get_ordering_op_properties(sortcl->sortop,
|
||||||
|
@ -2424,7 +2424,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
|||||||
/* Make sure referenced column exists. */
|
/* Make sure referenced column exists. */
|
||||||
foreach(columns, cxt->columns)
|
foreach(columns, cxt->columns)
|
||||||
{
|
{
|
||||||
column = castNode(ColumnDef, lfirst(columns));
|
column = lfirst_node(ColumnDef, columns);
|
||||||
if (strcmp(column->colname, key) == 0)
|
if (strcmp(column->colname, key) == 0)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
@ -2462,7 +2462,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
|||||||
|
|
||||||
foreach(inher, cxt->inhRelations)
|
foreach(inher, cxt->inhRelations)
|
||||||
{
|
{
|
||||||
RangeVar *inh = castNode(RangeVar, lfirst(inher));
|
RangeVar *inh = lfirst_node(RangeVar, inher);
|
||||||
Relation rel;
|
Relation rel;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
@ -4088,7 +4088,7 @@ transformPartitionBound(ParseState *pstate, Relation parent,
|
|||||||
duplicate = false;
|
duplicate = false;
|
||||||
foreach(cell2, result_spec->listdatums)
|
foreach(cell2, result_spec->listdatums)
|
||||||
{
|
{
|
||||||
Const *value2 = castNode(Const, lfirst(cell2));
|
Const *value2 = lfirst_node(Const, cell2);
|
||||||
|
|
||||||
if (equal(value, value2))
|
if (equal(value, value2))
|
||||||
{
|
{
|
||||||
@ -4267,7 +4267,7 @@ validateInfiniteBounds(ParseState *pstate, List *blist)
|
|||||||
|
|
||||||
foreach(lc, blist)
|
foreach(lc, blist)
|
||||||
{
|
{
|
||||||
PartitionRangeDatum *prd = castNode(PartitionRangeDatum, lfirst(lc));
|
PartitionRangeDatum *prd = lfirst_node(PartitionRangeDatum, lc);
|
||||||
|
|
||||||
if (kind == prd->kind)
|
if (kind == prd->kind)
|
||||||
continue;
|
continue;
|
||||||
|
@ -452,7 +452,7 @@ get_non_null_list_datum_count(PartitionBoundSpec **boundspecs, int nparts)
|
|||||||
|
|
||||||
foreach(lc, boundspecs[i]->listdatums)
|
foreach(lc, boundspecs[i]->listdatums)
|
||||||
{
|
{
|
||||||
Const *val = castNode(Const, lfirst(lc));
|
Const *val = lfirst_node(Const, lc);
|
||||||
|
|
||||||
if (!val->constisnull)
|
if (!val->constisnull)
|
||||||
count++;
|
count++;
|
||||||
@ -513,7 +513,7 @@ create_list_bounds(PartitionBoundSpec **boundspecs, int nparts,
|
|||||||
|
|
||||||
foreach(c, spec->listdatums)
|
foreach(c, spec->listdatums)
|
||||||
{
|
{
|
||||||
Const *val = castNode(Const, lfirst(c));
|
Const *val = lfirst_node(Const, c);
|
||||||
|
|
||||||
if (!val->constisnull)
|
if (!val->constisnull)
|
||||||
{
|
{
|
||||||
@ -3014,7 +3014,7 @@ check_new_partition_bound(char *relname, Relation parent,
|
|||||||
|
|
||||||
foreach(cell, spec->listdatums)
|
foreach(cell, spec->listdatums)
|
||||||
{
|
{
|
||||||
Const *val = castNode(Const, lfirst(cell));
|
Const *val = lfirst_node(Const, cell);
|
||||||
|
|
||||||
overlap_location = val->location;
|
overlap_location = val->location;
|
||||||
if (!val->constisnull)
|
if (!val->constisnull)
|
||||||
@ -3399,7 +3399,7 @@ make_one_partition_rbound(PartitionKey key, int index, List *datums, bool lower)
|
|||||||
i = 0;
|
i = 0;
|
||||||
foreach(lc, datums)
|
foreach(lc, datums)
|
||||||
{
|
{
|
||||||
PartitionRangeDatum *datum = castNode(PartitionRangeDatum, lfirst(lc));
|
PartitionRangeDatum *datum = lfirst_node(PartitionRangeDatum, lc);
|
||||||
|
|
||||||
/* What's contained in this range datum? */
|
/* What's contained in this range datum? */
|
||||||
bound->kind[i] = datum->kind;
|
bound->kind[i] = datum->kind;
|
||||||
@ -4103,7 +4103,7 @@ get_qual_for_list(Relation parent, PartitionBoundSpec *spec)
|
|||||||
*/
|
*/
|
||||||
foreach(cell, spec->listdatums)
|
foreach(cell, spec->listdatums)
|
||||||
{
|
{
|
||||||
Const *val = castNode(Const, lfirst(cell));
|
Const *val = lfirst_node(Const, cell);
|
||||||
|
|
||||||
if (val->constisnull)
|
if (val->constisnull)
|
||||||
list_has_null = true;
|
list_has_null = true;
|
||||||
@ -4358,8 +4358,8 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec,
|
|||||||
Datum test_result;
|
Datum test_result;
|
||||||
bool isNull;
|
bool isNull;
|
||||||
|
|
||||||
ldatum = castNode(PartitionRangeDatum, lfirst(cell1));
|
ldatum = lfirst_node(PartitionRangeDatum, cell1);
|
||||||
udatum = castNode(PartitionRangeDatum, lfirst(cell2));
|
udatum = lfirst_node(PartitionRangeDatum, cell2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Since get_range_key_properties() modifies partexprs_item, and we
|
* Since get_range_key_properties() modifies partexprs_item, and we
|
||||||
@ -4440,11 +4440,11 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec,
|
|||||||
PartitionRangeDatum *ldatum_next = NULL,
|
PartitionRangeDatum *ldatum_next = NULL,
|
||||||
*udatum_next = NULL;
|
*udatum_next = NULL;
|
||||||
|
|
||||||
ldatum = castNode(PartitionRangeDatum, lfirst(cell1));
|
ldatum = lfirst_node(PartitionRangeDatum, cell1);
|
||||||
if (lnext(spec->lowerdatums, cell1))
|
if (lnext(spec->lowerdatums, cell1))
|
||||||
ldatum_next = castNode(PartitionRangeDatum,
|
ldatum_next = castNode(PartitionRangeDatum,
|
||||||
lfirst(lnext(spec->lowerdatums, cell1)));
|
lfirst(lnext(spec->lowerdatums, cell1)));
|
||||||
udatum = castNode(PartitionRangeDatum, lfirst(cell2));
|
udatum = lfirst_node(PartitionRangeDatum, cell2);
|
||||||
if (lnext(spec->upperdatums, cell2))
|
if (lnext(spec->upperdatums, cell2))
|
||||||
udatum_next = castNode(PartitionRangeDatum,
|
udatum_next = castNode(PartitionRangeDatum,
|
||||||
lfirst(lnext(spec->upperdatums, cell2)));
|
lfirst(lnext(spec->upperdatums, cell2)));
|
||||||
|
@ -307,8 +307,8 @@ rewriteSearchAndCycle(CommonTableExpr *cte)
|
|||||||
list_nth_oid(cte->ctecolcollations, i),
|
list_nth_oid(cte->ctecolcollations, i),
|
||||||
0);
|
0);
|
||||||
tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false);
|
tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false);
|
||||||
tle->resorigtbl = castNode(TargetEntry, list_nth(rte1->subquery->targetList, i))->resorigtbl;
|
tle->resorigtbl = list_nth_node(TargetEntry, rte1->subquery->targetList, i)->resorigtbl;
|
||||||
tle->resorigcol = castNode(TargetEntry, list_nth(rte1->subquery->targetList, i))->resorigcol;
|
tle->resorigcol = list_nth_node(TargetEntry, rte1->subquery->targetList, i)->resorigcol;
|
||||||
newq1->targetList = lappend(newq1->targetList, tle);
|
newq1->targetList = lappend(newq1->targetList, tle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,8 +482,8 @@ rewriteSearchAndCycle(CommonTableExpr *cte)
|
|||||||
list_nth_oid(cte->ctecolcollations, i),
|
list_nth_oid(cte->ctecolcollations, i),
|
||||||
0);
|
0);
|
||||||
tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false);
|
tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false);
|
||||||
tle->resorigtbl = castNode(TargetEntry, list_nth(rte2->subquery->targetList, i))->resorigtbl;
|
tle->resorigtbl = list_nth_node(TargetEntry, rte2->subquery->targetList, i)->resorigtbl;
|
||||||
tle->resorigcol = castNode(TargetEntry, list_nth(rte2->subquery->targetList, i))->resorigcol;
|
tle->resorigcol = list_nth_node(TargetEntry, rte2->subquery->targetList, i)->resorigcol;
|
||||||
newq2->targetList = lappend(newq2->targetList, tle);
|
newq2->targetList = lappend(newq2->targetList, tle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -785,7 +785,7 @@ pg_rewrite_query(Query *query)
|
|||||||
*/
|
*/
|
||||||
foreach(lc, querytree_list)
|
foreach(lc, querytree_list)
|
||||||
{
|
{
|
||||||
Query *query = castNode(Query, lfirst(lc));
|
Query *query = lfirst_node(Query, lc);
|
||||||
|
|
||||||
if (query->commandType != CMD_UTILITY)
|
if (query->commandType != CMD_UTILITY)
|
||||||
{
|
{
|
||||||
|
@ -7793,7 +7793,7 @@ find_param_referent(Param *param, deparse_context *context,
|
|||||||
*/
|
*/
|
||||||
foreach(lc2, ((Plan *) ancestor)->initPlan)
|
foreach(lc2, ((Plan *) ancestor)->initPlan)
|
||||||
{
|
{
|
||||||
SubPlan *subplan = castNode(SubPlan, lfirst(lc2));
|
SubPlan *subplan = lfirst_node(SubPlan, lc2);
|
||||||
|
|
||||||
if (child_plan != (Plan *) list_nth(dpns->subplans,
|
if (child_plan != (Plan *) list_nth(dpns->subplans,
|
||||||
subplan->plan_id - 1))
|
subplan->plan_id - 1))
|
||||||
@ -9407,7 +9407,7 @@ get_rule_expr(Node *node, deparse_context *context,
|
|||||||
sep = "";
|
sep = "";
|
||||||
foreach(cell, spec->listdatums)
|
foreach(cell, spec->listdatums)
|
||||||
{
|
{
|
||||||
Const *val = castNode(Const, lfirst(cell));
|
Const *val = lfirst_node(Const, cell);
|
||||||
|
|
||||||
appendStringInfoString(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
get_const_expr(val, context, -1);
|
get_const_expr(val, context, -1);
|
||||||
@ -11990,7 +11990,7 @@ get_range_partbound_string(List *bound_datums)
|
|||||||
foreach(cell, bound_datums)
|
foreach(cell, bound_datums)
|
||||||
{
|
{
|
||||||
PartitionRangeDatum *datum =
|
PartitionRangeDatum *datum =
|
||||||
castNode(PartitionRangeDatum, lfirst(cell));
|
lfirst_node(PartitionRangeDatum, cell);
|
||||||
|
|
||||||
appendStringInfoString(buf, sep);
|
appendStringInfoString(buf, sep);
|
||||||
if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
|
if (datum->kind == PARTITION_RANGE_DATUM_MINVALUE)
|
||||||
|
@ -7996,7 +7996,7 @@ exec_save_simple_expr(PLpgSQL_expr *expr, CachedPlan *cplan)
|
|||||||
{
|
{
|
||||||
/* Extract the single tlist expression */
|
/* Extract the single tlist expression */
|
||||||
Assert(list_length(plan->targetlist) == 1);
|
Assert(list_length(plan->targetlist) == 1);
|
||||||
tle_expr = castNode(TargetEntry, linitial(plan->targetlist))->expr;
|
tle_expr = linitial_node(TargetEntry, plan->targetlist)->expr;
|
||||||
|
|
||||||
if (IsA(plan, Result))
|
if (IsA(plan, Result))
|
||||||
{
|
{
|
||||||
|
@ -131,8 +131,8 @@ test_predtest(PG_FUNCTION_ARGS)
|
|||||||
elog(ERROR, "failed to decipher query plan");
|
elog(ERROR, "failed to decipher query plan");
|
||||||
plan = stmt->planTree;
|
plan = stmt->planTree;
|
||||||
Assert(list_length(plan->targetlist) >= 2);
|
Assert(list_length(plan->targetlist) >= 2);
|
||||||
clause1 = castNode(TargetEntry, linitial(plan->targetlist))->expr;
|
clause1 = linitial_node(TargetEntry, plan->targetlist)->expr;
|
||||||
clause2 = castNode(TargetEntry, lsecond(plan->targetlist))->expr;
|
clause2 = lsecond_node(TargetEntry, plan->targetlist)->expr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Because the clauses are in the SELECT list, preprocess_expression did
|
* Because the clauses are in the SELECT list, preprocess_expression did
|
||||||
|
Loading…
x
Reference in New Issue
Block a user