public inbox for [email protected]
help / color / mirror / Atom feedFrom: Alexander Korotkov <[email protected]>
To: zengman <[email protected]>
Cc: Stéphane Tachoires <[email protected]>
Cc: Dmitry Koval <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date: Sun, 14 Dec 2025 15:47:34 +0200
Message-ID: <CAPpHfdvt64X0F3thjC0q9vOTU-JqG2M_MJfEeA2-_=odNOA3Dg@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org>
<CAPpHfdsh_jPZ6-2JtWoFeZravVQYY4cYCcnKXQW6KxEx+F5vxg@mail.gmail.com>
<[email protected]>
<CACJufxF1Hfx1PST7pCLrKkGcjHEn2A51znXmYwVccnt5GDORcw@mail.gmail.com>
<[email protected]>
<[email protected]>
<[email protected]>
<CACJufxET9Qe-=zJtjGrKPr7-1QbVcP9y-vJU9CMEDfPGt_dbyg@mail.gmail.com>
<[email protected]>
<CACJufxEBvrtcOWyX2NMwOCvb2ZvaRGaGeiMQpUD=yxL6ncBFOg@mail.gmail.com>
<[email protected]>
<CAPpHfdvSBR+sbsRCAybN949tOGArQvMH2QeDXf2L=7NDMNbJfw@mail.gmail.com>
<[email protected]>
<CAPpHfduQwwa4ytK-dGjRGN0fTWfpWNNysYuUKrOetsyGioBMfA@mail.gmail.com>
<[email protected]>
<CAPpHfdvpzezTnuumpdJYge=x1TbhgAkjMGh2GHnScf5SFsf2ew@mail.gmail.com>
<[email protected]>
<CAPpHfdtBH5YhAiKhXPcLAE4CCRMaGKqupzx8u2RKEm2aQ_e3Xw@mail.gmail.com>
<CA+gpmfLSELzEKEzSFXeLkRRMGkRfm2+7ewXHyW-8ZWPbWOywyg@mail.gmail.com>
<CAPpHfdtnWkesztu4qq1m8RfuR2OYXd5tbPyaHk-3Db2szWrb=Q@mail.gmail.com>
<CAPpHfdta0DMb3XjePJJWf1xbAndE8w2uYPaWEOFBGQ=xsDkfiQ@mail.gmail.com>
<[email protected]>
Hi Man,
On Sun, Dec 14, 2025 at 2:51 PM zengman <[email protected]> wrote:
> I just noticed two relatively large commits. I recall that not long ago we started attempting to adopt `palloc_object` and `palloc_array` in many places,
> yet in these two commits, some sections have used the new approach while others have not.
> Perhaps we could standardize the coding style for consistency.
>
> src/backend/commands/tablecmds.c
> src/backend/partitioning/partbounds.c
Could you, please, check the attached patch?
------
Regards,
Alexander Korotkov
Supabase
Attachments:
[application/octet-stream] v1-0001-Fix-usage-of-palloc-in-MERGE-SPLIT-PARTITION-s-co.patch (3.8K, ../CAPpHfdvt64X0F3thjC0q9vOTU-JqG2M_MJfEeA2-_=odNOA3Dg@mail.gmail.com/2-v1-0001-Fix-usage-of-palloc-in-MERGE-SPLIT-PARTITION-s-co.patch)
download | inline diff:
From b964df0852b32c046cf2f298bbd0d528be85f48a Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <[email protected]>
Date: Sun, 14 Dec 2025 15:40:45 +0200
Subject: [PATCH v1] Fix usage of palloc() in MERGE/SPLIT PARTITION(s) code
f2e4cc427951 and 4b3d173629f4 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 <[email protected]>
Discussion: https://postgr.es/m/tencent_3661BB522D5466B33EA33666%40qq.com
---
src/backend/commands/tablecmds.c | 6 +++---
src/backend/partitioning/partbounds.c | 12 ++++--------
2 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 953fadb9c6b..7550ee7c164 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -22317,7 +22317,7 @@ createTableConstraints(List **wqueue, AlteredTableInfo *tab,
*/
if (attribute->attgenerated == ATTRIBUTE_GENERATED_STORED)
{
- newval = (NewColumnValue *) palloc0(sizeof(NewColumnValue));
+ newval = palloc0_object(NewColumnValue);
newval->attnum = num;
newval->expr = expression_planner((Expr *) def);
newval->is_generated = (attribute->attgenerated != '\0');
@@ -22406,7 +22406,7 @@ createTableConstraints(List **wqueue, AlteredTableInfo *tab,
{
NewConstraint *newcon;
- newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
+ newcon = palloc0_object(NewConstraint);
newcon->name = ccon->name;
newcon->contype = CONSTR_CHECK;
newcon->qual = qual;
@@ -22944,7 +22944,7 @@ createSplitPartitionContext(Relation partRel)
{
SplitPartitionContext *pc;
- pc = (SplitPartitionContext *) palloc0(sizeof(SplitPartitionContext));
+ pc = palloc0_object(SplitPartitionContext);
pc->partRel = partRel;
/*
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index b7f90ae109d..16b0adc172c 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -5115,8 +5115,7 @@ calculate_partition_bound_for_merge(Relation parent,
int nparts = list_length(partOids);
List *bounds = NIL;
- lower_bounds = (PartitionRangeBound **)
- palloc0(nparts * sizeof(PartitionRangeBound *));
+ lower_bounds = palloc0_array(PartitionRangeBound *, nparts);
/*
* Create an array of lower bounds and a list of
@@ -5755,8 +5754,7 @@ check_partitions_for_split(Relation parent,
* Make an array new_parts with new partitions except the DEFAULT
* partition.
*/
- new_parts = (SinglePartitionSpec **)
- palloc0(list_length(partlist) * sizeof(SinglePartitionSpec *));
+ new_parts = palloc0_array(SinglePartitionSpec *, list_length(partlist));
/* isSplitPartDefault flag: is split partition a DEFAULT partition? */
isSplitPartDefault = (defaultPartOid == splitPartOid);
@@ -5786,8 +5784,7 @@ check_partitions_for_split(Relation parent,
* all partitions in ascending order of their bounds (we compare the
* lower bound only).
*/
- lower_bounds = (PartitionRangeBound **)
- palloc0(nparts * sizeof(PartitionRangeBound *));
+ lower_bounds = palloc0_array(PartitionRangeBound *, nparts);
/* Create an array of lower bounds. */
for (i = 0; i < nparts; i++)
@@ -5802,8 +5799,7 @@ check_partitions_for_split(Relation parent,
/* Reorder the array of partitions. */
tmp_new_parts = new_parts;
- new_parts = (SinglePartitionSpec **)
- palloc0(nparts * sizeof(SinglePartitionSpec *));
+ new_parts = palloc0_array(SinglePartitionSpec *, nparts);
for (i = 0; i < nparts; i++)
new_parts[i] = tmp_new_parts[lower_bounds[i]->index];
--
2.39.5 (Apple Git-154)
view thread (165+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
In-Reply-To: <CAPpHfdvt64X0F3thjC0q9vOTU-JqG2M_MJfEeA2-_=odNOA3Dg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox