Skip to content

Commit fe4d022

Browse files
committed
Fix rd_firstRelfilenodeSubid for nailed relations, in parallel workers.
Move applicable code out of RelationBuildDesc(), which nailed relations bypass. Non-assert builds experienced no known problems. Back-patch to v13, where commit c6b9204 introduced rd_firstRelfilenodeSubid. Kyotaro Horiguchi. Reported by Justin Pryzby. Discussion: https://postgr.es/m/20200907023737.GA7158@telsasoft.com
1 parent bedadc7 commit fe4d022

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

src/backend/utils/cache/relcache.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,14 +1243,6 @@ RelationBuildDesc(Oid targetRelId, bool insertIt)
12431243
if (insertIt)
12441244
RelationCacheInsert(relation, true);
12451245

1246-
/*
1247-
* For RelationNeedsWAL() to answer correctly on parallel workers, restore
1248-
* rd_firstRelfilenodeSubid. No subtransactions start or end while in
1249-
* parallel mode, so the specific SubTransactionId does not matter.
1250-
*/
1251-
if (IsParallelWorker() && RelFileNodeSkippingWAL(relation->rd_node))
1252-
relation->rd_firstRelfilenodeSubid = TopSubTransactionId;
1253-
12541246
/* It's fully valid */
12551247
relation->rd_isvalid = true;
12561248

@@ -1273,6 +1265,8 @@ RelationBuildDesc(Oid targetRelId, bool insertIt)
12731265
static void
12741266
RelationInitPhysicalAddr(Relation relation)
12751267
{
1268+
Oid oldnode = relation->rd_node.relNode;
1269+
12761270
/* these relations kinds never have storage */
12771271
if (!RELKIND_HAS_STORAGE(relation->rd_rel->relkind))
12781272
return;
@@ -1330,6 +1324,19 @@ RelationInitPhysicalAddr(Relation relation)
13301324
elog(ERROR, "could not find relation mapping for relation \"%s\", OID %u",
13311325
RelationGetRelationName(relation), relation->rd_id);
13321326
}
1327+
1328+
/*
1329+
* For RelationNeedsWAL() to answer correctly on parallel workers, restore
1330+
* rd_firstRelfilenodeSubid. No subtransactions start or end while in
1331+
* parallel mode, so the specific SubTransactionId does not matter.
1332+
*/
1333+
if (IsParallelWorker() && oldnode != relation->rd_node.relNode)
1334+
{
1335+
if (RelFileNodeSkippingWAL(relation->rd_node))
1336+
relation->rd_firstRelfilenodeSubid = TopSubTransactionId;
1337+
else
1338+
relation->rd_firstRelfilenodeSubid = InvalidSubTransactionId;
1339+
}
13331340
}
13341341

13351342
/*

src/test/regress/expected/reindex_catalog.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ REINDEX INDEX pg_index_indexrelid_index; -- non-mapped, non-shared, critical
3636
REINDEX INDEX pg_index_indrelid_index; -- non-mapped, non-shared, non-critical
3737
REINDEX INDEX pg_database_oid_index; -- mapped, shared, critical
3838
REINDEX INDEX pg_shdescription_o_c_index; -- mapped, shared, non-critical
39+
-- Check the same REINDEX INDEX statements under parallelism.
40+
BEGIN;
41+
SET min_parallel_table_scan_size = 0;
42+
REINDEX INDEX pg_class_oid_index; -- mapped, non-shared, critical
43+
REINDEX INDEX pg_class_relname_nsp_index; -- mapped, non-shared, non-critical
44+
REINDEX INDEX pg_index_indexrelid_index; -- non-mapped, non-shared, critical
45+
REINDEX INDEX pg_index_indrelid_index; -- non-mapped, non-shared, non-critical
46+
REINDEX INDEX pg_database_oid_index; -- mapped, shared, critical
47+
REINDEX INDEX pg_shdescription_o_c_index; -- mapped, shared, non-critical
48+
ROLLBACK;

src/test/regress/sql/reindex_catalog.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ REINDEX INDEX pg_index_indexrelid_index; -- non-mapped, non-shared, critical
3939
REINDEX INDEX pg_index_indrelid_index; -- non-mapped, non-shared, non-critical
4040
REINDEX INDEX pg_database_oid_index; -- mapped, shared, critical
4141
REINDEX INDEX pg_shdescription_o_c_index; -- mapped, shared, non-critical
42+
43+
-- Check the same REINDEX INDEX statements under parallelism.
44+
BEGIN;
45+
SET min_parallel_table_scan_size = 0;
46+
REINDEX INDEX pg_class_oid_index; -- mapped, non-shared, critical
47+
REINDEX INDEX pg_class_relname_nsp_index; -- mapped, non-shared, non-critical
48+
REINDEX INDEX pg_index_indexrelid_index; -- non-mapped, non-shared, critical
49+
REINDEX INDEX pg_index_indrelid_index; -- non-mapped, non-shared, non-critical
50+
REINDEX INDEX pg_database_oid_index; -- mapped, shared, critical
51+
REINDEX INDEX pg_shdescription_o_c_index; -- mapped, shared, non-critical
52+
ROLLBACK;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy