@@ -115,7 +115,6 @@ static bool ReindexRelationConcurrently(const ReindexStmt *stmt,
115
115
Oid relationOid ,
116
116
const ReindexParams * params );
117
117
static void update_relispartition (Oid relationId , bool newval );
118
- static inline void set_indexsafe_procflags (void );
119
118
120
119
/*
121
120
* callback argument type for RangeVarCallbackForReindexIndex()
@@ -418,10 +417,7 @@ CompareOpclassOptions(const Datum *opts1, const Datum *opts2, int natts)
418
417
* lazy VACUUMs, because they won't be fazed by missing index entries
419
418
* either. (Manual ANALYZEs, however, can't be excluded because they
420
419
* might be within transactions that are going to do arbitrary operations
421
- * later.) Processes running CREATE INDEX CONCURRENTLY or REINDEX CONCURRENTLY
422
- * on indexes that are neither expressional nor partial are also safe to
423
- * ignore, since we know that those processes won't examine any data
424
- * outside the table they're indexing.
420
+ * later.)
425
421
*
426
422
* Also, GetCurrentVirtualXIDs never reports our own vxid, so we need not
427
423
* check for that.
@@ -442,8 +438,7 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
442
438
VirtualTransactionId * old_snapshots ;
443
439
444
440
old_snapshots = GetCurrentVirtualXIDs (limitXmin , true, false,
445
- PROC_IS_AUTOVACUUM | PROC_IN_VACUUM
446
- | PROC_IN_SAFE_IC ,
441
+ PROC_IS_AUTOVACUUM | PROC_IN_VACUUM ,
447
442
& n_old_snapshots );
448
443
if (progress )
449
444
pgstat_progress_update_param (PROGRESS_WAITFOR_TOTAL , n_old_snapshots );
@@ -463,8 +458,7 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
463
458
464
459
newer_snapshots = GetCurrentVirtualXIDs (limitXmin ,
465
460
true, false,
466
- PROC_IS_AUTOVACUUM | PROC_IN_VACUUM
467
- | PROC_IN_SAFE_IC ,
461
+ PROC_IS_AUTOVACUUM | PROC_IN_VACUUM ,
468
462
& n_newer_snapshots );
469
463
for (j = i ; j < n_old_snapshots ; j ++ )
470
464
{
@@ -578,7 +572,6 @@ DefineIndex(Oid tableId,
578
572
amoptions_function amoptions ;
579
573
bool exclusion ;
580
574
bool partitioned ;
581
- bool safe_index ;
582
575
Datum reloptions ;
583
576
int16 * coloptions ;
584
577
IndexInfo * indexInfo ;
@@ -1181,10 +1174,6 @@ DefineIndex(Oid tableId,
1181
1174
}
1182
1175
}
1183
1176
1184
- /* Is index safe for others to ignore? See set_indexsafe_procflags() */
1185
- safe_index = indexInfo -> ii_Expressions == NIL &&
1186
- indexInfo -> ii_Predicate == NIL ;
1187
-
1188
1177
/*
1189
1178
* Report index creation if appropriate (delay this till after most of the
1190
1179
* error checks)
@@ -1671,10 +1660,6 @@ DefineIndex(Oid tableId,
1671
1660
CommitTransactionCommand ();
1672
1661
StartTransactionCommand ();
1673
1662
1674
- /* Tell concurrent index builds to ignore us, if index qualifies */
1675
- if (safe_index )
1676
- set_indexsafe_procflags ();
1677
-
1678
1663
/*
1679
1664
* The index is now visible, so we can report the OID. While on it,
1680
1665
* include the report for the beginning of phase 2.
@@ -1729,9 +1714,6 @@ DefineIndex(Oid tableId,
1729
1714
CommitTransactionCommand ();
1730
1715
StartTransactionCommand ();
1731
1716
1732
- /* Tell concurrent index builds to ignore us, if index qualifies */
1733
- if (safe_index )
1734
- set_indexsafe_procflags ();
1735
1717
pgstat_progress_update_param (PROGRESS_CREATEIDX_PHASE ,
1736
1718
PROGRESS_CREATEIDX_PHASE_WAIT_2 );
1737
1719
/*
@@ -1761,10 +1743,6 @@ DefineIndex(Oid tableId,
1761
1743
CommitTransactionCommand ();
1762
1744
StartTransactionCommand ();
1763
1745
1764
- /* Tell concurrent index builds to ignore us, if index qualifies */
1765
- if (safe_index )
1766
- set_indexsafe_procflags ();
1767
-
1768
1746
/*
1769
1747
* Phase 3 of concurrent index build
1770
1748
*
@@ -1790,9 +1768,7 @@ DefineIndex(Oid tableId,
1790
1768
1791
1769
CommitTransactionCommand ();
1792
1770
StartTransactionCommand ();
1793
- /* Tell concurrent index builds to ignore us, if index qualifies */
1794
- if (safe_index )
1795
- set_indexsafe_procflags ();
1771
+
1796
1772
/*
1797
1773
* Merge content of auxiliary and target indexes - insert any missing index entries.
1798
1774
*/
@@ -1809,9 +1785,6 @@ DefineIndex(Oid tableId,
1809
1785
CommitTransactionCommand ();
1810
1786
StartTransactionCommand ();
1811
1787
1812
- /* Tell concurrent index builds to ignore us, if index qualifies */
1813
- if (safe_index )
1814
- set_indexsafe_procflags ();
1815
1788
1816
1789
/* We should now definitely not be advertising any xmin. */
1817
1790
Assert (MyProc -> xmin == InvalidTransactionId );
@@ -1852,10 +1825,6 @@ DefineIndex(Oid tableId,
1852
1825
CommitTransactionCommand ();
1853
1826
StartTransactionCommand ();
1854
1827
1855
- /* Tell concurrent index builds to ignore us, if index qualifies */
1856
- if (safe_index )
1857
- set_indexsafe_procflags ();
1858
-
1859
1828
pgstat_progress_update_param (PROGRESS_CREATEIDX_PHASE ,
1860
1829
PROGRESS_CREATEIDX_PHASE_WAIT_5 );
1861
1830
/* Now wait for all transaction to see auxiliary as "non-ready for inserts" */
@@ -1876,10 +1845,6 @@ DefineIndex(Oid tableId,
1876
1845
CommitTransactionCommand ();
1877
1846
StartTransactionCommand ();
1878
1847
1879
- /* Tell concurrent index builds to ignore us, if index qualifies */
1880
- if (safe_index )
1881
- set_indexsafe_procflags ();
1882
-
1883
1848
pgstat_progress_update_param (PROGRESS_CREATEIDX_PHASE ,
1884
1849
PROGRESS_CREATEIDX_PHASE_WAIT_6 );
1885
1850
/* Now wait for all transaction to ignore auxiliary because it is dead */
@@ -3620,7 +3585,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
3620
3585
Oid junkAuxIndexId ;
3621
3586
Oid tableId ;
3622
3587
Oid amId ;
3623
- bool safe ; /* for set_indexsafe_procflags */
3624
3588
} ReindexIndexInfo ;
3625
3589
List * heapRelationIds = NIL ;
3626
3590
List * indexIds = NIL ;
@@ -3994,17 +3958,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
3994
3958
save_nestlevel = NewGUCNestLevel ();
3995
3959
RestrictSearchPath ();
3996
3960
3997
- /* determine safety of this index for set_indexsafe_procflags */
3998
- idx -> safe = (RelationGetIndexExpressions (indexRel ) == NIL &&
3999
- RelationGetIndexPredicate (indexRel ) == NIL );
4000
-
4001
- #ifdef USE_INJECTION_POINTS
4002
- if (idx -> safe )
4003
- INJECTION_POINT ("reindex-conc-index-safe" , NULL );
4004
- else
4005
- INJECTION_POINT ("reindex-conc-index-not-safe" , NULL );
4006
- #endif
4007
-
4008
3961
idx -> tableId = RelationGetRelid (heapRel );
4009
3962
idx -> amId = indexRel -> rd_rel -> relam ;
4010
3963
@@ -4070,7 +4023,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4070
4023
newidx -> indexId = newIndexId ;
4071
4024
newidx -> auxIndexId = auxIndexId ;
4072
4025
newidx -> junkAuxIndexId = junkAuxIndexId ;
4073
- newidx -> safe = idx -> safe ;
4074
4026
newidx -> tableId = idx -> tableId ;
4075
4027
newidx -> amId = idx -> amId ;
4076
4028
@@ -4171,11 +4123,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4171
4123
CommitTransactionCommand ();
4172
4124
StartTransactionCommand ();
4173
4125
4174
- /*
4175
- * Because we don't take a snapshot in this transaction, there's no need
4176
- * to set the PROC_IN_SAFE_IC flag here.
4177
- */
4178
-
4179
4126
/*
4180
4127
* Phase 2 of REINDEX CONCURRENTLY
4181
4128
*
@@ -4207,10 +4154,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4207
4154
*/
4208
4155
CHECK_FOR_INTERRUPTS ();
4209
4156
4210
- /* Tell concurrent indexing to ignore us, if index qualifies */
4211
- if (newidx -> safe )
4212
- set_indexsafe_procflags ();
4213
-
4214
4157
/* Build auxiliary index, it is fast - without any actual heap scan, just an empty index. */
4215
4158
index_concurrently_build (newidx -> tableId , newidx -> auxIndexId );
4216
4159
@@ -4219,11 +4162,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4219
4162
4220
4163
StartTransactionCommand ();
4221
4164
4222
- /*
4223
- * Because we don't take a snapshot in this transaction, there's no need
4224
- * to set the PROC_IN_SAFE_IC flag here.
4225
- */
4226
-
4227
4165
pgstat_progress_update_param (PROGRESS_CREATEIDX_PHASE ,
4228
4166
PROGRESS_CREATEIDX_PHASE_WAIT_2 );
4229
4167
/*
@@ -4248,10 +4186,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4248
4186
*/
4249
4187
CHECK_FOR_INTERRUPTS ();
4250
4188
4251
- /* Tell concurrent indexing to ignore us, if index qualifies */
4252
- if (newidx -> safe )
4253
- set_indexsafe_procflags ();
4254
-
4255
4189
/*
4256
4190
* Update progress for the index to build, with the correct parent
4257
4191
* table involved.
@@ -4271,11 +4205,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4271
4205
4272
4206
StartTransactionCommand ();
4273
4207
4274
- /*
4275
- * Because we don't take a snapshot or Xid in this transaction, there's no
4276
- * need to set the PROC_IN_SAFE_IC flag here.
4277
- */
4278
-
4279
4208
pgstat_progress_update_param (PROGRESS_CREATEIDX_PHASE ,
4280
4209
PROGRESS_CREATEIDX_PHASE_WAIT_3 );
4281
4210
WaitForLockersMultiple (lockTags , ShareLock , true);
@@ -4297,10 +4226,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4297
4226
*/
4298
4227
CHECK_FOR_INTERRUPTS ();
4299
4228
4300
- /* Tell concurrent indexing to ignore us, if index qualifies */
4301
- if (newidx -> safe )
4302
- set_indexsafe_procflags ();
4303
-
4304
4229
/*
4305
4230
* Updating pg_index might involve TOAST table access, so ensure we
4306
4231
* have a valid snapshot.
@@ -4336,10 +4261,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4336
4261
*/
4337
4262
CHECK_FOR_INTERRUPTS ();
4338
4263
4339
- /* Tell concurrent indexing to ignore us, if index qualifies */
4340
- if (newidx -> safe )
4341
- set_indexsafe_procflags ();
4342
-
4343
4264
/*
4344
4265
* Update progress for the index to build, with the correct parent
4345
4266
* table involved.
@@ -4367,9 +4288,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4367
4288
* interesting tuples. But since it might not contain tuples deleted
4368
4289
* just before the latest snap was taken, we have to wait out any
4369
4290
* transactions that might have older snapshots.
4370
- *
4371
- * Because we don't take a snapshot or Xid in this transaction,
4372
- * there's no need to set the PROC_IN_SAFE_IC flag here.
4373
4291
*/
4374
4292
pgstat_progress_update_param (PROGRESS_CREATEIDX_PHASE ,
4375
4293
PROGRESS_CREATEIDX_PHASE_WAIT_4 );
@@ -4391,13 +4309,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4391
4309
INJECTION_POINT ("reindex_relation_concurrently_before_swap" , NULL );
4392
4310
StartTransactionCommand ();
4393
4311
4394
- /*
4395
- * Because this transaction only does catalog manipulations and doesn't do
4396
- * any index operations, we can set the PROC_IN_SAFE_IC flag here
4397
- * unconditionally.
4398
- */
4399
- set_indexsafe_procflags ();
4400
-
4401
4312
forboth (lc , indexIds , lc2 , newIndexIds )
4402
4313
{
4403
4314
ReindexIndexInfo * oldidx = lfirst (lc );
@@ -4453,12 +4364,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4453
4364
CommitTransactionCommand ();
4454
4365
StartTransactionCommand ();
4455
4366
4456
- /*
4457
- * While we could set PROC_IN_SAFE_IC if all indexes qualified, there's no
4458
- * real need for that, because we only acquire an Xid after the wait is
4459
- * done, and that lasts for a very short period.
4460
- */
4461
-
4462
4367
/*
4463
4368
* Phase 5 of REINDEX CONCURRENTLY
4464
4369
*
@@ -4522,12 +4427,6 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
4522
4427
CommitTransactionCommand ();
4523
4428
StartTransactionCommand ();
4524
4429
4525
- /*
4526
- * While we could set PROC_IN_SAFE_IC if all indexes qualified, there's no
4527
- * real need for that, because we only acquire an Xid after the wait is
4528
- * done, and that lasts for a very short period.
4529
- */
4530
-
4531
4430
/*
4532
4431
* Phase 6 of REINDEX CONCURRENTLY
4533
4432
*
@@ -4795,36 +4694,3 @@ update_relispartition(Oid relationId, bool newval)
4795
4694
table_close (classRel , RowExclusiveLock );
4796
4695
}
4797
4696
4798
- /*
4799
- * Set the PROC_IN_SAFE_IC flag in MyProc->statusFlags.
4800
- *
4801
- * When doing concurrent index builds, we can set this flag
4802
- * to tell other processes concurrently running CREATE
4803
- * INDEX CONCURRENTLY or REINDEX CONCURRENTLY to ignore us when
4804
- * doing their waits for concurrent snapshots. On one hand it
4805
- * avoids pointlessly waiting for a process that's not interesting
4806
- * anyway; but more importantly it avoids deadlocks in some cases.
4807
- *
4808
- * This can be done safely only for indexes that don't execute any
4809
- * expressions that could access other tables, so index must not be
4810
- * expressional nor partial. Caller is responsible for only calling
4811
- * this routine when that assumption holds true.
4812
- *
4813
- * (The flag is reset automatically at transaction end, so it must be
4814
- * set for each transaction.)
4815
- */
4816
- static inline void
4817
- set_indexsafe_procflags (void )
4818
- {
4819
- /*
4820
- * This should only be called before installing xid or xmin in MyProc;
4821
- * otherwise, concurrent processes could see an Xmin that moves backwards.
4822
- */
4823
- Assert (MyProc -> xid == InvalidTransactionId &&
4824
- MyProc -> xmin == InvalidTransactionId );
4825
-
4826
- LWLockAcquire (ProcArrayLock , LW_EXCLUSIVE );
4827
- MyProc -> statusFlags |= PROC_IN_SAFE_IC ;
4828
- ProcGlobal -> statusFlags [MyProc -> pgxactoff ] = MyProc -> statusFlags ;
4829
- LWLockRelease (ProcArrayLock );
4830
- }
0 commit comments