Re: CREATE INDEX CONCURRENTLY on partitioned index

From: Alexander Pyhalov <a(dot)pyhalov(at)postgrespro(dot)ru>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: Ilya Gladyshev <ilya(dot)v(dot)gladyshev(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, 李杰(慎追) <adger(dot)lj(at)alibaba-inc(dot)com>, 曾文旌(义从) <wenjing(dot)zwj(at)alibaba-inc(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Subject: Re: CREATE INDEX CONCURRENTLY on partitioned index
Date: 2023-07-13 06:49:42
Message-ID: 37d3f0a984a15f6465b83027eed8c588@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Justin Pryzby писал 2023-07-13 05:27:
> On Mon, Mar 27, 2023 at 01:28:24PM +0300, Alexander Pyhalov wrote:
>> Justin Pryzby писал 2023-03-26 17:51:
>> > On Sun, Dec 04, 2022 at 01:09:35PM -0600, Justin Pryzby wrote:
>> > > This currently handles partitions with a loop around the whole CIC
>> > > implementation, which means that things like WaitForLockers() happen
>> > > once for each index, the same as REINDEX CONCURRENTLY on a partitioned
>> > > table. Contrast that with ReindexRelationConcurrently(), which handles
>> > > all the indexes on a table in one pass by looping around indexes within
>> > > each phase.
>> >
>> > Rebased over the progress reporting fix (27f5c712b).
>> >
>> > I added a list of (intermediate) partitioned tables, rather than looping
>> > over the list of inheritors again, to save calling rel_get_relkind().
>> >
>> > I think this patch is done.
>>
>> Overall looks good to me. However, I think that using 'partitioned' as
>> list
>> of partitioned index oids in DefineIndex() is a bit misleading - we've
>> just
>> used it as boolean, specifying if we are dealing with a partitioned
>> relation.
>
> Right. This is also rebased on 8c852ba9a4 (Allow some exclusion
> constraints on partitions).

Hi.
I have some more question.
In the following code (indexcmds.c:1640 and later)

1640 rel = table_open(relationId,
ShareUpdateExclusiveLock);
1641 heaprelid = rel->rd_lockInfo.lockRelId;
1642 table_close(rel, ShareUpdateExclusiveLock);
1643 SET_LOCKTAG_RELATION(heaplocktag,
heaprelid.dbId, heaprelid.relId);

should we release ShareUpdateExclusiveLock before getting session lock
in DefineIndexConcurrentInternal()?
Also we unlock parent table there between reindexing childs in the end
of DefineIndexConcurrentInternal():

1875 /*
1876 * Last thing to do is release the session-level lock on
the parent table.
1877 */
1878 UnlockRelationIdForSession(&heaprelid,
ShareUpdateExclusiveLock);
1879 }

Is it safe? Shouldn't we hold session lock on the parent table while
rebuilding child indexes?

--
Best regards,
Alexander Pyhalov,
Postgres Professional

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2023-07-13 06:58:56 Re: The same 2PC data maybe recovered twice
Previous Message Michael Paquier 2023-07-13 05:39:32 Re: add non-option reordering to in-tree getopt_long