AT detach partition is broken

Started by Amit Langoteabout 9 years ago4 messageshackers
Jump to latest
#1Amit Langote
Langote_Amit_f8@lab.ntt.co.jp

I noticed that running ALTER TABLE table_name DETACH PARTITION crashes, if
table_name is not a partitioned table. That's because of an Assert in
ATExecDetachPartition(). We really should error out much sooner in this
case, IOW during transformAlterTableStmt(), as is done in the case of
ATTACH PARTITION.

Attached patch fixes that.

Thanks,
Amit

Attachments:

0001-Unbreak-ALTER-TABLE-DETACH-PARTITION.patchtext/x-diff; name=0001-Unbreak-ALTER-TABLE-DETACH-PARTITION.patchDownload+29-11
#2Robert Haas
robertmhaas@gmail.com
In reply to: Amit Langote (#1)
Re: AT detach partition is broken

On Mon, Feb 13, 2017 at 2:30 AM, Amit Langote
<Langote_Amit_f8@lab.ntt.co.jp> wrote:

I noticed that running ALTER TABLE table_name DETACH PARTITION crashes, if
table_name is not a partitioned table. That's because of an Assert in
ATExecDetachPartition(). We really should error out much sooner in this
case, IOW during transformAlterTableStmt(), as is done in the case of
ATTACH PARTITION.

Attached patch fixes that.

-                    /* assign transformed values */
-                    partcmd->bound = cxt.partbound;
+                    /*
+                     * Assign transformed value of the partition bound, if
+                     * any.
+                     */
+                    if (cxt.partbound != NULL)
+                        partcmd->bound = cxt.partbound;

This hunk isn't really needed, is it? I mean, if cxt.partbound comes
out NULL, then partcmd->bound will be NULL with or without adding an
"if" here, won't it?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Robert Haas (#2)
Re: AT detach partition is broken

On 2017/02/15 2:37, Robert Haas wrote:

On Mon, Feb 13, 2017 at 2:30 AM, Amit Langote
<Langote_Amit_f8@lab.ntt.co.jp> wrote:

I noticed that running ALTER TABLE table_name DETACH PARTITION crashes, if
table_name is not a partitioned table. That's because of an Assert in
ATExecDetachPartition(). We really should error out much sooner in this
case, IOW during transformAlterTableStmt(), as is done in the case of
ATTACH PARTITION.

Attached patch fixes that.

-                    /* assign transformed values */
-                    partcmd->bound = cxt.partbound;
+                    /*
+                     * Assign transformed value of the partition bound, if
+                     * any.
+                     */
+                    if (cxt.partbound != NULL)
+                        partcmd->bound = cxt.partbound;

This hunk isn't really needed, is it? I mean, if cxt.partbound comes
out NULL, then partcmd->bound will be NULL with or without adding an
"if" here, won't it?

You're right. Took this one out (except slightly tweaking the comment) in
the attached updated patch.

Thanks,
Amit

Attachments:

0001-Unbreak-ALTER-TABLE-DETACH-PARTITION.patchtext/x-diff; name=0001-Unbreak-ALTER-TABLE-DETACH-PARTITION.patchDownload+24-11
#4Robert Haas
robertmhaas@gmail.com
In reply to: Amit Langote (#3)
Re: AT detach partition is broken

On Wed, Feb 15, 2017 at 7:45 PM, Amit Langote
<Langote_Amit_f8@lab.ntt.co.jp> wrote:

You're right. Took this one out (except slightly tweaking the comment) in
the attached updated patch.

Committed after tweaking the other comment in that function.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers