🌐 AI搜索 & 代理 主页
Skip to content

Commit c5ae07a

Browse files
committed
Fix usage of palloc() in MERGE/SPLIT PARTITION(s) code
f2e4cc4 and 4b3d173 implement ALTER TABLE ... MERGE/SPLIT PARTITION(s) commands. In several places, these commits use palloc(), where we should use palloc_object() and palloc_array(). This commit provides appropriate usage of palloc_object() and palloc_array(). Reported-by: Man Zeng <zengman@halodbtech.com> Discussion: https://postgr.es/m/tencent_3661BB522D5466B33EA33666%40qq.com
1 parent 4b3d173 commit c5ae07a

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/backend/commands/tablecmds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22317,7 +22317,7 @@ createTableConstraints(List **wqueue, AlteredTableInfo *tab,
2231722317
*/
2231822318
if (attribute->attgenerated == ATTRIBUTE_GENERATED_STORED)
2231922319
{
22320-
newval = (NewColumnValue *) palloc0(sizeof(NewColumnValue));
22320+
newval = palloc0_object(NewColumnValue);
2232122321
newval->attnum = num;
2232222322
newval->expr = expression_planner((Expr *) def);
2232322323
newval->is_generated = (attribute->attgenerated != '\0');
@@ -22406,7 +22406,7 @@ createTableConstraints(List **wqueue, AlteredTableInfo *tab,
2240622406
{
2240722407
NewConstraint *newcon;
2240822408

22409-
newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
22409+
newcon = palloc0_object(NewConstraint);
2241022410
newcon->name = ccon->name;
2241122411
newcon->contype = CONSTR_CHECK;
2241222412
newcon->qual = qual;
@@ -22944,7 +22944,7 @@ createSplitPartitionContext(Relation partRel)
2294422944
{
2294522945
SplitPartitionContext *pc;
2294622946

22947-
pc = (SplitPartitionContext *) palloc0(sizeof(SplitPartitionContext));
22947+
pc = palloc0_object(SplitPartitionContext);
2294822948
pc->partRel = partRel;
2294922949

2295022950
/*

src/backend/partitioning/partbounds.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5115,8 +5115,7 @@ calculate_partition_bound_for_merge(Relation parent,
51155115
int nparts = list_length(partOids);
51165116
List *bounds = NIL;
51175117

5118-
lower_bounds = (PartitionRangeBound **)
5119-
palloc0(nparts * sizeof(PartitionRangeBound *));
5118+
lower_bounds = palloc0_array(PartitionRangeBound *, nparts);
51205119

51215120
/*
51225121
* Create an array of lower bounds and a list of
@@ -5755,8 +5754,7 @@ check_partitions_for_split(Relation parent,
57555754
* Make an array new_parts with new partitions except the DEFAULT
57565755
* partition.
57575756
*/
5758-
new_parts = (SinglePartitionSpec **)
5759-
palloc0(list_length(partlist) * sizeof(SinglePartitionSpec *));
5757+
new_parts = palloc0_array(SinglePartitionSpec *, list_length(partlist));
57605758

57615759
/* isSplitPartDefault flag: is split partition a DEFAULT partition? */
57625760
isSplitPartDefault = (defaultPartOid == splitPartOid);
@@ -5786,8 +5784,7 @@ check_partitions_for_split(Relation parent,
57865784
* all partitions in ascending order of their bounds (we compare the
57875785
* lower bound only).
57885786
*/
5789-
lower_bounds = (PartitionRangeBound **)
5790-
palloc0(nparts * sizeof(PartitionRangeBound *));
5787+
lower_bounds = palloc0_array(PartitionRangeBound *, nparts);
57915788

57925789
/* Create an array of lower bounds. */
57935790
for (i = 0; i < nparts; i++)
@@ -5802,8 +5799,7 @@ check_partitions_for_split(Relation parent,
58025799

58035800
/* Reorder the array of partitions. */
58045801
tmp_new_parts = new_parts;
5805-
new_parts = (SinglePartitionSpec **)
5806-
palloc0(nparts * sizeof(SinglePartitionSpec *));
5802+
new_parts = palloc0_array(SinglePartitionSpec *, nparts);
58075803
for (i = 0; i < nparts; i++)
58085804
new_parts[i] = tmp_new_parts[lower_bounds[i]->index];
58095805

0 commit comments

Comments
 (0)