Re: BUG #16276: Server crash on an invalid attempt to attach apartition to an index - Mailing list pgsql-bugs

From Amit Langote
Subject Re: BUG #16276: Server crash on an invalid attempt to attach apartition to an index
Date
Msg-id CA+HiwqFziODja7kVzp5M7t2XfnUT-nxxqEse5eQ2PR4Z0JpLvQ@mail.gmail.com
Whole thread Raw
In response to Re: BUG #16276: Server crash on an invalid attempt to attach apartition to an index  (Michael Paquier <michael@paquier.xyz>)
Responses Re: BUG #16276: Server crash on an invalid attempt to attach apartition to an index  (Michael Paquier <michael@paquier.xyz>)
List pgsql-bugs
On Thu, Feb 27, 2020 at 11:31 AM Michael Paquier <michael@paquier.xyz> wrote:
> On Wed, Feb 26, 2020 at 05:06:24PM +0900, Michael Paquier wrote:
> > Attempting to attach a table to a partitioned index?  Nice thought.
> > Without the assertion, RangeVarCallbackForAttachIndex complains that
> > the relation is not an index, which is right, so I would be tempted to
> > just remove the culprit assertion.  Any thoughts?
>
> FWIW, one can note that ALTER TABLE ATTACH PARTITION with indexes
> correctly registers partition indexes without partition bounds in
> pg_class, even if the grammar cannot accept ALTER TABLE without any
> bounds defined:
> create table idxpart(a int) partition by list (a);
> create table idxpart1 partition of idxpart for values in (1);
> create index idxpart_idx on only idxpart(a);
> create index idxpart1_idx on only idxpart1(a);
> alter table idxpart_idx attach partition idxpart1_idx for values in (0);
>
> So I would rather not issue an error in that case on compatibility
> ground.

Simply dropping the culprit assertion might be enough for
back-branches, but it seems misleading to silently ignore the bound
IMO.  Maybe, report an error in newer versions, as follows:

@@ -3698,8 +3698,17 @@ transformPartitionCmd(CreateStmtContext *cxt,
PartitionCmd *cmd)
                                                          cmd->bound);
             break;
         case RELKIND_PARTITIONED_INDEX:
-            /* nothing to check */
-            Assert(cmd->bound == NULL);
+            /*
+             * ALTER INDEX, which does not allow partition bound to be
+             * specified, must be used when trying to attach partition of an
+             * index.
+             */
+            if (cmd->bound != NULL)
+                ereport(ERROR,
+                        (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+                         errmsg("\"%s\" is not a partitioned table",
+                                RelationGetRelationName(parentRel)),
+                         errhint("Use ALTER INDEX to attach index
partition.")));

?

So,

create table idxpart(a int) partition by list (a);
create index idxpart_idx on idxpart (a);
create table idxpart1(a int);
alter table idxpart_idx attach partition idxpart1 for values in (0);
ERROR:  "idxpart_idx" is not a partitioned table
HINT:  Use ALTER INDEX to attach index partition.

Thanks,
Amit



pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #16276: Server crash on an invalid attempt to attach apartition to an index
Next
From: PG Bug reporting form
Date:
Subject: BUG #16280: dead tuples (probably) effect plan and query performance