Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXH4U-0006zM-MB for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Nov 2019 03:54:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXH4R-0001oJ-8K for pgsql-bugs@arkaria.postgresql.org; Wed, 20 Nov 2019 03:54:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXH4P-0001oB-36 for pgsql-bugs@lists.postgresql.org; Wed, 20 Nov 2019 03:54:23 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iXH4K-0003kf-HP for pgsql-bugs@lists.postgresql.org; Wed, 20 Nov 2019 03:54:19 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id F0A8C326; Tue, 19 Nov 2019 22:54:13 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 19 Nov 2019 22:54:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=olSPLVAGzmV9disNNPOkjl89sEP vIDj/IehY3oHMlC0=; b=js1SS1gpMJ5fJpfxuCU7JUGI50RjI4As4Jbg+/e/KDz EtABQgjPtPnOOfkpHkD5kjmVGJEQsNLURqiC5CNIEDqLufBg4Tr06+xDPgtpUrDO /5wNEKSmSXPj3Kg6ylAksagqGYii4mq3grAokBUiEweUIxIxV5v6uBOEyt/rBgtw 55fNWnWu8kQNmo0aTdiFpiwbF3ND0T+xLXaKs/3FgkHL63wnCN3hkskyh27OTT6H B8iqNUARmo0E/dwaH4FEROJfzma7vkdbTpiRZl/glO00coPgxKvN+An8M0M5vHkp xzEmFO9g+ehEc7J2MKACxIjLlfzk91ghugdXcl8aHtg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=olSPLV AGzmV9disNNPOkjl89sEPvIDj/IehY3oHMlC0=; b=X+O/pzDOHCsnuAomlXtVjI OMDLGiPuoNevQ1BDLMmWevmPwcPnYLPzSLweY4GYnrTbZ1AA5lb4iPhECUekCMRO CCkThLf3dYv712lxZ/dqS2rk4+B/RdIvz/EjKpkpjjIjPSYRtSwHNcseoKprbecu tuBzqDzNk7YOQieQeC/1a5rG+YCeA2/upXixGamChzoZOFgCLZdokLSIhqmz4pps foKjHYNXl+QaRbzyL9Au3VsWADTcQcgaRsofCt5YMu0XeKnyeALOxqtnx2hX5vcz pBE9FfZAr35wXFgHwxrnaCYls7PLG3rLLxcgYwkRntQ+6EeGGt0chf0Gsww22Lzg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudegledgieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepudduuddruddtvddrudektddrudekheenucfrrghr rghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id 795578005A; Tue, 19 Nov 2019 22:54:11 -0500 (EST) Date: Wed, 20 Nov 2019 12:54:08 +0900 From: Michael Paquier To: Andres Freund Cc: Tom Lane , Manuel Rigger , PostgreSQL mailing lists Subject: Re: REINDEX CONCURRENTLY unexpectedly fails Message-ID: <20191120035408.GA4243@paquier.xyz> References: <12383.1573660748@sss.pgh.pa.us> <20191113163851.e2enkdpvd3nrobst@alap3.anarazel.de> <19198.1573663534@sss.pgh.pa.us> <20191114080855.GG1910@paquier.xyz> <3808.1573754033@sss.pgh.pa.us> <20191115024512.GE1849@paquier.xyz> <20191115025412.p3beiflrd6bx6wgf@alap3.anarazel.de> <20191115032141.GH1849@paquier.xyz> <20191115080706.GI1849@paquier.xyz> <20191120013649.2xfr2dnznyjgluch@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="QTprm0S8XgL7H0Dt" Content-Disposition: inline In-Reply-To: <20191120013649.2xfr2dnznyjgluch@alap3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --QTprm0S8XgL7H0Dt Content-Type: multipart/mixed; boundary="azLHFNyN32YCQGCU" Content-Disposition: inline --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Nov 19, 2019 at 05:36:49PM -0800, Andres Freund wrote: > On 2019-11-15 17:07:06 +0900, Michael Paquier wrote: >> So, here is a patch to address all that. I have also added a test for >> REINDEX SCHEMA on a temporary schema. While looking at the problem, I >> have found a crash if trying to reindex concurrently an index or a >> table using a temporary relation from a different session because we >> have been lacking checks with RELATION_IS_OTHER_TEMP() in the >> concurrent code paths. Thanks for providing comments. The next set of minor releases is in February, so we have some room until that. For now I'll just add this patch to the next CF as a bug fix to keeo track of it. > Probably worth fixing separately? There is already a check for RELATION_IS_OTHER_TEMP() in the non-concurrent reindex path, so by forcing temp relations to take this path then the issue gets fixed automatically, with the error message =66rom reindex_index() generated. >> Please note that I have not changed index_drop() for the concurrent >> mode. Per my checks this does not actually cause any direct bugs as >> this code path just takes care of dropping the dependencies with the >> index. There could be an argument for changing that on HEAD though, >> but I am not sure that this is worth the complication either. >=20 > I'm extremely doubtful this works correctly. E.g., what prevents the > tids for index_concurrently_set_dead() from being recycled and pointing > to a different row after one of the internal transactions? ON COMMIT DELETE ROWS does a physical truncation of the relation files. And as DROP INDEX CONCURRENTLY cannot be run in a transaction block, you would never face a case where you have no past TIDs which could be referred to when setting the index as invalid. Now I don't actually object to enforce the non-concurrent path in index_drop() for *all* temporary relations. Anyway, that makes sense in itself on performance grounds, similarly to the create path, so did that by enforcing the flag in index_drop() (doDeletion would be tempting but I took the problem at its root). And added some tests for the drop path and an extra assertion.=20 > I don't think "ignore concurrent index creation" is a good description - > they're still created. I'd rephrase it as "For temporary tables build > index non-concurrently", or something in that vein. > > I think we also need to mention somewhere that it's actually crucial to > ignore them, as otherwise we'd run into problems with on commit truncate > / drop. Sure. I have expanded the comment section on that. > Probably worthwhile to centralize check and comments into one place, to > avoid duplication / them diverging. Perhaps something like > IndexCreationSupportsConcurrent() or IndexCreationForceNonConcurrent()? Good idea, done that. It reduces the explanations of the patch to be in a single location. >> @@ -2771,6 +2797,9 @@ ReindexRelationConcurrently(Oid relationOid, int o= ptions) >> /* Open relation to get its indexes */ >> heapRelation =3D table_open(relationOid, ShareUpdateExclusiveLock); >> =20 >> + /* Temporary tables are not processed concurrently */ >> + Assert(heapRelation->rd_rel->relpersistence !=3D RELPERSISTENCE_TEM= P); >=20 > s/are not/can not/? Okay. >> +-- Temporary tables with concurrent builds >> +CREATE TEMP TABLE concur_temp (f1 int, f2 text); >> +INSERT INTO concur_temp VALUES (1, 'foo'), (2, 'bar'); >> +CREATE INDEX CONCURRENTLY concur_temp_ind ON concur_temp(f1); >> +DROP TABLE concur_temp; >> +-- On-commit actions >> +CREATE TEMP TABLE concur_temp (f1 int, f2 text) >> + ON COMMIT DELETE ROWS; >> +INSERT INTO concur_temp VALUES (1, 'foo'), (2, 'bar'); >> +CREATE INDEX CONCURRENTLY concur_temp_ind ON concur_temp(f1); >> +DROP TABLE concur_temp; >> -- >=20 > I'd also add a test for ON COMMIT DROP. Considered that, but ON COMMIT DROP does not make sense because it requires a transaction context, which is why I did not add one. And it seems to me that there is not much value to just check after CIC or REINDEX's restriction to not run in a transaction block? I added tests for these two, but I am of the opinion that they don't bring much. >> diff --git a/doc/src/sgml/ref/reindex.sgml b/doc/src/sgml/ref/reindex.sg= ml >> index 10881ab03a..e5d2b1a06e 100644 >> --- a/doc/src/sgml/ref/reindex.sgml >> +++ b/doc/src/sgml/ref/reindex.sgml >> @@ -162,6 +162,9 @@ REINDEX [ ( VERBOSE ) ] { INDEX | TABLE | SCHEMA | D= ATABASE | SYSTEM } [ CONCURR >> — see > endterm=3D"sql-reindex-concurrently-title"/>. >> >> + >> + This option is ignored for temporary relations. >> + >> >> >> =20 >=20 > I think either this needs to be more verbose, explaining that there's no > harm from the option being ignored, or it should be ignored as an > implementation detail. I think that documenting it is good for the end-user as well. Just attempted something in the updated version for all the sections of the docs involved. -- Michael --azLHFNyN32YCQGCU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="reindex-conc-temp-v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h index 1113d25b2d..04d3d4826f 100644 --- a/src/include/catalog/index.h +++ b/src/include/catalog/index.h @@ -113,6 +113,8 @@ extern bool CompareIndexInfo(IndexInfo *info1, IndexInf= o *info2, =20 extern void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii); =20 +extern bool RelationSupportsConcurrently(char relpersistence); + extern void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 67f637de11..0012ebf69c 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -2017,6 +2017,13 @@ index_drop(Oid indexId, bool concurrent, bool concur= rent_lock_mode) LOCKTAG heaplocktag; LOCKMODE lockmode; =20 + /* + * Enforce non-concurrent drop if the relation does not support this + * option. + */ + if (!RelationSupportsConcurrently(get_rel_persistence(indexId))) + concurrent =3D false; + /* * To drop an index safely, we must grab exclusive lock on its parent * table. Exclusive lock on the index alone is insufficient because @@ -2109,6 +2116,9 @@ index_drop(Oid indexId, bool concurrent, bool concurr= ent_lock_mode) */ CacheInvalidateRelcache(userHeapRelation); =20 + /* Temporary tables cannot be processed concurrently */ + Assert(userHeapRelation->rd_rel->relpersistence !=3D RELPERSISTENCE_TEMP= ); + /* save lockrelid and locktag for below, then close but keep locks */ heaprelid =3D userHeapRelation->rd_lockInfo.lockRelId; SET_LOCKTAG_RELATION(heaplocktag, heaprelid.dbId, heaprelid.relId); @@ -2441,6 +2451,30 @@ CompareIndexInfo(IndexInfo *info1, IndexInfo *info2, return true; } =20 +/* + * RelationSupportsConcurrently + * + * Check if a relation supports concurrent builds or not. This is + * used as a sanity check prior processing CREATE INDEX, DROP INDEX + * or REINDEX when using CONCURRENTLY. + */ +bool +RelationSupportsConcurrently(char relpersistence) +{ + /* + * Build indexes non-concurrently for temporary relations. Such + * relations only work with the session assigned to them, so they are + * not subject to concurrent concerns, and a concurrent build would + * cause issues with ON COMMIT actions triggered by the transactions + * of the concurrent build. A non-concurrent reindex is also more + * efficient in this case. + */ + if (relpersistence =3D=3D RELPERSISTENCE_TEMP) + return false; + + return true; +} + /* ---------------- * BuildSpeculativeIndexInfo * Add extra state to IndexInfo record diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexc= mds.c index 374e2d0efe..bb3dcf5525 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -550,6 +550,13 @@ DefineIndex(Oid relationId, lockmode =3D stmt->concurrent ? ShareUpdateExclusiveLock : ShareLock; rel =3D table_open(relationId, lockmode); =20 + /* + * Enforce non-concurrent build if the relation does not support this + * option. + */ + if (!RelationSupportsConcurrently(rel->rd_rel->relpersistence)) + stmt->concurrent =3D false; + namespaceId =3D RelationGetNamespace(rel); =20 /* Ensure that it makes sense to index this kind of relation */ @@ -2349,7 +2356,7 @@ ReindexIndex(RangeVar *indexRelation, int options, bo= ol concurrent) persistence =3D irel->rd_rel->relpersistence; index_close(irel, NoLock); =20 - if (concurrent) + if (concurrent && RelationSupportsConcurrently(persistence)) ReindexRelationConcurrently(indOid, options); else reindex_index(indOid, false, persistence, @@ -2442,7 +2449,8 @@ ReindexTable(RangeVar *relation, int options, bool co= ncurrent) 0, RangeVarCallbackOwnsTable, NULL); =20 - if (concurrent) + if (concurrent && + RelationSupportsConcurrently(get_rel_persistence(heapOid))) { result =3D ReindexRelationConcurrently(heapOid, options); =20 @@ -2648,7 +2656,8 @@ ReindexMultipleTables(const char *objectName, Reindex= ObjectType objectKind, /* functions in indexes may want a snapshot set */ PushActiveSnapshot(GetTransactionSnapshot()); =20 - if (concurrent) + if (concurrent && + RelationSupportsConcurrently(get_rel_persistence(relid))) { (void) ReindexRelationConcurrently(relid, options); /* ReindexRelationConcurrently() does the verbose output */ @@ -2771,6 +2780,9 @@ ReindexRelationConcurrently(Oid relationOid, int opti= ons) /* Open relation to get its indexes */ heapRelation =3D table_open(relationOid, ShareUpdateExclusiveLock); =20 + /* Temporary tables cannot be processed concurrently */ + Assert(heapRelation->rd_rel->relpersistence !=3D RELPERSISTENCE_TEMP); + /* Add all the valid indexes of relation to list */ foreach(lc, RelationGetIndexList(heapRelation)) { @@ -2864,6 +2876,9 @@ ReindexRelationConcurrently(Oid relationOid, int opti= ons) /* Save the list of relation OIDs in private context */ oldcontext =3D MemoryContextSwitchTo(private_context); =20 + /* Temporary tables cannot be processed concurrently */ + Assert(get_rel_persistence(heapId) !=3D RELPERSISTENCE_TEMP); + /* Track the heap relation of this index for session locks */ heapRelationIds =3D list_make1_oid(heapId); =20 diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/= expected/create_index.out index 1cdb7a9663..79cc569969 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -1398,6 +1398,31 @@ Indexes: "concur_index5" btree (f2) WHERE f1 =3D 'x'::text "std_index" btree (f2) =20 +-- Temporary tables with concurrent builds and on-commit actions +-- CONCURRENTLY used with CREATE INDEX and DROP INDEX is ignored. +-- PRESERVE ROWS, the default. +CREATE TEMP TABLE concur_temp (f1 int, f2 text) + ON COMMIT PRESERVE ROWS; +INSERT INTO concur_temp VALUES (1, 'foo'), (2, 'bar'); +CREATE INDEX CONCURRENTLY concur_temp_ind ON concur_temp(f1); +DROP INDEX CONCURRENTLY concur_temp_ind; +DROP TABLE concur_temp; +-- ON COMMIT DROP +BEGIN; +CREATE TEMP TABLE concur_temp (f1 int, f2 text) + ON COMMIT DROP; +INSERT INTO concur_temp VALUES (1, 'foo'), (2, 'bar'); +-- Fails when running in a transaction. +CREATE INDEX CONCURRENTLY concur_temp_ind ON concur_temp(f1); +ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block +COMMIT; +-- ON COMMIT DELETE ROWS +CREATE TEMP TABLE concur_temp (f1 int, f2 text) + ON COMMIT DELETE ROWS; +INSERT INTO concur_temp VALUES (1, 'foo'), (2, 'bar'); +CREATE INDEX CONCURRENTLY concur_temp_ind ON concur_temp(f1); +DROP INDEX CONCURRENTLY concur_temp_ind; +DROP TABLE concur_temp; -- -- Try some concurrent index drops -- @@ -2368,6 +2393,55 @@ SELECT pg_get_indexdef('concur_exprs_index_pred_2'::= regclass); (1 row) =20 DROP TABLE concur_exprs_tab; +-- Temporary tables and on-commit actions, where CONCURRENTLY is ignored. +-- ON COMMIT PRESERVE ROWS, the default. +CREATE TEMP TABLE concur_temp_tab_1 (c1 int, c2 text) + ON COMMIT PRESERVE ROWS; +INSERT INTO concur_temp_tab_1 VALUES (1, 'foo'), (2, 'bar'); +CREATE INDEX concur_temp_ind_1 ON concur_temp_tab_1(c2); +REINDEX TABLE CONCURRENTLY concur_temp_tab_1; +REINDEX INDEX CONCURRENTLY concur_temp_ind_1; +-- Still fails in transaction blocks +BEGIN; +REINDEX INDEX CONCURRENTLY concur_temp_ind_1; +ERROR: REINDEX CONCURRENTLY cannot run inside a transaction block +COMMIT; +-- ON COMMIT DELETE ROWS +CREATE TEMP TABLE concur_temp_tab_2 (c1 int, c2 text) + ON COMMIT DELETE ROWS; +CREATE INDEX concur_temp_ind_2 ON concur_temp_tab_2(c2); +REINDEX TABLE CONCURRENTLY concur_temp_tab_2; +REINDEX INDEX CONCURRENTLY concur_temp_ind_2; +-- ON COMMIT DROP +BEGIN; +CREATE TEMP TABLE concur_temp_tab_3 (c1 int, c2 text) + ON COMMIT PRESERVE ROWS; +INSERT INTO concur_temp_tab_3 VALUES (1, 'foo'), (2, 'bar'); +CREATE INDEX concur_temp_ind_3 ON concur_temp_tab_3(c2); +-- Fails when running in a transaction +REINDEX INDEX CONCURRENTLY concur_temp_ind_3; +ERROR: REINDEX CONCURRENTLY cannot run inside a transaction block +COMMIT; +-- REINDEX SCHEMA processes all temporary relations +CREATE TABLE reindex_temp_before AS +SELECT oid, relname, relfilenode, relkind, reltoastrelid + FROM pg_class + WHERE relname IN ('concur_temp_ind_1', 'concur_temp_ind_2'); +SELECT pg_my_temp_schema()::regnamespace as temp_schema_name \gset +REINDEX SCHEMA :temp_schema_name; +SELECT b.relname, + b.relkind, + CASE WHEN a.relfilenode =3D b.relfilenode THEN 'relfilenode is unc= hanged' + ELSE 'relfilenode has changed' END + FROM reindex_temp_before b JOIN pg_class a ON b.oid =3D a.oid + ORDER BY 1; + relname | relkind | case =20 +-------------------+---------+------------------------- + concur_temp_ind_1 | i | relfilenode has changed + concur_temp_ind_2 | i | relfilenode has changed +(2 rows) + +DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before; -- -- REINDEX SCHEMA -- diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/c= reate_index.sql index 76598085f7..ae28f08401 100644 --- a/src/test/regress/sql/create_index.sql +++ b/src/test/regress/sql/create_index.sql @@ -489,6 +489,31 @@ VACUUM FULL concur_heap; REINDEX TABLE concur_heap; \d concur_heap =20 +-- Temporary tables with concurrent builds and on-commit actions +-- CONCURRENTLY used with CREATE INDEX and DROP INDEX is ignored. +-- PRESERVE ROWS, the default. +CREATE TEMP TABLE concur_temp (f1 int, f2 text) + ON COMMIT PRESERVE ROWS; +INSERT INTO concur_temp VALUES (1, 'foo'), (2, 'bar'); +CREATE INDEX CONCURRENTLY concur_temp_ind ON concur_temp(f1); +DROP INDEX CONCURRENTLY concur_temp_ind; +DROP TABLE concur_temp; +-- ON COMMIT DROP +BEGIN; +CREATE TEMP TABLE concur_temp (f1 int, f2 text) + ON COMMIT DROP; +INSERT INTO concur_temp VALUES (1, 'foo'), (2, 'bar'); +-- Fails when running in a transaction. +CREATE INDEX CONCURRENTLY concur_temp_ind ON concur_temp(f1); +COMMIT; +-- ON COMMIT DELETE ROWS +CREATE TEMP TABLE concur_temp (f1 int, f2 text) + ON COMMIT DELETE ROWS; +INSERT INTO concur_temp VALUES (1, 'foo'), (2, 'bar'); +CREATE INDEX CONCURRENTLY concur_temp_ind ON concur_temp(f1); +DROP INDEX CONCURRENTLY concur_temp_ind; +DROP TABLE concur_temp; + -- -- Try some concurrent index drops -- @@ -954,6 +979,48 @@ SELECT pg_get_indexdef('concur_exprs_index_pred'::regc= lass); SELECT pg_get_indexdef('concur_exprs_index_pred_2'::regclass); DROP TABLE concur_exprs_tab; =20 +-- Temporary tables and on-commit actions, where CONCURRENTLY is ignored. +-- ON COMMIT PRESERVE ROWS, the default. +CREATE TEMP TABLE concur_temp_tab_1 (c1 int, c2 text) + ON COMMIT PRESERVE ROWS; +INSERT INTO concur_temp_tab_1 VALUES (1, 'foo'), (2, 'bar'); +CREATE INDEX concur_temp_ind_1 ON concur_temp_tab_1(c2); +REINDEX TABLE CONCURRENTLY concur_temp_tab_1; +REINDEX INDEX CONCURRENTLY concur_temp_ind_1; +-- Still fails in transaction blocks +BEGIN; +REINDEX INDEX CONCURRENTLY concur_temp_ind_1; +COMMIT; +-- ON COMMIT DELETE ROWS +CREATE TEMP TABLE concur_temp_tab_2 (c1 int, c2 text) + ON COMMIT DELETE ROWS; +CREATE INDEX concur_temp_ind_2 ON concur_temp_tab_2(c2); +REINDEX TABLE CONCURRENTLY concur_temp_tab_2; +REINDEX INDEX CONCURRENTLY concur_temp_ind_2; +-- ON COMMIT DROP +BEGIN; +CREATE TEMP TABLE concur_temp_tab_3 (c1 int, c2 text) + ON COMMIT PRESERVE ROWS; +INSERT INTO concur_temp_tab_3 VALUES (1, 'foo'), (2, 'bar'); +CREATE INDEX concur_temp_ind_3 ON concur_temp_tab_3(c2); +-- Fails when running in a transaction +REINDEX INDEX CONCURRENTLY concur_temp_ind_3; +COMMIT; +-- REINDEX SCHEMA processes all temporary relations +CREATE TABLE reindex_temp_before AS +SELECT oid, relname, relfilenode, relkind, reltoastrelid + FROM pg_class + WHERE relname IN ('concur_temp_ind_1', 'concur_temp_ind_2'); +SELECT pg_my_temp_schema()::regnamespace as temp_schema_name \gset +REINDEX SCHEMA :temp_schema_name; +SELECT b.relname, + b.relkind, + CASE WHEN a.relfilenode =3D b.relfilenode THEN 'relfilenode is unc= hanged' + ELSE 'relfilenode has changed' END + FROM reindex_temp_before b JOIN pg_class a ON b.oid =3D a.oid + ORDER BY 1; +DROP TABLE concur_temp_tab_1, concur_temp_tab_2, reindex_temp_before; + -- -- REINDEX SCHEMA -- diff --git a/doc/src/sgml/ref/create_index.sgml b/doc/src/sgml/ref/create_i= ndex.sgml index 629a31ef79..e27cc0af3d 100644 --- a/doc/src/sgml/ref/create_index.sgml +++ b/doc/src/sgml/ref/create_index.sgml @@ -129,6 +129,11 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EX= ISTS ] . + + This option is ignored for temporary relations as such relations + are assigned to the session using them, so they are not subject to + problems with concurrent locking issues. + =20 diff --git a/doc/src/sgml/ref/drop_index.sgml b/doc/src/sgml/ref/drop_index= =2Esgml index 2a8ca5bf68..c7bd67f24e 100644 --- a/doc/src/sgml/ref/drop_index.sgml +++ b/doc/src/sgml/ref/drop_index.sgml @@ -58,6 +58,11 @@ DROP INDEX [ CONCURRENTLY ] [ IF EXISTS ] nameDROP INDEX CONCURRENTLY cannot. + + This option is ignored for temporary relations as such relations + are assigned to the session using them, so they are not subject to + problems with concurrent locking issues. + =20 diff --git a/doc/src/sgml/ref/reindex.sgml b/doc/src/sgml/ref/reindex.sgml index 10881ab03a..eccdbc66e6 100644 --- a/doc/src/sgml/ref/reindex.sgml +++ b/doc/src/sgml/ref/reindex.sgml @@ -162,6 +162,12 @@ REINDEX [ ( VERBOSE ) ] { INDEX | TABLE | SCHEMA | DAT= ABASE | SYSTEM } [ CONCURR — see . + + This option is ignored for temporary relations as such relations + are assigned to the session using them, so they are not subject to + concerns with concurrent builds and REINDEX + requiring an exclusive lock on the parent table. + =20 --azLHFNyN32YCQGCU-- --QTprm0S8XgL7H0Dt Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl3UuOAACgkQnvQgOdby QH0Cdg//fVzRHN65eHZYSPZ7k6rAiE44/gXwDVrPwzN6gUqkeEJnLvIfPj6fnMhB sqwj1n5ykbKjwXqaQC448N60YJW4iub8pQlayBJ8K2tsF9whIxEDtIp3aiO++cLa tcwOumuy0AA+s5pqMbrAmPqflImEnohJcnm+x6PBEVDUC0BoyITn/+R/9uHG6Eh5 D0o1cgqjvB32JY4W1rjqWAkPtSX3+Gdzkm2Lcx88k/p9Vks2NfTmNJvRn2VgGl3y el93UvLX4UMnRn4tD/LvgZC45tUbhkEank+px7QDWz0zKJ5CHbrEiqmObzySnZeR Kf2c4TwkL5p60IoyRWHmFUHmz4h5uoQz4qk7SRG0Rgzmo1DnNXbe3XeFiNJ+GAXk I2VXnyM48vNBmmD4VNQ4h5TsKCDZeXwCHb3LIbj47ascpUR9fjMx8y7AwWvKbiHL SyQ8UrmMvUUPfRQhPrr9yplyGvfXnpFCW0BtQfOH54cFAFT/R9ZMh9jP+uVGil57 A47OuS3oZfitUA2i55+IFP/x67yVyLEUNWByT+hBK02ZB6gabJMNcKq7Ju/edl/a kzuqa01lSNM29lgoASpSLnwovB/vHwbmctXb2REd5xfMDiu9K7tl77ov0zvciIwQ ffkdB1UcsXM5PQilnEntWU8TqbI2+eg8cngviKKp1i6cQIDiE08= =WLWZ -----END PGP SIGNATURE----- --QTprm0S8XgL7H0Dt--