Re: BUG #16276: Server crash on an invalid attempt to attach a partition to an index

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: exclusion(at)gmail(dot)com, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16276: Server crash on an invalid attempt to attach a partition to an index
Date: 2020-02-27 08:14:28
Message-ID: CA+HiwqFziODja7kVzp5M7t2XfnUT-nxxqEse5eQ2PR4Z0JpLvQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Feb 27, 2020 at 11:31 AM Michael Paquier <michael(at)paquier(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2020-02-27 11:28:11 BUG #16280: dead tuples (probably) effect plan and query performance
Previous Message Michael Paquier 2020-02-27 02:31:20 Re: BUG #16276: Server crash on an invalid attempt to attach a partition to an index