diff options
Diffstat (limited to 'src/backend/optimizer')
24 files changed, 94 insertions, 109 deletions
diff --git a/src/backend/optimizer/geqo/geqo_erx.c b/src/backend/optimizer/geqo/geqo_erx.c index af289f7eeb7..f11a59e4a28 100644 --- a/src/backend/optimizer/geqo/geqo_erx.c +++ b/src/backend/optimizer/geqo/geqo_erx.c @@ -62,7 +62,7 @@ alloc_edge_table(PlannerInfo *root, int num_gene) * directly; 0 will not be used */ - edge_table = (Edge *) palloc((num_gene + 1) * sizeof(Edge)); + edge_table = palloc_array(Edge, num_gene + 1); return edge_table; } diff --git a/src/backend/optimizer/geqo/geqo_eval.c b/src/backend/optimizer/geqo/geqo_eval.c index 8005754c8c6..c65a31d0679 100644 --- a/src/backend/optimizer/geqo/geqo_eval.c +++ b/src/backend/optimizer/geqo/geqo_eval.c @@ -191,7 +191,7 @@ gimme_tree(PlannerInfo *root, Gene *tour, int num_gene) cur_rel_index - 1); /* Make it into a single-rel clump */ - cur_clump = (Clump *) palloc(sizeof(Clump)); + cur_clump = palloc_object(Clump); cur_clump->joinrel = cur_rel; cur_clump->size = 1; diff --git a/src/backend/optimizer/geqo/geqo_pmx.c b/src/backend/optimizer/geqo/geqo_pmx.c index 01d55711925..af1cb868391 100644 --- a/src/backend/optimizer/geqo/geqo_pmx.c +++ b/src/backend/optimizer/geqo/geqo_pmx.c @@ -48,10 +48,10 @@ void pmx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene) { - int *failed = (int *) palloc((num_gene + 1) * sizeof(int)); - int *from = (int *) palloc((num_gene + 1) * sizeof(int)); - int *indx = (int *) palloc((num_gene + 1) * sizeof(int)); - int *check_list = (int *) palloc((num_gene + 1) * sizeof(int)); + int *failed = palloc_array(int, num_gene + 1); + int *from = palloc_array(int, num_gene + 1); + int *indx = palloc_array(int, num_gene + 1); + int *check_list = palloc_array(int, num_gene + 1); int left, right, diff --git a/src/backend/optimizer/geqo/geqo_pool.c b/src/backend/optimizer/geqo/geqo_pool.c index 89e3d6a0277..d0f53d888ef 100644 --- a/src/backend/optimizer/geqo/geqo_pool.c +++ b/src/backend/optimizer/geqo/geqo_pool.c @@ -46,17 +46,17 @@ alloc_pool(PlannerInfo *root, int pool_size, int string_length) int i; /* pool */ - new_pool = (Pool *) palloc(sizeof(Pool)); + new_pool = palloc_object(Pool); new_pool->size = pool_size; new_pool->string_length = string_length; /* all chromosome */ - new_pool->data = (Chromosome *) palloc(pool_size * sizeof(Chromosome)); + new_pool->data = palloc_array(Chromosome, pool_size); /* all gene */ chromo = (Chromosome *) new_pool->data; /* vector of all chromos */ for (i = 0; i < pool_size; i++) - chromo[i].string = palloc((string_length + 1) * sizeof(Gene)); + chromo[i].string = palloc_array(Gene, string_length + 1); return new_pool; } @@ -163,8 +163,8 @@ alloc_chromo(PlannerInfo *root, int string_length) { Chromosome *chromo; - chromo = (Chromosome *) palloc(sizeof(Chromosome)); - chromo->string = (Gene *) palloc((string_length + 1) * sizeof(Gene)); + chromo = palloc_object(Chromosome); + chromo->string = palloc_array(Gene, string_length + 1); return chromo; } diff --git a/src/backend/optimizer/geqo/geqo_recombination.c b/src/backend/optimizer/geqo/geqo_recombination.c index a5d3e47ad11..41d35c179e1 100644 --- a/src/backend/optimizer/geqo/geqo_recombination.c +++ b/src/backend/optimizer/geqo/geqo_recombination.c @@ -74,7 +74,7 @@ alloc_city_table(PlannerInfo *root, int num_gene) * palloc one extra location so that nodes numbered 1..n can be indexed * directly; 0 will not be used */ - city_table = (City *) palloc((num_gene + 1) * sizeof(City)); + city_table = palloc_array(City, num_gene + 1); return city_table; } diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c index d0f516b7645..eb9b7f3eabd 100644 --- a/src/backend/optimizer/path/clausesel.c +++ b/src/backend/optimizer/path/clausesel.c @@ -495,7 +495,7 @@ addRangeClause(RangeQueryClause **rqlist, Node *clause, } /* No matching var found, so make a new clause-pair data structure */ - rqelem = (RangeQueryClause *) palloc(sizeof(RangeQueryClause)); + rqelem = palloc_object(RangeQueryClause); rqelem->var = var; if (is_lobound) { diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 5a7283bd2f5..a39cc793b4d 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -2179,7 +2179,7 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers) * whichever is less. */ arrlen = Min(parallel_workers, numpaths); - costarr = (Cost *) palloc(sizeof(Cost) * arrlen); + costarr = palloc_array(Cost, arrlen); /* The first few paths will each be claimed by a different worker. */ path_index = 0; @@ -4137,7 +4137,7 @@ cached_scansel(PlannerInfo *root, RestrictInfo *rinfo, PathKey *pathkey) /* Cache the result in suitably long-lived workspace */ oldcontext = MemoryContextSwitchTo(root->planner_cxt); - cache = (MergeScanSelCache *) palloc(sizeof(MergeScanSelCache)); + cache = palloc_object(MergeScanSelCache); cache->opfamily = pathkey->pk_opfamily; cache->collation = pathkey->pk_eclass->ec_collation; cache->cmptype = pathkey->pk_cmptype; diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 2654c59c4c6..5d4f81ee77e 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -1291,7 +1291,7 @@ group_similar_or_args(PlannerInfo *root, RelOptInfo *rel, RestrictInfo *rinfo) * which will be used to sort these arguments at the next step. */ i = -1; - matches = (OrArgIndexMatch *) palloc(sizeof(OrArgIndexMatch) * n); + matches = palloc_array(OrArgIndexMatch, n); foreach(lc, orargs) { Node *arg = lfirst(lc); @@ -1853,8 +1853,7 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel, List *paths) * same set of clauses; keep only the cheapest-to-scan of any such groups. * The surviving paths are put into an array for qsort'ing. */ - pathinfoarray = (PathClauseUsage **) - palloc(npaths * sizeof(PathClauseUsage *)); + pathinfoarray = palloc_array(PathClauseUsage *, npaths); clauselist = NIL; npaths = 0; foreach(l, paths) @@ -2090,7 +2089,7 @@ classify_index_clause_usage(Path *path, List **clauselist) Bitmapset *clauseids; ListCell *lc; - result = (PathClauseUsage *) palloc(sizeof(PathClauseUsage)); + result = palloc_object(PathClauseUsage); result->path = path; /* Recursively find the quals and preds used by the path */ diff --git a/src/backend/optimizer/path/joinrels.c b/src/backend/optimizer/path/joinrels.c index 5d1fc3899da..8827b9a5245 100644 --- a/src/backend/optimizer/path/joinrels.c +++ b/src/backend/optimizer/path/joinrels.c @@ -1990,8 +1990,7 @@ compute_partition_bounds(PlannerInfo *root, RelOptInfo *rel1, Assert(nparts > 0); joinrel->boundinfo = boundinfo; joinrel->nparts = nparts; - joinrel->part_rels = - (RelOptInfo **) palloc0(sizeof(RelOptInfo *) * nparts); + joinrel->part_rels = palloc0_array(RelOptInfo *, nparts); } else { diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c index 296a894b857..e2784c01549 100644 --- a/src/backend/optimizer/plan/analyzejoins.c +++ b/src/backend/optimizer/plan/analyzejoins.c @@ -2363,8 +2363,7 @@ remove_self_joins_recurse(PlannerInfo *root, List *joinlist, Relids toRemove) * In order to find relations with the same oid we first build an array of * candidates and then sort it by oid. */ - candidates = (SelfJoinCandidate *) palloc(sizeof(SelfJoinCandidate) * - numRels); + candidates = palloc_array(SelfJoinCandidate, numRels); i = -1; j = 0; while ((i = bms_next_member(relids, i)) >= 0) diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 8af091ba647..bc417f93840 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -2207,7 +2207,7 @@ remap_groupColIdx(PlannerInfo *root, List *groupClause) Assert(grouping_map); - new_grpColIdx = palloc0(sizeof(AttrNumber) * list_length(groupClause)); + new_grpColIdx = palloc0_array(AttrNumber, list_length(groupClause)); i = 0; foreach(lc, groupClause) @@ -2496,9 +2496,9 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path) * Convert SortGroupClause lists into arrays of attr indexes and equality * operators, as wanted by executor. */ - partColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numPart); - partOperators = (Oid *) palloc(sizeof(Oid) * numPart); - partCollations = (Oid *) palloc(sizeof(Oid) * numPart); + partColIdx = palloc_array(AttrNumber, numPart); + partOperators = palloc_array(Oid, numPart); + partCollations = palloc_array(Oid, numPart); partNumCols = 0; foreach(lc, wc->partitionClause) @@ -2513,9 +2513,9 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path) partNumCols++; } - ordColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numOrder); - ordOperators = (Oid *) palloc(sizeof(Oid) * numOrder); - ordCollations = (Oid *) palloc(sizeof(Oid) * numOrder); + ordColIdx = palloc_array(AttrNumber, numOrder); + ordOperators = palloc_array(Oid, numOrder); + ordCollations = palloc_array(Oid, numOrder); ordNumCols = 0; foreach(lc, wc->orderClause) @@ -5862,9 +5862,9 @@ make_recursive_union(List *tlist, Oid *dupCollations; ListCell *slitem; - dupColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols); - dupOperators = (Oid *) palloc(sizeof(Oid) * numCols); - dupCollations = (Oid *) palloc(sizeof(Oid) * numCols); + dupColIdx = palloc_array(AttrNumber, numCols); + dupOperators = palloc_array(Oid, numCols); + dupCollations = palloc_array(Oid, numCols); foreach(slitem, distinctList) { @@ -6694,9 +6694,9 @@ make_unique_from_pathkeys(Plan *lefttree, List *pathkeys, int numCols, * prepare_sort_from_pathkeys ... maybe unify sometime? */ Assert(numCols >= 0 && numCols <= list_length(pathkeys)); - uniqColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols); - uniqOperators = (Oid *) palloc(sizeof(Oid) * numCols); - uniqCollations = (Oid *) palloc(sizeof(Oid) * numCols); + uniqColIdx = palloc_array(AttrNumber, numCols); + uniqOperators = palloc_array(Oid, numCols); + uniqCollations = palloc_array(Oid, numCols); foreach(lc, pathkeys) { @@ -6831,10 +6831,10 @@ make_setop(SetOpCmd cmd, SetOpStrategy strategy, * convert SortGroupClause list into arrays of attr indexes and comparison * operators, as wanted by executor */ - cmpColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols); - cmpOperators = (Oid *) palloc(sizeof(Oid) * numCols); - cmpCollations = (Oid *) palloc(sizeof(Oid) * numCols); - cmpNullsFirst = (bool *) palloc(sizeof(bool) * numCols); + cmpColIdx = palloc_array(AttrNumber, numCols); + cmpOperators = palloc_array(Oid, numCols); + cmpCollations = palloc_array(Oid, numCols); + cmpNullsFirst = palloc_array(bool, numCols); foreach(slitem, groupList) { diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index 671c5cde8fc..f7f76469a2d 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -438,8 +438,7 @@ remove_useless_groupby_columns(PlannerInfo *root) * Fill groupbyattnos[k] with a bitmapset of the column attnos of RTE k * that are GROUP BY items. */ - groupbyattnos = (Bitmapset **) palloc0(sizeof(Bitmapset *) * - (list_length(parse->rtable) + 1)); + groupbyattnos = palloc0_array(Bitmapset *, list_length(parse->rtable) + 1); foreach(lc, root->processed_groupClause) { SortGroupClause *sgc = lfirst_node(SortGroupClause, lc); @@ -597,8 +596,7 @@ remove_useless_groupby_columns(PlannerInfo *root) * allocate the surplusvars[] array until we find something. */ if (surplusvars == NULL) - surplusvars = (Bitmapset **) palloc0(sizeof(Bitmapset *) * - (list_length(parse->rtable) + 1)); + surplusvars = palloc0_array(Bitmapset *, list_length(parse->rtable) + 1); /* Remember the attnos of the removable columns */ surplusvars[relid] = bms_difference(relattnos, best_keycolumns); diff --git a/src/backend/optimizer/plan/planagg.c b/src/backend/optimizer/plan/planagg.c index a2ac58d246e..1a35c269e04 100644 --- a/src/backend/optimizer/plan/planagg.c +++ b/src/backend/optimizer/plan/planagg.c @@ -336,7 +336,7 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo, * than before. (This means that when we are done, there will be no Vars * of level 1, which is why the subquery can become an initplan.) */ - subroot = (PlannerInfo *) palloc(sizeof(PlannerInfo)); + subroot = palloc_object(PlannerInfo); memcpy(subroot, root, sizeof(PlannerInfo)); subroot->query_level++; subroot->parent_root = root; diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index fd77334e5fd..8b22c30559b 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -2213,7 +2213,7 @@ preprocess_grouping_sets(PlannerInfo *root) List *sets; int maxref = 0; ListCell *lc_set; - grouping_sets_data *gd = palloc0(sizeof(grouping_sets_data)); + grouping_sets_data *gd = palloc0_object(grouping_sets_data); /* * We don't currently make any attempt to optimize the groupClause when @@ -5977,8 +5977,8 @@ select_active_windows(PlannerInfo *root, WindowFuncLists *wflists) List *result = NIL; ListCell *lc; int nActive = 0; - WindowClauseSortData *actives = palloc(sizeof(WindowClauseSortData) - * list_length(windowClause)); + WindowClauseSortData *actives = palloc_array(WindowClauseSortData, + list_length(windowClause)); /* First, construct an array of the active windows */ foreach(lc, windowClause) diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index ccdc9bc264a..cd7ea1e6b58 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -312,7 +312,7 @@ set_plan_references(PlannerInfo *root, Plan *plan) root->simple_rte_array[rc->rti] != NULL); /* flat copy is enough since all fields are scalars */ - newrc = (PlanRowMark *) palloc(sizeof(PlanRowMark)); + newrc = palloc_object(PlanRowMark); memcpy(newrc, rc, sizeof(PlanRowMark)); /* adjust indexes ... but *not* the rowmarkId */ @@ -545,7 +545,7 @@ add_rte_to_flat_rtable(PlannerGlobal *glob, List *rteperminfos, RangeTblEntry *newrte; /* flat copy to duplicate all the scalar fields */ - newrte = (RangeTblEntry *) palloc(sizeof(RangeTblEntry)); + newrte = palloc_object(RangeTblEntry); memcpy(newrte, rte, sizeof(RangeTblEntry)); /* zap unneeded sub-structure */ @@ -2028,7 +2028,7 @@ offset_relid_set(Relids relids, int rtoffset) static inline Var * copyVar(Var *var) { - Var *newvar = (Var *) palloc(sizeof(Var)); + Var *newvar = palloc_object(Var); *newvar = *var; return newvar; diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c index 7581695647d..c3b726e93e7 100644 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@ -741,7 +741,7 @@ pull_up_sublinks_jointree_recurse(PlannerInfo *root, Node *jtnode, * Make a modifiable copy of join node, but don't bother copying its * subnodes (yet). */ - j = (JoinExpr *) palloc(sizeof(JoinExpr)); + j = palloc_object(JoinExpr); memcpy(j, jtnode, sizeof(JoinExpr)); jtlink = (Node *) j; @@ -3240,8 +3240,7 @@ reduce_outer_joins_pass1(Node *jtnode) { reduce_outer_joins_pass1_state *result; - result = (reduce_outer_joins_pass1_state *) - palloc(sizeof(reduce_outer_joins_pass1_state)); + result = palloc_object(reduce_outer_joins_pass1_state); result->relids = NULL; result->contains_outer = false; result->sub_states = NIL; @@ -3593,7 +3592,7 @@ report_reduced_full_join(reduce_outer_joins_pass2_state *state2, { reduce_outer_joins_partial_state *statep; - statep = palloc(sizeof(reduce_outer_joins_partial_state)); + statep = palloc_object(reduce_outer_joins_partial_state); statep->full_join_rti = rtindex; statep->unreduced_side = relids; state2->partial_reduced = lappend(state2->partial_reduced, statep); diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index f528f096a56..a01b02f3a7b 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -1629,7 +1629,7 @@ generate_append_tlist(List *colTypes, List *colCollations, * If the inputs all agree on type and typmod of a particular column, use * that typmod; else use -1. */ - colTypmods = (int32 *) palloc(list_length(colTypes) * sizeof(int32)); + colTypmods = palloc_array(int32, list_length(colTypes)); foreach(tlistl, input_tlists) { diff --git a/src/backend/optimizer/util/appendinfo.c b/src/backend/optimizer/util/appendinfo.c index 69b8b0c2ae0..271bb4e6828 100644 --- a/src/backend/optimizer/util/appendinfo.c +++ b/src/backend/optimizer/util/appendinfo.c @@ -808,8 +808,7 @@ find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos) int i; /* Allocate an array that's certainly big enough */ - appinfos = (AppendRelInfo **) - palloc(sizeof(AppendRelInfo *) * bms_num_members(relids)); + appinfos = palloc_array(AppendRelInfo *, bms_num_members(relids)); i = -1; while ((i = bms_next_member(relids, i)) >= 0) diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index bda4c4eb292..ddafc21c819 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -239,7 +239,7 @@ contain_window_function(Node *clause) WindowFuncLists * find_window_functions(Node *clause, Index maxWinRef) { - WindowFuncLists *lists = palloc(sizeof(WindowFuncLists)); + WindowFuncLists *lists = palloc_object(WindowFuncLists); lists->numWindowFuncs = 0; lists->maxWinRef = maxWinRef; @@ -5744,8 +5744,8 @@ make_SAOP_expr(Oid oper, Node *leftexpr, Oid coltype, Oid arraycollid, get_typlenbyvalalign(coltype, &typlen, &typbyval, &typalign); - elems = (Datum *) palloc(sizeof(Datum) * list_length(exprs)); - nulls = (bool *) palloc(sizeof(bool) * list_length(exprs)); + elems = palloc_array(Datum, list_length(exprs)); + nulls = palloc_array(bool, list_length(exprs)); foreach_node(Const, value, exprs) { elems[i] = value->constvalue; diff --git a/src/backend/optimizer/util/extendplan.c b/src/backend/optimizer/util/extendplan.c index 03d32277ba1..2bc4ad32631 100644 --- a/src/backend/optimizer/util/extendplan.c +++ b/src/backend/optimizer/util/extendplan.c @@ -98,10 +98,8 @@ SetPlannerGlobalExtensionState(PlannerGlobal *glob, int extension_id, int i; i = pg_nextpower2_32(extension_id + 1); - glob->extension_state = (void **) - repalloc0(glob->extension_state, - glob->extension_state_allocated * sizeof(void *), - i * sizeof(void *)); + glob->extension_state = repalloc0_array(glob->extension_state, void *, + glob->extension_state_allocated, i); glob->extension_state_allocated = i; } @@ -134,10 +132,8 @@ SetPlannerInfoExtensionState(PlannerInfo *root, int extension_id, int i; i = pg_nextpower2_32(extension_id + 1); - root->extension_state = (void **) - repalloc0(root->extension_state, - root->extension_state_allocated * sizeof(void *), - i * sizeof(void *)); + root->extension_state = repalloc0_array(root->extension_state, void *, + root->extension_state_allocated, i); root->extension_state_allocated = i; } @@ -172,10 +168,8 @@ SetRelOptInfoExtensionState(RelOptInfo *rel, int extension_id, int i; i = pg_nextpower2_32(extension_id + 1); - rel->extension_state = (void **) - repalloc0(rel->extension_state, - rel->extension_state_allocated * sizeof(void *), - i * sizeof(void *)); + rel->extension_state = repalloc0_array(rel->extension_state, void *, + rel->extension_state_allocated, i); rel->extension_state_allocated = i; } diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index ed0dac37f51..e553afb7f01 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -279,11 +279,11 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, info->ncolumns = ncolumns = index->indnatts; info->nkeycolumns = nkeycolumns = index->indnkeyatts; - info->indexkeys = (int *) palloc(sizeof(int) * ncolumns); - info->indexcollations = (Oid *) palloc(sizeof(Oid) * nkeycolumns); - info->opfamily = (Oid *) palloc(sizeof(Oid) * nkeycolumns); - info->opcintype = (Oid *) palloc(sizeof(Oid) * nkeycolumns); - info->canreturn = (bool *) palloc(sizeof(bool) * ncolumns); + info->indexkeys = palloc_array(int, ncolumns); + info->indexcollations = palloc_array(Oid, nkeycolumns); + info->opfamily = palloc_array(Oid, nkeycolumns); + info->opcintype = palloc_array(Oid, nkeycolumns); + info->canreturn = palloc_array(bool, ncolumns); for (i = 0; i < ncolumns; i++) { @@ -336,8 +336,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, Assert(amroutine->amcanorder); info->sortopfamily = info->opfamily; - info->reverse_sort = (bool *) palloc(sizeof(bool) * nkeycolumns); - info->nulls_first = (bool *) palloc(sizeof(bool) * nkeycolumns); + info->reverse_sort = palloc_array(bool, nkeycolumns); + info->nulls_first = palloc_array(bool, nkeycolumns); for (i = 0; i < nkeycolumns; i++) { @@ -360,9 +360,9 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, * corresponding btree opfamily for each opfamily of the * other index type. */ - info->sortopfamily = (Oid *) palloc(sizeof(Oid) * nkeycolumns); - info->reverse_sort = (bool *) palloc(sizeof(bool) * nkeycolumns); - info->nulls_first = (bool *) palloc(sizeof(bool) * nkeycolumns); + info->sortopfamily = palloc_array(Oid, nkeycolumns); + info->reverse_sort = palloc_array(bool, nkeycolumns); + info->nulls_first = palloc_array(bool, nkeycolumns); for (i = 0; i < nkeycolumns; i++) { @@ -2769,32 +2769,31 @@ find_partition_scheme(PlannerInfo *root, Relation relation) * array since the relcache entry may not survive after we have closed the * relation. */ - part_scheme = (PartitionScheme) palloc0(sizeof(PartitionSchemeData)); + part_scheme = palloc0_object(PartitionSchemeData); part_scheme->strategy = partkey->strategy; part_scheme->partnatts = partkey->partnatts; - part_scheme->partopfamily = (Oid *) palloc(sizeof(Oid) * partnatts); + part_scheme->partopfamily = palloc_array(Oid, partnatts); memcpy(part_scheme->partopfamily, partkey->partopfamily, sizeof(Oid) * partnatts); - part_scheme->partopcintype = (Oid *) palloc(sizeof(Oid) * partnatts); + part_scheme->partopcintype = palloc_array(Oid, partnatts); memcpy(part_scheme->partopcintype, partkey->partopcintype, sizeof(Oid) * partnatts); - part_scheme->partcollation = (Oid *) palloc(sizeof(Oid) * partnatts); + part_scheme->partcollation = palloc_array(Oid, partnatts); memcpy(part_scheme->partcollation, partkey->partcollation, sizeof(Oid) * partnatts); - part_scheme->parttyplen = (int16 *) palloc(sizeof(int16) * partnatts); + part_scheme->parttyplen = palloc_array(int16, partnatts); memcpy(part_scheme->parttyplen, partkey->parttyplen, sizeof(int16) * partnatts); - part_scheme->parttypbyval = (bool *) palloc(sizeof(bool) * partnatts); + part_scheme->parttypbyval = palloc_array(bool, partnatts); memcpy(part_scheme->parttypbyval, partkey->parttypbyval, sizeof(bool) * partnatts); - part_scheme->partsupfunc = (FmgrInfo *) - palloc(sizeof(FmgrInfo) * partnatts); + part_scheme->partsupfunc = palloc_array(FmgrInfo, partnatts); for (i = 0; i < partnatts; i++) fmgr_info_copy(&part_scheme->partsupfunc[i], &partkey->partsupfunc[i], CurrentMemoryContext); @@ -2828,7 +2827,7 @@ set_baserel_partition_key_exprs(Relation relation, Assert(partkey != NULL); partnatts = partkey->partnatts; - partexprs = (List **) palloc(sizeof(List *) * partnatts); + partexprs = palloc_array(List *, partnatts); lc = list_head(partkey->partexprs); for (cnt = 0; cnt < partnatts; cnt++) @@ -2869,7 +2868,7 @@ set_baserel_partition_key_exprs(Relation relation, * expression lists to keep partition key expression handling code simple. * See build_joinrel_partition_info() and match_expr_to_partition_keys(). */ - rel->nullable_partexprs = (List **) palloc0(sizeof(List *) * partnatts); + rel->nullable_partexprs = palloc0_array(List *, partnatts); } /* diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c index ac28573cd0a..0a14658ed7d 100644 --- a/src/backend/optimizer/util/predtest.c +++ b/src/backend/optimizer/util/predtest.c @@ -967,7 +967,7 @@ arrayconst_startup_fn(Node *clause, PredIterInfo info) char elmalign; /* Create working state struct */ - state = (ArrayConstIterState *) palloc(sizeof(ArrayConstIterState)); + state = palloc_object(ArrayConstIterState); info->state = state; /* Deconstruct the array literal */ @@ -1046,7 +1046,7 @@ arrayexpr_startup_fn(Node *clause, PredIterInfo info) ArrayExpr *arrayexpr; /* Create working state struct */ - state = (ArrayExprIterState *) palloc(sizeof(ArrayExprIterState)); + state = palloc_object(ArrayExprIterState); info->state = state; /* Set up a dummy OpExpr to return as the per-item node */ diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index 1158bc194c3..405f4dae109 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -120,11 +120,11 @@ setup_simple_rel_arrays(PlannerInfo *root) * exist yet. It'll be filled by later calls to build_simple_rel(). */ root->simple_rel_array = (RelOptInfo **) - palloc0(size * sizeof(RelOptInfo *)); + palloc0_array(RelOptInfo *, size); /* simple_rte_array is an array equivalent of the rtable list */ root->simple_rte_array = (RangeTblEntry **) - palloc0(size * sizeof(RangeTblEntry *)); + palloc0_array(RangeTblEntry *, size); rti = 1; foreach(lc, root->parse->rtable) { @@ -141,7 +141,7 @@ setup_simple_rel_arrays(PlannerInfo *root) } root->append_rel_array = (AppendRelInfo **) - palloc0(size * sizeof(AppendRelInfo *)); + palloc0_array(AppendRelInfo *, size); /* * append_rel_array is filled with any already-existing AppendRelInfos, @@ -373,9 +373,9 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent) rel->min_attr = 0; rel->max_attr = list_length(rte->eref->colnames); rel->attr_needed = (Relids *) - palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids)); + palloc0_array(Relids, rel->max_attr - rel->min_attr + 1); rel->attr_widths = (int32 *) - palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32)); + palloc0_array(int32, rel->max_attr - rel->min_attr + 1); break; case RTE_RESULT: /* RTE_RESULT has no columns, nor could it have whole-row Var */ @@ -2486,9 +2486,8 @@ set_joinrel_partition_key_exprs(RelOptInfo *joinrel, PartitionScheme part_scheme = joinrel->part_scheme; int partnatts = part_scheme->partnatts; - joinrel->partexprs = (List **) palloc0(sizeof(List *) * partnatts); - joinrel->nullable_partexprs = - (List **) palloc0(sizeof(List *) * partnatts); + joinrel->partexprs = palloc0_array(List *, partnatts); + joinrel->nullable_partexprs = palloc0_array(List *, partnatts); /* * The joinrel's partition expressions are the same as those of the input diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c index d2b4ecc5e51..af7b19be5c7 100644 --- a/src/backend/optimizer/util/tlist.c +++ b/src/backend/optimizer/util/tlist.c @@ -467,7 +467,7 @@ extract_grouping_ops(List *groupClause) Oid *groupOperators; ListCell *glitem; - groupOperators = (Oid *) palloc(sizeof(Oid) * numCols); + groupOperators = palloc_array(Oid, numCols); foreach(glitem, groupClause) { @@ -493,7 +493,7 @@ extract_grouping_collations(List *groupClause, List *tlist) Oid *grpCollations; ListCell *glitem; - grpCollations = (Oid *) palloc(sizeof(Oid) * numCols); + grpCollations = palloc_array(Oid, numCols); foreach(glitem, groupClause) { @@ -518,7 +518,7 @@ extract_grouping_cols(List *groupClause, List *tlist) int colno = 0; ListCell *glitem; - grpColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols); + grpColIdx = palloc_array(AttrNumber, numCols); foreach(glitem, groupClause) { @@ -1089,7 +1089,7 @@ split_pathtarget_walker(Node *node, split_pathtarget_context *context) */ if (list_member(context->input_target_exprs, node)) { - split_pathtarget_item *item = palloc(sizeof(split_pathtarget_item)); + split_pathtarget_item *item = palloc_object(split_pathtarget_item); item->expr = node; item->sortgroupref = context->current_sgref; @@ -1109,7 +1109,7 @@ split_pathtarget_walker(Node *node, split_pathtarget_context *context) IsA(node, GroupingFunc) || IsA(node, WindowFunc)) { - split_pathtarget_item *item = palloc(sizeof(split_pathtarget_item)); + split_pathtarget_item *item = palloc_object(split_pathtarget_item); item->expr = node; item->sortgroupref = context->current_sgref; @@ -1124,7 +1124,7 @@ split_pathtarget_walker(Node *node, split_pathtarget_context *context) */ if (IS_SRF_CALL(node)) { - split_pathtarget_item *item = palloc(sizeof(split_pathtarget_item)); + split_pathtarget_item *item = palloc_object(split_pathtarget_item); List *save_input_vars = context->current_input_vars; List *save_input_srfs = context->current_input_srfs; int save_current_depth = context->current_depth; |
