Skip to content

Commit 54562c9

Browse files
committed
Improve Asserts checking relation matching in parallel scans.
table_beginscan_parallel and index_beginscan_parallel contain Asserts checking that the relation a worker will use in a parallel scan is the same one the leader intended. However, they were checking for relation OID match, which was not strong enough to detect the mismatch problem fixed in 126ec0b. What would be strong enough is to compare relfilenodes instead. Arguably, that's a saner definition anyway, since a scan surely operates on a physical relation not a logical one. Hence, store and compare RelFileLocators not relation OIDs. Also ensure that index_beginscan_parallel checks the index identity not just the table identity. Discussion: https://postgr.es/m/2127254.1726789524@sss.pgh.pa.us
1 parent afb03e2 commit 54562c9

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/backend/access/index/indexam.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ index_parallelscan_initialize(Relation heapRelation, Relation indexRelation,
500500
EstimateSnapshotSpace(snapshot));
501501
offset = MAXALIGN(offset);
502502

503-
target->ps_relid = RelationGetRelid(heapRelation);
504-
target->ps_indexid = RelationGetRelid(indexRelation);
503+
target->ps_locator = heapRelation->rd_locator;
504+
target->ps_indexlocator = indexRelation->rd_locator;
505505
target->ps_offset = offset;
506506
SerializeSnapshot(snapshot, target->ps_snapshot_data);
507507

@@ -544,7 +544,9 @@ index_beginscan_parallel(Relation heaprel, Relation indexrel, int nkeys,
544544
Snapshot snapshot;
545545
IndexScanDesc scan;
546546

547-
Assert(RelationGetRelid(heaprel) == pscan->ps_relid);
547+
Assert(RelFileLocatorEquals(heaprel->rd_locator, pscan->ps_locator));
548+
Assert(RelFileLocatorEquals(indexrel->rd_locator, pscan->ps_indexlocator));
549+
548550
snapshot = RestoreSnapshot(pscan->ps_snapshot_data);
549551
RegisterSnapshot(snapshot);
550552
scan = index_beginscan_internal(indexrel, nkeys, norderbys, snapshot,

src/backend/access/table/tableam.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc pscan)
168168
uint32 flags = SO_TYPE_SEQSCAN |
169169
SO_ALLOW_STRAT | SO_ALLOW_SYNC | SO_ALLOW_PAGEMODE;
170170

171-
Assert(RelationGetRelid(relation) == pscan->phs_relid);
171+
Assert(RelFileLocatorEquals(relation->rd_locator, pscan->phs_locator));
172172

173173
if (!pscan->phs_snapshot_any)
174174
{
@@ -389,7 +389,7 @@ table_block_parallelscan_initialize(Relation rel, ParallelTableScanDesc pscan)
389389
{
390390
ParallelBlockTableScanDesc bpscan = (ParallelBlockTableScanDesc) pscan;
391391

392-
bpscan->base.phs_relid = RelationGetRelid(rel);
392+
bpscan->base.phs_locator = rel->rd_locator;
393393
bpscan->phs_nblocks = RelationGetNumberOfBlocks(rel);
394394
/* compare phs_syncscan initialization to similar logic in initscan */
395395
bpscan->base.phs_syncscan = synchronize_seqscans &&

src/include/access/relscan.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "access/itup.h"
1919
#include "port/atomics.h"
2020
#include "storage/buf.h"
21+
#include "storage/relfilelocator.h"
2122
#include "storage/spin.h"
2223
#include "utils/relcache.h"
2324

@@ -62,7 +63,7 @@ typedef struct TableScanDescData *TableScanDesc;
6263
*/
6364
typedef struct ParallelTableScanDescData
6465
{
65-
Oid phs_relid; /* OID of relation to scan */
66+
RelFileLocator phs_locator; /* physical relation to scan */
6667
bool phs_syncscan; /* report location to syncscan logic? */
6768
bool phs_snapshot_any; /* SnapshotAny, not phs_snapshot_data? */
6869
Size phs_snapshot_off; /* data for snapshot */
@@ -169,8 +170,8 @@ typedef struct IndexScanDescData
169170
/* Generic structure for parallel scans */
170171
typedef struct ParallelIndexScanDescData
171172
{
172-
Oid ps_relid;
173-
Oid ps_indexid;
173+
RelFileLocator ps_locator; /* physical table relation to scan */
174+
RelFileLocator ps_indexlocator; /* physical index relation to scan */
174175
Size ps_offset; /* Offset in bytes of am specific structure */
175176
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER];
176177
} ParallelIndexScanDescData;

0 commit comments

Comments
 (0)