pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Index drops during phase 1 of REINDEX CONCURRENTLY
6+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2026-11-20 d94964f14f 4139fc83f4 9e612947ea 116bd1a912 435fa54b0d e5b33ff451  Pin relations in phase 1 of REINDEX CONCURRENTLY
* Index drops during phase 1 of REINDEX CONCURRENTLY
@ 2026-11-14 00:31 Michael Paquier <michael@paquier.xyz>
  2026-11-14 05:42 ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Ayush Tiwari <ayushtiwari.slg01@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Michael Paquier @ 2026-11-14 00:31 UTC (permalink / raw)
  To: Postgres hackers <pgsql-hackers@lists.postgresql.org>

Hi all,

Some of the feedback I got after f24a08ec13eb involved the fact that
indexes could also be dropped during the phase 1 of REINDEX
CONCURRENTLY when the expressions or predicates are evaluated.  The
damage is limited to cache lookup failures or assertion hits during
phase 2, thanks to the protections that f24a08ec13eb has added.

Anyway, it would be nice to fix this issue.  Attached is a patch
addressing the problem with a test, for a backpatch down to v15.

Thoughts or objections?
--
Michael

Attachments:

0001-Pin-relations-during-phase-1-of-REINDEX-CONCURRENTLY.patch (text/plain, 7.9K) download From 67a2c319cc3f83b670241f5440fdbab4ccb8ccfa Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@paquier.xyz> Date: Sat, 14 Nov 2026 09:20:12 +0900 Subject: [PATCH] Pin relations during phase 1 of REINDEX CONCURRENTLY Phase 1 of ReindexRelationConcurrently() (creation of the new indexes) evaluates index expressions and predicates when computing the safety of each index and when creating the definition of each new index. These may call functions run as the table owner. The old and new indexes processed in the previous iterations of the loop were closed at this stage. Hence, a function was able to drop one of them or reindex one of the new indexes, leading to an assertion failure in the build phase, or to an internal error due to a dropped index. The relations opened in phase 1 are now kept pinned until the session locks are taken, so as DDLs on them are blocked by CheckTableNotInUse(). The build and validation phases were already pinning the relations. Author: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/TODO Backpatch-through: 15 --- src/backend/commands/indexcmds.c | 16 ++++++++-- src/test/regress/expected/create_index.out | 37 +++++++++++++++++++++- src/test/regress/sql/create_index.sql | 26 ++++++++++++++- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 68fc87b76a0e..8414b8037222 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -3790,6 +3790,7 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein List *indexIds = NIL; List *newIndexIds = NIL; List *relationLocks = NIL; + List *phase1Rels = NIL; List *lockTags = NIL; ListCell *lc, *lc2; @@ -4215,8 +4216,13 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein MemoryContextSwitchTo(oldcontext); - index_close(indexRel, NoLock); - index_close(newIndexRel, NoLock); + /* + * Index expressions and predicates of the indexes processed in the + * next iterations are evaluated in this loop, so keep the relations + * opened until all the new indexes are created. + */ + phase1Rels = lappend(phase1Rels, indexRel); + phase1Rels = lappend(phase1Rels, newIndexRel); /* Roll back any GUC changes executed by index functions */ AtEOXact_GUC(false, save_nestlevel); @@ -4224,7 +4230,7 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein /* Restore userid and security context */ SetUserIdAndSecContext(save_userid, save_sec_context); - table_close(heapRel, NoLock); + phase1Rels = lappend(phase1Rels, heapRel); /* * If a statement is available, telling that this comes from a REINDEX @@ -4279,6 +4285,10 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein LockRelationIdForSession(lockrelid, ShareUpdateExclusiveLock); } + /* Session locks are taken, release the relations opened in phase 1 */ + ReindexUnpinRelations(phase1Rels); + phase1Rels = NIL; + PopActiveSnapshot(); CommitTransactionCommand(); StartTransactionCommand(); diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out index e914c809b820..857603cd2b4f 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -2878,7 +2878,8 @@ Indexes: DROP TABLE concur_appclass_tab; -- Check that a function called from an index expression is not able to --- manipulate a relation involved in the operation. +-- manipulate a relation involved in the operation. This involves phase 2 of +-- REINDEX CONCURRENTLY. CREATE TABLE concur_reindex_ddl_tab (i int); INSERT INTO concur_reindex_ddl_tab VALUES (1); -- Use two functions, one volatile called in a second, immutable, one. @@ -2901,6 +2902,40 @@ REINDEX INDEX CONCURRENTLY concur_reindex_ddl_ind2; -- ok REINDEX INDEX CONCURRENTLY concur_reindex_ddl_ind1; -- ok REINDEX INDEX CONCURRENTLY concur_reindex_ddl_ind2; -- dropped ERROR: relation "concur_reindex_ddl_ind2" does not exist +DROP TABLE concur_reindex_ddl_tab; +DROP FUNCTION concur_reindex_ddl_im(int); +DROP FUNCTION concur_reindex_ddl_f(); +-- Same, with the function called when the index definitions are created. +-- This involves phase 1 of REINDEX CONCURRENTLY. +CREATE TABLE concur_reindex_ddl_tab (i int); +INSERT INTO concur_reindex_ddl_tab VALUES (1); +CREATE FUNCTION concur_reindex_ddl_f() RETURNS void LANGUAGE plpgsql AS + 'begin end'; +CREATE FUNCTION concur_reindex_ddl_im(int) RETURNS int + LANGUAGE plpgsql IMMUTABLE AS + 'begin perform public.concur_reindex_ddl_f(); return $1; end'; +CREATE INDEX concur_reindex_ddl_ind1 ON concur_reindex_ddl_tab (i); +CREATE INDEX concur_reindex_ddl_ind2 ON + concur_reindex_ddl_tab ((i + concur_reindex_ddl_im(0))); +CREATE OR REPLACE FUNCTION concur_reindex_ddl_f() RETURNS void + LANGUAGE plpgsql AS + 'begin DROP INDEX public.concur_reindex_ddl_ind1; end'; +REINDEX TABLE CONCURRENTLY concur_reindex_ddl_tab; -- error +ERROR: cannot DROP INDEX "concur_reindex_ddl_ind1" because it is being used by active queries in this session +CONTEXT: SQL statement "DROP INDEX public.concur_reindex_ddl_ind1" +PL/pgSQL function concur_reindex_ddl_f() line 1 at SQL statement +SQL statement "SELECT public.concur_reindex_ddl_f()" +PL/pgSQL function concur_reindex_ddl_im(integer) line 1 at PERFORM +SELECT c.relname, i.indisvalid FROM pg_index i + JOIN pg_class c ON c.oid = i.indexrelid + WHERE i.indrelid = 'concur_reindex_ddl_tab'::regclass + ORDER BY c.relname COLLATE "C"; + relname | indisvalid +-------------------------+------------ + concur_reindex_ddl_ind1 | t + concur_reindex_ddl_ind2 | t +(2 rows) + DROP TABLE concur_reindex_ddl_tab; DROP FUNCTION concur_reindex_ddl_im(int); DROP FUNCTION concur_reindex_ddl_f(); diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql index e4b8cee1e1c2..27e038fa8087 100644 --- a/src/test/regress/sql/create_index.sql +++ b/src/test/regress/sql/create_index.sql @@ -1144,7 +1144,8 @@ REINDEX TABLE CONCURRENTLY concur_appclass_tab; DROP TABLE concur_appclass_tab; -- Check that a function called from an index expression is not able to --- manipulate a relation involved in the operation. +-- manipulate a relation involved in the operation. This involves phase 2 of +-- REINDEX CONCURRENTLY. CREATE TABLE concur_reindex_ddl_tab (i int); INSERT INTO concur_reindex_ddl_tab VALUES (1); -- Use two functions, one volatile called in a second, immutable, one. @@ -1163,6 +1164,29 @@ REINDEX INDEX CONCURRENTLY concur_reindex_ddl_ind2; -- dropped DROP TABLE concur_reindex_ddl_tab; DROP FUNCTION concur_reindex_ddl_im(int); DROP FUNCTION concur_reindex_ddl_f(); +-- Same, with the function called when the index definitions are created. +-- This involves phase 1 of REINDEX CONCURRENTLY. +CREATE TABLE concur_reindex_ddl_tab (i int); +INSERT INTO concur_reindex_ddl_tab VALUES (1); +CREATE FUNCTION concur_reindex_ddl_f() RETURNS void LANGUAGE plpgsql AS + 'begin end'; +CREATE FUNCTION concur_reindex_ddl_im(int) RETURNS int + LANGUAGE plpgsql IMMUTABLE AS + 'begin perform public.concur_reindex_ddl_f(); return $1; end'; +CREATE INDEX concur_reindex_ddl_ind1 ON concur_reindex_ddl_tab (i); +CREATE INDEX concur_reindex_ddl_ind2 ON + concur_reindex_ddl_tab ((i + concur_reindex_ddl_im(0))); +CREATE OR REPLACE FUNCTION concur_reindex_ddl_f() RETURNS void + LANGUAGE plpgsql AS + 'begin DROP INDEX public.concur_reindex_ddl_ind1; end'; +REINDEX TABLE CONCURRENTLY concur_reindex_ddl_tab; -- error +SELECT c.relname, i.indisvalid FROM pg_index i + JOIN pg_class c ON c.oid = i.indexrelid + WHERE i.indrelid = 'concur_reindex_ddl_tab'::regclass + ORDER BY c.relname COLLATE "C"; +DROP TABLE concur_reindex_ddl_tab; +DROP FUNCTION concur_reindex_ddl_im(int); +DROP FUNCTION concur_reindex_ddl_f(); -- Partitions -- Create some partitioned tables -- 2.56.0
signature.asc (application/pgp-signature, 832B) download ^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: Index drops during phase 1 of REINDEX CONCURRENTLY
  2026-11-14 00:31 Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
@ 2026-11-14 05:42 ` Ayush Tiwari <ayushtiwari.slg01@gmail.com>
  2026-11-15 04:22   ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY shihao zhong <zhong950419@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Ayush Tiwari @ 2026-11-14 05:42 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>

Hi,

On Sat, 14 Nov 2026 at 06:02, Michael Paquier <michael@paquier.xyz> wrote:
>
> Hi all,
>
> Some of the feedback I got after f24a08ec13eb involved the fact that
> indexes could also be dropped during the phase 1 of REINDEX
> CONCURRENTLY when the expressions or predicates are evaluated.  The
> damage is limited to cache lookup failures or assertion hits during
> phase 2, thanks to the protections that f24a08ec13eb has added.

Yea, I can see both here without the fix. Your test fails with "could not
open relation with OID", and doing a REINDEX on the _ccnew index from the
function hits the ii_ReadyForInserts assert.

> Anyway, it would be nice to fix this issue.  Attached is a patch
> addressing the problem with a test, for a backpatch down to v15.
>
> Thoughts or objections?

The patch looks good to me, some minor comment nits:

- "then close relations" in the lockrelid comment isn't true anymore, and
  parentRelationIds there is heapRelationIds now?

- IIUC ReindexUnpinRelations() isn't only closing relations from
  ReindexPinRelations() anymore too..

Regards,
Ayush






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Index drops during phase 1 of REINDEX CONCURRENTLY
  2026-11-14 00:31 Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
  2026-11-14 05:42 ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Ayush Tiwari <ayushtiwari.slg01@gmail.com>
@ 2026-11-15 04:22   ` shihao zhong <zhong950419@gmail.com>
  2026-11-15 06:18     ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 6+ messages in thread

From: shihao zhong @ 2026-11-15 04:22 UTC (permalink / raw)
  To: Ayush Tiwari <ayushtiwari.slg01@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Postgres hackers <pgsql-hackers@lists.postgresql.org>

Hi Michael,

Thanks for the patch. I created the expression index first in the
new test, so concur_reindex_ddl_f() drops an index that the loop in
ReindexRelationConcurrently() has not reached yet. With the patch
the index_open() of the next iteration still fails with

  ERROR:  could not open relation with OID 16390

Would it make sense to open all the old indexes before the loop?

Thanks,
Shihao

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Index drops during phase 1 of REINDEX CONCURRENTLY
  2026-11-14 00:31 Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
  2026-11-14 05:42 ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Ayush Tiwari <ayushtiwari.slg01@gmail.com>
  2026-11-15 04:22   ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY shihao zhong <zhong950419@gmail.com>
@ 2026-11-15 06:18     ` Michael Paquier <michael@paquier.xyz>
  2026-11-16 04:04       ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Chao Li <li.evan.chao@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Michael Paquier @ 2026-11-15 06:18 UTC (permalink / raw)
  To: shihao zhong <zhong950419@gmail.com>; +Cc: Ayush Tiwari <ayushtiwari.slg01@gmail.com>; Postgres hackers <pgsql-hackers@lists.postgresql.org>

On Sat, Nov 14, 2026 at 11:22:59PM -0500, shihao zhong wrote:
> Would it make sense to open all the old indexes before the loop?

Hmm, yeah.  We could as well open the indexes when these are gathered
in the initial loop as we are in the same transaction.  Would you like
to write a patch to show your idea?  (I'm out most of next week so
won't have much time to look at what you have, but perhaps others
will.)
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Index drops during phase 1 of REINDEX CONCURRENTLY
  2026-11-14 00:31 Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
  2026-11-14 05:42 ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Ayush Tiwari <ayushtiwari.slg01@gmail.com>
  2026-11-15 04:22   ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY shihao zhong <zhong950419@gmail.com>
  2026-11-15 06:18     ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
@ 2026-11-16 04:04       ` Chao Li <li.evan.chao@gmail.com>
  2026-11-20 04:47         ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 6+ messages in thread

From: Chao Li @ 2026-11-16 04:04 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: shihao zhong <zhong950419@gmail.com>; Ayush Tiwari <ayushtiwari.slg01@gmail.com>; Postgres hackers <pgsql-hackers@lists.postgresql.org>



> On Nov 15, 2026, at 14:18, Michael Paquier <michael@paquier.xyz> wrote:
> 
> On Sat, Nov 14, 2026 at 11:22:59PM -0500, shihao zhong wrote:
>> Would it make sense to open all the old indexes before the loop?
> 
> Hmm, yeah.  We could as well open the indexes when these are gathered
> in the initial loop as we are in the same transaction.  Would you like
> to write a patch to show your idea?  (I'm out most of next week so
> won't have much time to look at what you have, but perhaps others
> will.)
> --
> Michael

Following Shihao’s comment, I swapped the order of the two CREATE INDEX statements:
```
CREATE INDEX concur_reindex_ddl_ind2 ON
  concur_reindex_ddl_tab ((i + concur_reindex_ddl_im(0)));
CREATE INDEX concur_reindex_ddl_ind1 ON concur_reindex_ddl_tab (i);
```

I then reproduced the same test failure that Shihao reported.

After some debugging, I think the problem is that RelationGetIndexList() returns the indexes in OID order. Creating ind2 first therefore puts it before ind1 in indexIds. The gathering loop closes the indexes while retaining their locks. Consequently, when phase 1 processes ind2, ind1 has not yet been reopened: it is locked, but not opened.

The retained lock doesn't prevent DROP INDEX in the same transaction. The following comment in index_drop() seems to explain why only locking cannot block index dropping:
```
   /*
    * We might still have open queries using it in our own session, which the
    * above locking won't prevent, so test explicitly.
    */
   CheckTableNotInUse(userIndexRelation, "DROP INDEX");
```

So, when phase 1 evaluates concur_reindex_ddl_im(0) while processing ind2, the function can drop ind1. The next iteration then attempts to open ind1, which would fail.

To prevent this, we need to open all original target indexes before the phase 1 creation loop starts. Michael seems to suggest remaining the indexes opened after the gathering loop. Since that code has several branches, I thought it might be cleaner to add a separate loop immediately before the phase 1 loop to open all indexes in indexIds.

The attached diff takes this approach and also swaps the order of the two CREATE INDEX statements in the test. The test passes with this change. Note that, the diff is based on v1.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

nocfbot_open_index_first.diff (application/octet-stream, 3.4K) download diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 8414b803722..5c64f519350 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -3788,6 +3788,7 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein } ReindexIndexInfo; List *heapRelationIds = NIL; List *indexIds = NIL; + List *lockedIndexRels = NIL; List *newIndexIds = NIL; List *relationLocks = NIL; List *phase1Rels = NIL; @@ -4103,7 +4104,21 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein * more detailed comments. */ + /* + * Open all indexes before phase 1 to prevent from potential index drop + * from the same transation during creating the new indexes. + */ foreach(lc, indexIds) + { + ReindexIndexInfo *idx = lfirst(lc); + Relation indexRel; + + indexRel = index_open(idx->indexId, ShareUpdateExclusiveLock); + + lockedIndexRels = lappend(lockedIndexRels, indexRel); + } + + forboth(lc, indexIds, lc2, lockedIndexRels) { char *concurrentName; ReindexIndexInfo *idx = lfirst(lc); @@ -4118,7 +4133,7 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein LockRelId *lockrelid; Oid tablespaceid; - indexRel = index_open(idx->indexId, ShareUpdateExclusiveLock); + indexRel = lfirst(lc2); heapRel = table_open(indexRel->rd_index->indrelid, ShareUpdateExclusiveLock); @@ -4247,6 +4262,9 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein } } + list_free(lockedIndexRels); + lockedIndexRels = NIL; + /* * Save the heap lock for following visibility checks with other backends * might conflict with this session. diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out index 857603cd2b4..025eca2beb3 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -2914,9 +2914,9 @@ CREATE FUNCTION concur_reindex_ddl_f() RETURNS void LANGUAGE plpgsql AS CREATE FUNCTION concur_reindex_ddl_im(int) RETURNS int LANGUAGE plpgsql IMMUTABLE AS 'begin perform public.concur_reindex_ddl_f(); return $1; end'; -CREATE INDEX concur_reindex_ddl_ind1 ON concur_reindex_ddl_tab (i); CREATE INDEX concur_reindex_ddl_ind2 ON concur_reindex_ddl_tab ((i + concur_reindex_ddl_im(0))); +CREATE INDEX concur_reindex_ddl_ind1 ON concur_reindex_ddl_tab (i); CREATE OR REPLACE FUNCTION concur_reindex_ddl_f() RETURNS void LANGUAGE plpgsql AS 'begin DROP INDEX public.concur_reindex_ddl_ind1; end'; diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql index 27e038fa808..a28a2dc3ba5 100644 --- a/src/test/regress/sql/create_index.sql +++ b/src/test/regress/sql/create_index.sql @@ -1173,9 +1173,9 @@ CREATE FUNCTION concur_reindex_ddl_f() RETURNS void LANGUAGE plpgsql AS CREATE FUNCTION concur_reindex_ddl_im(int) RETURNS int LANGUAGE plpgsql IMMUTABLE AS 'begin perform public.concur_reindex_ddl_f(); return $1; end'; -CREATE INDEX concur_reindex_ddl_ind1 ON concur_reindex_ddl_tab (i); CREATE INDEX concur_reindex_ddl_ind2 ON concur_reindex_ddl_tab ((i + concur_reindex_ddl_im(0))); +CREATE INDEX concur_reindex_ddl_ind1 ON concur_reindex_ddl_tab (i); CREATE OR REPLACE FUNCTION concur_reindex_ddl_f() RETURNS void LANGUAGE plpgsql AS 'begin DROP INDEX public.concur_reindex_ddl_ind1; end';
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: Index drops during phase 1 of REINDEX CONCURRENTLY
  2026-11-14 00:31 Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
  2026-11-14 05:42 ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Ayush Tiwari <ayushtiwari.slg01@gmail.com>
  2026-11-15 04:22   ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY shihao zhong <zhong950419@gmail.com>
  2026-11-15 06:18     ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
  2026-11-16 04:04       ` Re: Index drops during phase 1 of REINDEX CONCURRENTLY Chao Li <li.evan.chao@gmail.com>
@ 2026-11-20 04:47         ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Paquier @ 2026-11-20 04:47 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; +Cc: shihao zhong <zhong950419@gmail.com>; Ayush Tiwari <ayushtiwari.slg01@gmail.com>; Postgres hackers <pgsql-hackers@lists.postgresql.org>

On Mon, Nov 16, 2026 at 12:04:32PM +0800, Chao Li wrote:
> Following Shihao’s comment, I swapped the order of the two CREATE
> INDEX statements:
> ```
> CREATE INDEX concur_reindex_ddl_ind2 ON
>   concur_reindex_ddl_tab ((i + concur_reindex_ddl_im(0)));
> CREATE INDEX concur_reindex_ddl_ind1 ON concur_reindex_ddl_tab (i);
> ```

This shows your point, but it also impacts the test by not checking
anymore what I want it to test.

> The attached diff takes this approach and also swaps the order of
> the two CREATE INDEX statements in the test. The test passes with
> this change. Note that, the diff is based on v1.

Hmm, no, I think that you are overcomplicating things here by
introducing a second list that serves the same purpose as the "phase
1" list.  It is simpler to keep the Relation references opened based
on the ones already taken in the first loop, and we are talking about
only two places.

Another redundant piece is the addition of the heap relation to the
new list until the session locks are hold.  Perhaps nicer on
consistency grounds in the long-run, but not actually required so I
have kept the table_close() for it.

The original test ordering is kept.  I have reused the solution where
the relations are kept opened in the initial loop, then committed the
change down to v15.

Thanks all for the reviews.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-11-20 04:47 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 00:31 Index drops during phase 1 of REINDEX CONCURRENTLY Michael Paquier <michael@paquier.xyz>
2026-11-14 05:42 ` Ayush Tiwari <ayushtiwari.slg01@gmail.com>
2026-11-15 04:22   ` shihao zhong <zhong950419@gmail.com>
2026-11-15 06:18     ` Michael Paquier <michael@paquier.xyz>
2026-11-16 04:04       ` Chao Li <li.evan.chao@gmail.com>
2026-11-20 04:47         ` Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox