mirror of
https://github.com/postgres/postgres.git
synced 2025-12-13 14:22:43 +03:00
Use palloc_object() and palloc_array(), the last change
This is the last batch of changes that have been suggested by the author, this part covering the non-trivial changes. Some of the changes suggested have been discarded as they seem to lead to more instructions generated, leaving the parts that can be qualified as in-place replacements. Similar work has been done in1b105f9472,0c3c5c3b06and31d3847a37. Author: David Geier <geidav.pg@gmail.com> Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
This commit is contained in:
@@ -227,7 +227,7 @@ ExecSetupPartitionTupleRouting(EState *estate, Relation rel)
|
||||
* The reason for this is that a common case is for INSERT to insert a
|
||||
* single tuple into a partitioned table and this must be fast.
|
||||
*/
|
||||
proute = (PartitionTupleRouting *) palloc0(sizeof(PartitionTupleRouting));
|
||||
proute = palloc0_object(PartitionTupleRouting);
|
||||
proute->partition_root = rel;
|
||||
proute->memcxt = CurrentMemoryContext;
|
||||
/* Rest of members initialized by zeroing */
|
||||
@@ -1198,10 +1198,8 @@ ExecInitRoutingInfo(ModifyTableState *mtstate,
|
||||
if (proute->max_partitions == 0)
|
||||
{
|
||||
proute->max_partitions = 8;
|
||||
proute->partitions = (ResultRelInfo **)
|
||||
palloc(sizeof(ResultRelInfo *) * proute->max_partitions);
|
||||
proute->is_borrowed_rel = (bool *)
|
||||
palloc(sizeof(bool) * proute->max_partitions);
|
||||
proute->partitions = palloc_array(ResultRelInfo *, proute->max_partitions);
|
||||
proute->is_borrowed_rel = palloc_array(bool, proute->max_partitions);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1316,10 +1314,8 @@ ExecInitPartitionDispatchInfo(EState *estate,
|
||||
if (proute->max_dispatch == 0)
|
||||
{
|
||||
proute->max_dispatch = 4;
|
||||
proute->partition_dispatch_info = (PartitionDispatch *)
|
||||
palloc(sizeof(PartitionDispatch) * proute->max_dispatch);
|
||||
proute->nonleaf_partitions = (ResultRelInfo **)
|
||||
palloc(sizeof(ResultRelInfo *) * proute->max_dispatch);
|
||||
proute->partition_dispatch_info = palloc_array(PartitionDispatch, proute->max_dispatch);
|
||||
proute->nonleaf_partitions = palloc_array(ResultRelInfo *, proute->max_dispatch);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2211,7 +2207,7 @@ CreatePartitionPruneState(EState *estate, PartitionPruneInfo *pruneinfo,
|
||||
* arrays are in partition bounds order.
|
||||
*/
|
||||
pprune->nparts = partdesc->nparts;
|
||||
pprune->subplan_map = palloc(sizeof(int) * partdesc->nparts);
|
||||
pprune->subplan_map = palloc_array(int, partdesc->nparts);
|
||||
|
||||
if (partdesc->nparts == pinfo->nparts &&
|
||||
memcmp(partdesc->oids, pinfo->relid_map,
|
||||
@@ -2238,8 +2234,8 @@ CreatePartitionPruneState(EState *estate, PartitionPruneInfo *pruneinfo,
|
||||
* attached. Cope with that by creating a map that skips any
|
||||
* mismatches.
|
||||
*/
|
||||
pprune->subpart_map = palloc(sizeof(int) * partdesc->nparts);
|
||||
pprune->leafpart_rti_map = palloc(sizeof(int) * partdesc->nparts);
|
||||
pprune->subpart_map = palloc_array(int, partdesc->nparts);
|
||||
pprune->leafpart_rti_map = palloc_array(int, partdesc->nparts);
|
||||
|
||||
for (pp_idx = 0; pp_idx < partdesc->nparts; pp_idx++)
|
||||
{
|
||||
@@ -2390,16 +2386,14 @@ InitPartitionPruneContext(PartitionPruneContext *context,
|
||||
context->partsupfunc = partkey->partsupfunc;
|
||||
|
||||
/* We'll look up type-specific support functions as needed */
|
||||
context->stepcmpfuncs = (FmgrInfo *)
|
||||
palloc0(sizeof(FmgrInfo) * n_steps * partnatts);
|
||||
context->stepcmpfuncs = palloc0_array(FmgrInfo, n_steps * partnatts);
|
||||
|
||||
context->ppccontext = CurrentMemoryContext;
|
||||
context->planstate = planstate;
|
||||
context->exprcontext = econtext;
|
||||
|
||||
/* Initialize expression state for each expression we need */
|
||||
context->exprstates = (ExprState **)
|
||||
palloc0(sizeof(ExprState *) * n_steps * partnatts);
|
||||
context->exprstates = palloc0_array(ExprState *, n_steps * partnatts);
|
||||
foreach(lc, pruning_steps)
|
||||
{
|
||||
PartitionPruneStepOp *step = (PartitionPruneStepOp *) lfirst(lc);
|
||||
@@ -2500,7 +2494,7 @@ InitExecPartitionPruneContexts(PartitionPruneState *prunestate,
|
||||
* indexes to new ones. For convenience of initialization, we use
|
||||
* 1-based indexes in this array and leave pruned items as 0.
|
||||
*/
|
||||
new_subplan_indexes = (int *) palloc0(sizeof(int) * n_total_subplans);
|
||||
new_subplan_indexes = palloc0_array(int, n_total_subplans);
|
||||
newidx = 1;
|
||||
i = -1;
|
||||
while ((i = bms_next_member(initially_valid_subplans, i)) >= 0)
|
||||
|
||||
@@ -246,7 +246,7 @@ make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
|
||||
* that zero can represent an un-filled array entry.
|
||||
*/
|
||||
allpartrelids = NIL;
|
||||
relid_subplan_map = palloc0(sizeof(int) * root->simple_rel_array_size);
|
||||
relid_subplan_map = palloc0_array(int, root->simple_rel_array_size);
|
||||
|
||||
i = 1;
|
||||
foreach(lc, subpaths)
|
||||
@@ -465,7 +465,7 @@ make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
|
||||
* In this phase we discover whether runtime pruning is needed at all; if
|
||||
* not, we can avoid doing further work.
|
||||
*/
|
||||
relid_subpart_map = palloc0(sizeof(int) * root->simple_rel_array_size);
|
||||
relid_subpart_map = palloc0_array(int, root->simple_rel_array_size);
|
||||
|
||||
i = 1;
|
||||
rti = -1;
|
||||
@@ -818,9 +818,8 @@ prune_append_rel_partitions(RelOptInfo *rel)
|
||||
context.boundinfo = rel->boundinfo;
|
||||
context.partcollation = rel->part_scheme->partcollation;
|
||||
context.partsupfunc = rel->part_scheme->partsupfunc;
|
||||
context.stepcmpfuncs = (FmgrInfo *) palloc0(sizeof(FmgrInfo) *
|
||||
context.partnatts *
|
||||
list_length(pruning_steps));
|
||||
context.stepcmpfuncs = palloc0_array(FmgrInfo,
|
||||
context.partnatts * list_length(pruning_steps));
|
||||
context.ppccontext = CurrentMemoryContext;
|
||||
|
||||
/* These are not valid when being called from the planner */
|
||||
@@ -1890,7 +1889,7 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
|
||||
return PARTCLAUSE_MATCH_STEPS;
|
||||
}
|
||||
|
||||
partclause = (PartClauseInfo *) palloc(sizeof(PartClauseInfo));
|
||||
partclause = palloc_object(PartClauseInfo);
|
||||
partclause->keyno = partkeyidx;
|
||||
/* Do pruning with the Boolean equality operator. */
|
||||
partclause->opno = BooleanEqualOperator;
|
||||
@@ -2147,7 +2146,7 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context,
|
||||
/*
|
||||
* Build the clause, passing the negator if applicable.
|
||||
*/
|
||||
partclause = (PartClauseInfo *) palloc(sizeof(PartClauseInfo));
|
||||
partclause = palloc_object(PartClauseInfo);
|
||||
partclause->keyno = partkeyidx;
|
||||
if (is_opne_listp)
|
||||
{
|
||||
@@ -2693,7 +2692,7 @@ get_matching_hash_bounds(PartitionPruneContext *context,
|
||||
StrategyNumber opstrategy, const Datum *values, int nvalues,
|
||||
FmgrInfo *partsupfunc, Bitmapset *nullkeys)
|
||||
{
|
||||
PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult));
|
||||
PruneStepResult *result = palloc0_object(PruneStepResult);
|
||||
PartitionBoundInfo boundinfo = context->boundinfo;
|
||||
int *partindices = boundinfo->indexes;
|
||||
int partnatts = context->partnatts;
|
||||
@@ -2770,7 +2769,7 @@ get_matching_list_bounds(PartitionPruneContext *context,
|
||||
StrategyNumber opstrategy, Datum value, int nvalues,
|
||||
FmgrInfo *partsupfunc, Bitmapset *nullkeys)
|
||||
{
|
||||
PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult));
|
||||
PruneStepResult *result = palloc0_object(PruneStepResult);
|
||||
PartitionBoundInfo boundinfo = context->boundinfo;
|
||||
int off,
|
||||
minoff,
|
||||
@@ -2981,7 +2980,7 @@ get_matching_range_bounds(PartitionPruneContext *context,
|
||||
StrategyNumber opstrategy, const Datum *values, int nvalues,
|
||||
FmgrInfo *partsupfunc, Bitmapset *nullkeys)
|
||||
{
|
||||
PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult));
|
||||
PruneStepResult *result = palloc0_object(PruneStepResult);
|
||||
PartitionBoundInfo boundinfo = context->boundinfo;
|
||||
Oid *partcollation = context->partcollation;
|
||||
int partnatts = context->partnatts;
|
||||
@@ -3504,7 +3503,7 @@ perform_pruning_base_step(PartitionPruneContext *context,
|
||||
{
|
||||
PruneStepResult *result;
|
||||
|
||||
result = (PruneStepResult *) palloc(sizeof(PruneStepResult));
|
||||
result = palloc_object(PruneStepResult);
|
||||
result->bound_offsets = NULL;
|
||||
result->scan_default = false;
|
||||
result->scan_null = false;
|
||||
@@ -3593,7 +3592,7 @@ perform_pruning_combine_step(PartitionPruneContext *context,
|
||||
PartitionPruneStepCombine *cstep,
|
||||
PruneStepResult **step_results)
|
||||
{
|
||||
PruneStepResult *result = (PruneStepResult *) palloc0(sizeof(PruneStepResult));
|
||||
PruneStepResult *result = palloc0_object(PruneStepResult);
|
||||
bool firststep;
|
||||
ListCell *lc1;
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ statext_ndistinct_build(double totalrows, StatsBuildData *data)
|
||||
MVNDistinctItem *item = &result->items[itemcnt];
|
||||
int j;
|
||||
|
||||
item->attributes = palloc(sizeof(AttrNumber) * k);
|
||||
item->attributes = palloc_array(AttrNumber, k);
|
||||
item->nattributes = k;
|
||||
|
||||
/* translate the indexes to attnums */
|
||||
@@ -359,9 +359,9 @@ ndistinct_for_combination(double totalrows, StatsBuildData *data,
|
||||
* using the specified column combination as dimensions. We could try to
|
||||
* sort in place, but it'd probably be more complex and bug-prone.
|
||||
*/
|
||||
items = (SortItem *) palloc(numrows * sizeof(SortItem));
|
||||
values = (Datum *) palloc0(sizeof(Datum) * numrows * k);
|
||||
isnull = (bool *) palloc0(sizeof(bool) * numrows * k);
|
||||
items = palloc_array(SortItem, numrows);
|
||||
values = palloc0_array(Datum, numrows * k);
|
||||
isnull = palloc0_array(bool, numrows * k);
|
||||
|
||||
for (i = 0; i < numrows; i++)
|
||||
{
|
||||
@@ -508,12 +508,12 @@ generator_init(int n, int k)
|
||||
Assert((n >= k) && (k > 0));
|
||||
|
||||
/* allocate the generator state as a single chunk of memory */
|
||||
state = (CombinationGenerator *) palloc(sizeof(CombinationGenerator));
|
||||
state = palloc_object(CombinationGenerator);
|
||||
|
||||
state->ncombinations = n_choose_k(n, k);
|
||||
|
||||
/* pre-allocate space for all combinations */
|
||||
state->combinations = (int *) palloc(sizeof(int) * k * state->ncombinations);
|
||||
state->combinations = palloc_array(int, k * state->ncombinations);
|
||||
|
||||
state->current = 0;
|
||||
state->k = k;
|
||||
@@ -606,7 +606,7 @@ generate_combinations_recurse(CombinationGenerator *state,
|
||||
static void
|
||||
generate_combinations(CombinationGenerator *state)
|
||||
{
|
||||
int *current = (int *) palloc0(sizeof(int) * state->k);
|
||||
int *current = palloc0_array(int, state->k);
|
||||
|
||||
generate_combinations_recurse(state, 0, 0, current);
|
||||
|
||||
|
||||
@@ -4676,7 +4676,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
|
||||
if (nlocators == 0)
|
||||
return;
|
||||
|
||||
rels = palloc(sizeof(SMgrRelation) * nlocators); /* non-local relations */
|
||||
rels = palloc_array(SMgrRelation, nlocators); /* non-local relations */
|
||||
|
||||
/* If it's a local relation, it's localbuf.c's problem. */
|
||||
for (i = 0; i < nlocators; i++)
|
||||
@@ -4758,7 +4758,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
|
||||
}
|
||||
|
||||
pfree(block);
|
||||
locators = palloc(sizeof(RelFileLocator) * n); /* non-local relations */
|
||||
locators = palloc_array(RelFileLocator, n); /* non-local relations */
|
||||
for (i = 0; i < n; i++)
|
||||
locators[i] = rels[i]->smgr_rlocator.locator;
|
||||
|
||||
@@ -5037,7 +5037,7 @@ FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
|
||||
return;
|
||||
|
||||
/* fill-in array for qsort */
|
||||
srels = palloc(sizeof(SMgrSortArray) * nrels);
|
||||
srels = palloc_array(SMgrSortArray, nrels);
|
||||
|
||||
for (i = 0; i < nrels; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user