Re: BUG #17997: Assert failed in validatePartitionedIndex() when attaching partition index to child of valid index

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17997: Assert failed in validatePartitionedIndex() when attaching partition index to child of valid index
Date: 2023-06-26 08:05:37
Message-ID: ZJlG0a/F03iPI/wj@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Jun 26, 2023 at 03:49:05PM +0900, Michael Paquier wrote:
> It seems to me that there are two potential solutions here:
> 1) We could recurse and make sure that the index of t *also* becomes
> *invalid*, because t_a_idx and tp1_a_idx form a partition chain, still
> the leaf tp1_1 does *not* have an index yet, making it unusable.
> 2) Then I found about AttachPartitionEnsureIndexes(). This is called
> when attaching a partition to make sure that indexes are created to
> match the indexes between the partitioned table and the new partition
> attached to it, but it does not recurse when attaching a partitioned
> table, or an index would have been created on tp1_1 when running the
> 6th command to complete the index tree all the way down.
>
> At the end, I'd like to think that 2) is the right path forward. For
> example, this creates a partitioned index automatically when attaching
> a partition:
> create table t(a int) partition by range (a);
> create index on t(a);
> create table tp1(a int) partition by range (a);
> alter table t attach partition tp1 for values from (1) to (100);
> =# \di
> List of relations
> Schema | Name | Type | Owner | Table
> --------+-----------+-------------------+--------+-------
> public | t_a_idx | partitioned index | popopo | t
> public | tp1_a_idx | partitioned index | popopo | tp1
> (2 rows)

A third solution that came into my mind just now would be to revisit
the choice done in AttachPartitionEnsureIndexes() where an invalid
index can be chosen as a match when creating the indexes on the
partitions, so as we are able to get to the bottom of a chain with
valid indexes for the whole tree. I have been testing the attached
and it has been working here the way I'd expect when manipulating
partition trees with ATTACH PARTITION, though this breaks the scenario
of this bug report because we would now get a failure when attempting
to attach an index in the last command.

Thoughts or comments?
--
Michael

Attachment Content-Type Size
0001-Fix-ATTACH-PARTITION-to-ignore-invalid-indexes-as-ma.patch text/x-diff 5.0 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2023-06-26 08:35:44 Re: BUG #18000: Access method used by matview can be dropped leaving broken matview
Previous Message Heikki Linnakangas 2023-06-26 08:04:26 Re: BUG #17949: Adding an index introduces serialisation anomalies.