aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-03-09 15:18:59 -0500
committerPeter Eisentraut <peter_e@gmx.net>2017-03-28 21:59:23 -0400
commit4cb824699e12c39fad97fb3d9085ced0d14c067c (patch)
tree9a835d8efb7739e6436d3fc24b4b5a290b95df7d /src/backend/optimizer
parent66b764341ba12206f01e2600713bdc3abdb070b3 (diff)
downloadpostgresql-4cb824699e12c39fad97fb3d9085ced0d14c067c.tar.gz
postgresql-4cb824699e12c39fad97fb3d9085ced0d14c067c.zip
Cast result of copyObject() to correct type
copyObject() is declared to return void *, which allows easily assigning the result independent of the input, but it loses all type checking. If the compiler supports typeof or something similar, cast the result to the input type. This creates a greater amount of type safety. In some cases, where the result is assigned to a generic type such as Node * or Expr *, new casts are now necessary, but in general casts are now unnecessary in the normal case and indicate that something unusual is happening. Reviewed-by: Mark Dilger <hornschnorter@gmail.com>
Diffstat (limited to 'src/backend/optimizer')
-rw-r--r--src/backend/optimizer/path/indxpath.c4
-rw-r--r--src/backend/optimizer/plan/createplan.c6
-rw-r--r--src/backend/optimizer/plan/initsplan.c8
-rw-r--r--src/backend/optimizer/plan/planagg.c4
-rw-r--r--src/backend/optimizer/plan/planner.c4
-rw-r--r--src/backend/optimizer/plan/setrefs.c26
-rw-r--r--src/backend/optimizer/plan/subselect.c14
-rw-r--r--src/backend/optimizer/prep/prepjointree.c4
-rw-r--r--src/backend/optimizer/prep/preptlist.c2
-rw-r--r--src/backend/optimizer/prep/prepunion.c4
-rw-r--r--src/backend/optimizer/util/tlist.c12
11 files changed, 44 insertions, 44 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index c2b72d410af..a5d19f9b1c5 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -4004,9 +4004,9 @@ adjust_rowcompare_for_index(RowCompareExpr *clause,
matching_cols);
rc->inputcollids = list_truncate(list_copy(clause->inputcollids),
matching_cols);
- rc->largs = list_truncate((List *) copyObject(clause->largs),
+ rc->largs = list_truncate(copyObject(clause->largs),
matching_cols);
- rc->rargs = list_truncate((List *) copyObject(clause->rargs),
+ rc->rargs = list_truncate(copyObject(clause->rargs),
matching_cols);
return (Expr *) rc;
}
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index aafec58281b..d357479829f 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -1275,7 +1275,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags)
foreach(l, uniq_exprs)
{
- Node *uniqexpr = lfirst(l);
+ Expr *uniqexpr = lfirst(l);
TargetEntry *tle;
tle = tlist_member(uniqexpr, newtlist);
@@ -1318,7 +1318,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags)
groupColPos = 0;
foreach(l, uniq_exprs)
{
- Node *uniqexpr = lfirst(l);
+ Expr *uniqexpr = lfirst(l);
TargetEntry *tle;
tle = tlist_member(uniqexpr, newtlist);
@@ -4318,7 +4318,7 @@ process_subquery_nestloop_params(PlannerInfo *root, List *subplan_params)
/* No, so add it */
nlp = makeNode(NestLoopParam);
nlp->paramno = pitem->paramId;
- nlp->paramval = copyObject(phv);
+ nlp->paramval = (Var *) copyObject(phv);
root->curOuterParams = lappend(root->curOuterParams, nlp);
}
}
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index b4ac224a7a8..53aefbd1a3d 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -2306,8 +2306,8 @@ process_implied_equality(PlannerInfo *root,
clause = make_opclause(opno,
BOOLOID, /* opresulttype */
false, /* opretset */
- (Expr *) copyObject(item1),
- (Expr *) copyObject(item2),
+ copyObject(item1),
+ copyObject(item2),
InvalidOid,
collation);
@@ -2369,8 +2369,8 @@ build_implied_join_equality(Oid opno,
clause = make_opclause(opno,
BOOLOID, /* opresulttype */
false, /* opretset */
- (Expr *) copyObject(item1),
- (Expr *) copyObject(item2),
+ copyObject(item1),
+ copyObject(item2),
InvalidOid,
collation);
diff --git a/src/backend/optimizer/plan/planagg.c b/src/backend/optimizer/plan/planagg.c
index c3fbf3cdf82..55657360fc3 100644
--- a/src/backend/optimizer/plan/planagg.c
+++ b/src/backend/optimizer/plan/planagg.c
@@ -369,11 +369,11 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo,
subroot->outer_params = NULL;
subroot->init_plans = NIL;
- subroot->parse = parse = (Query *) copyObject(root->parse);
+ subroot->parse = parse = copyObject(root->parse);
IncrementVarSublevelsUp((Node *) parse, 1, 1);
/* append_rel_list might contain outer Vars? */
- subroot->append_rel_list = (List *) copyObject(root->append_rel_list);
+ subroot->append_rel_list = copyObject(root->append_rel_list);
IncrementVarSublevelsUp((Node *) subroot->append_rel_list, 1, 1);
/* There shouldn't be any OJ info to translate, as yet */
Assert(subroot->join_info_list == NIL);
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index fa7a5f84277..f99257b5993 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -1157,7 +1157,7 @@ inheritance_planner(PlannerInfo *root)
* executor doesn't need to see the modified copies --- we can just
* pass it the original rowMarks list.)
*/
- subroot->rowMarks = (List *) copyObject(root->rowMarks);
+ subroot->rowMarks = copyObject(root->rowMarks);
/*
* The append_rel_list likewise might contain references to subquery
@@ -1179,7 +1179,7 @@ inheritance_planner(PlannerInfo *root)
AppendRelInfo *appinfo2 = (AppendRelInfo *) lfirst(lc2);
if (bms_is_member(appinfo2->child_relid, modifiableARIindexes))
- appinfo2 = (AppendRelInfo *) copyObject(appinfo2);
+ appinfo2 = copyObject(appinfo2);
subroot->append_rel_list = lappend(subroot->append_rel_list,
appinfo2);
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 5930747eba4..4e3f6ee960f 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -111,10 +111,10 @@ static Var *search_indexed_tlist_for_var(Var *var,
indexed_tlist *itlist,
Index newvarno,
int rtoffset);
-static Var *search_indexed_tlist_for_non_var(Node *node,
+static Var *search_indexed_tlist_for_non_var(Expr *node,
indexed_tlist *itlist,
Index newvarno);
-static Var *search_indexed_tlist_for_sortgroupref(Node *node,
+static Var *search_indexed_tlist_for_sortgroupref(Expr *node,
Index sortgroupref,
indexed_tlist *itlist,
Index newvarno);
@@ -1440,7 +1440,7 @@ fix_param_node(PlannerInfo *root, Param *p)
elog(ERROR, "unexpected PARAM_MULTIEXPR ID: %d", p->paramid);
return copyObject(list_nth(params, colno - 1));
}
- return copyObject(p);
+ return (Node *) copyObject(p);
}
/*
@@ -1727,7 +1727,7 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
if (tle->ressortgroupref != 0 && !IsA(tle->expr, Var))
{
newexpr = (Node *)
- search_indexed_tlist_for_sortgroupref((Node *) tle->expr,
+ search_indexed_tlist_for_sortgroupref(tle->expr,
tle->ressortgroupref,
subplan_itlist,
OUTER_VAR);
@@ -1810,7 +1810,7 @@ convert_combining_aggrefs(Node *node, void *context)
*/
child_agg->args = NIL;
child_agg->aggfilter = NULL;
- parent_agg = (Aggref *) copyObject(child_agg);
+ parent_agg = copyObject(child_agg);
child_agg->args = orig_agg->args;
child_agg->aggfilter = orig_agg->aggfilter;
@@ -2054,7 +2054,7 @@ search_indexed_tlist_for_var(Var *var, indexed_tlist *itlist,
* so there's a correctness reason not to call it unless that's set.
*/
static Var *
-search_indexed_tlist_for_non_var(Node *node,
+search_indexed_tlist_for_non_var(Expr *node,
indexed_tlist *itlist, Index newvarno)
{
TargetEntry *tle;
@@ -2095,7 +2095,7 @@ search_indexed_tlist_for_non_var(Node *node,
* And it's also faster than search_indexed_tlist_for_non_var.
*/
static Var *
-search_indexed_tlist_for_sortgroupref(Node *node,
+search_indexed_tlist_for_sortgroupref(Expr *node,
Index sortgroupref,
indexed_tlist *itlist,
Index newvarno)
@@ -2229,7 +2229,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
/* See if the PlaceHolderVar has bubbled up from a lower plan node */
if (context->outer_itlist && context->outer_itlist->has_ph_vars)
{
- newvar = search_indexed_tlist_for_non_var((Node *) phv,
+ newvar = search_indexed_tlist_for_non_var((Expr *) phv,
context->outer_itlist,
OUTER_VAR);
if (newvar)
@@ -2237,7 +2237,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
}
if (context->inner_itlist && context->inner_itlist->has_ph_vars)
{
- newvar = search_indexed_tlist_for_non_var((Node *) phv,
+ newvar = search_indexed_tlist_for_non_var((Expr *) phv,
context->inner_itlist,
INNER_VAR);
if (newvar)
@@ -2252,7 +2252,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
/* Try matching more complex expressions too, if tlists have any */
if (context->outer_itlist && context->outer_itlist->has_non_vars)
{
- newvar = search_indexed_tlist_for_non_var(node,
+ newvar = search_indexed_tlist_for_non_var((Expr *) node,
context->outer_itlist,
OUTER_VAR);
if (newvar)
@@ -2260,7 +2260,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
}
if (context->inner_itlist && context->inner_itlist->has_non_vars)
{
- newvar = search_indexed_tlist_for_non_var(node,
+ newvar = search_indexed_tlist_for_non_var((Expr *) node,
context->inner_itlist,
INNER_VAR);
if (newvar)
@@ -2344,7 +2344,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
/* See if the PlaceHolderVar has bubbled up from a lower plan node */
if (context->subplan_itlist->has_ph_vars)
{
- newvar = search_indexed_tlist_for_non_var((Node *) phv,
+ newvar = search_indexed_tlist_for_non_var((Expr *) phv,
context->subplan_itlist,
context->newvarno);
if (newvar)
@@ -2380,7 +2380,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
/* Try matching more complex expressions too, if tlist has any */
if (context->subplan_itlist->has_non_vars)
{
- newvar = search_indexed_tlist_for_non_var(node,
+ newvar = search_indexed_tlist_for_non_var((Expr *) node,
context->subplan_itlist,
context->newvarno);
if (newvar)
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index 6fa65406624..db0e5b31e2e 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -125,7 +125,7 @@ assign_param_for_var(PlannerInfo *root, Var *var)
}
/* Nope, so make a new one */
- var = (Var *) copyObject(var);
+ var = copyObject(var);
var->varlevelsup = 0;
pitem = makeNode(PlannerParamItem);
@@ -224,7 +224,7 @@ assign_param_for_placeholdervar(PlannerInfo *root, PlaceHolderVar *phv)
}
/* Nope, so make a new one */
- phv = (PlaceHolderVar *) copyObject(phv);
+ phv = copyObject(phv);
if (phv->phlevelsup != 0)
{
IncrementVarSublevelsUp((Node *) phv, -((int) phv->phlevelsup), 0);
@@ -316,7 +316,7 @@ replace_outer_agg(PlannerInfo *root, Aggref *agg)
* It does not seem worthwhile to try to match duplicate outer aggs. Just
* make a new slot every time.
*/
- agg = (Aggref *) copyObject(agg);
+ agg = copyObject(agg);
IncrementVarSublevelsUp((Node *) agg, -((int) agg->agglevelsup), 0);
Assert(agg->agglevelsup == 0);
@@ -358,7 +358,7 @@ replace_outer_grouping(PlannerInfo *root, GroupingFunc *grp)
* It does not seem worthwhile to try to match duplicate outer aggs. Just
* make a new slot every time.
*/
- grp = (GroupingFunc *) copyObject(grp);
+ grp = copyObject(grp);
IncrementVarSublevelsUp((Node *) grp, -((int) grp->agglevelsup), 0);
Assert(grp->agglevelsup == 0);
@@ -491,7 +491,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery,
* same sub-Query node, but the planner wants to scribble on the Query.
* Try to clean this up when we do querytree redesign...
*/
- subquery = (Query *) copyObject(orig_subquery);
+ subquery = copyObject(orig_subquery);
/*
* If it's an EXISTS subplan, we might be able to simplify it.
@@ -568,7 +568,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery,
List *paramIds;
/* Make a second copy of the original subquery */
- subquery = (Query *) copyObject(orig_subquery);
+ subquery = copyObject(orig_subquery);
/* and re-simplify */
simple_exists = simplify_EXISTS_query(root, subquery);
Assert(simple_exists);
@@ -1431,7 +1431,7 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
* Copy the subquery so we can modify it safely (see comments in
* make_subplan).
*/
- subselect = (Query *) copyObject(subselect);
+ subselect = copyObject(subselect);
/*
* See if the subquery can be simplified based on the knowledge that it's
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 048815d7b07..348c6b791f4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -1592,7 +1592,7 @@ pull_up_simple_values(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte)
* Need a modifiable copy of the VALUES list to hack on, just in case it's
* multiply referenced.
*/
- values_list = (List *) copyObject(linitial(rte->values_lists));
+ values_list = copyObject(linitial(rte->values_lists));
/*
* The VALUES RTE can't contain any Vars of level zero, let alone any that
@@ -2128,7 +2128,7 @@ pullup_replace_vars_callback(Var *var,
varattno);
/* Make a copy of the tlist item to return */
- newnode = copyObject(tle->expr);
+ newnode = (Node *) copyObject(tle->expr);
/* Insert PlaceHolderVar if needed */
if (rcon->need_phvs)
diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c
index 824af3f54cb..de47153bace 100644
--- a/src/backend/optimizer/prep/preptlist.c
+++ b/src/backend/optimizer/prep/preptlist.c
@@ -180,7 +180,7 @@ preprocess_targetlist(PlannerInfo *root, List *tlist)
var->varno == result_relation)
continue; /* don't need it */
- if (tlist_member((Node *) var, tlist))
+ if (tlist_member((Expr *) var, tlist))
continue; /* already got it */
tle = makeTargetEntry((Expr *) var,
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index d88738ec7cb..e327e66f6b9 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -1274,7 +1274,7 @@ generate_append_tlist(List *colTypes, List *colCollations,
static List *
generate_setop_grouplist(SetOperationStmt *op, List *targetlist)
{
- List *grouplist = (List *) copyObject(op->groupClauses);
+ List *grouplist = copyObject(op->groupClauses);
ListCell *lg;
ListCell *lt;
@@ -1879,7 +1879,7 @@ adjust_appendrel_attrs_mutator(Node *node,
rte = rt_fetch(appinfo->parent_relid,
context->root->parse->rtable);
- fields = (List *) copyObject(appinfo->translated_vars);
+ fields = copyObject(appinfo->translated_vars);
rowexpr = makeNode(RowExpr);
rowexpr->args = fields;
rowexpr->row_typeid = var->vartype;
diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c
index 5728f70c8b0..09523853d0c 100644
--- a/src/backend/optimizer/util/tlist.c
+++ b/src/backend/optimizer/util/tlist.c
@@ -51,7 +51,7 @@ static bool split_pathtarget_walker(Node *node,
* equal() to the given expression. Result is NULL if no such member.
*/
TargetEntry *
-tlist_member(Node *node, List *targetlist)
+tlist_member(Expr *node, List *targetlist)
{
ListCell *temp;
@@ -72,12 +72,12 @@ tlist_member(Node *node, List *targetlist)
* involving binary-compatible sort operations.
*/
TargetEntry *
-tlist_member_ignore_relabel(Node *node, List *targetlist)
+tlist_member_ignore_relabel(Expr *node, List *targetlist)
{
ListCell *temp;
while (node && IsA(node, RelabelType))
- node = (Node *) ((RelabelType *) node)->arg;
+ node = ((RelabelType *) node)->arg;
foreach(temp, targetlist)
{
@@ -139,7 +139,7 @@ add_to_flat_tlist(List *tlist, List *exprs)
foreach(lc, exprs)
{
- Node *expr = (Node *) lfirst(lc);
+ Expr *expr = (Expr *) lfirst(lc);
if (!tlist_member(expr, tlist))
{
@@ -762,7 +762,7 @@ apply_pathtarget_labeling_to_tlist(List *tlist, PathTarget *target)
if (expr && IsA(expr, Var))
tle = tlist_member_match_var((Var *) expr, tlist);
else
- tle = tlist_member((Node *) expr, tlist);
+ tle = tlist_member(expr, tlist);
/*
* Complain if noplace for the sortgrouprefs label, or if we'd
@@ -999,7 +999,7 @@ split_pathtarget_at_srfs(PlannerInfo *root,
foreach(lcx, input_srfs)
{
- Node *srf = (Node *) lfirst(lcx);
+ Expr *srf = (Expr *) lfirst(lcx);
if (list_member(prev_level_tlist, srf))
add_new_column_to_pathtarget(ntarget, copyObject(srf));