@@ -3015,6 +3015,13 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3015
3015
char * relationName = NULL ;
3016
3016
char * relationNamespace = NULL ;
3017
3017
PGRUsage ru0 ;
3018
+ const int progress_index [] = {
3019
+ PROGRESS_CREATEIDX_COMMAND ,
3020
+ PROGRESS_CREATEIDX_PHASE ,
3021
+ PROGRESS_CREATEIDX_INDEX_OID ,
3022
+ PROGRESS_CREATEIDX_ACCESS_METHOD_OID
3023
+ };
3024
+ int64 progress_vals [4 ];
3018
3025
3019
3026
/*
3020
3027
* Create a memory context that will survive forced transaction commits we
@@ -3294,12 +3301,11 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3294
3301
3295
3302
pgstat_progress_start_command (PROGRESS_COMMAND_CREATE_INDEX ,
3296
3303
RelationGetRelid (heapRel ));
3297
- pgstat_progress_update_param (PROGRESS_CREATEIDX_COMMAND ,
3298
- PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY );
3299
- pgstat_progress_update_param (PROGRESS_CREATEIDX_INDEX_OID ,
3300
- indexId );
3301
- pgstat_progress_update_param (PROGRESS_CREATEIDX_ACCESS_METHOD_OID ,
3302
- indexRel -> rd_rel -> relam );
3304
+ progress_vals [0 ] = PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY ;
3305
+ progress_vals [1 ] = 0 ; /* initializing */
3306
+ progress_vals [2 ] = indexId ;
3307
+ progress_vals [3 ] = indexRel -> rd_rel -> relam ;
3308
+ pgstat_progress_update_multi_param (4 , progress_index , progress_vals );
3303
3309
3304
3310
/* Choose a temporary relation name for the new index */
3305
3311
concurrentName = ChooseRelationName (get_rel_name (indexId ),
@@ -3403,12 +3409,12 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3403
3409
WaitForLockersMultiple (lockTags , ShareLock , true);
3404
3410
CommitTransactionCommand ();
3405
3411
3406
- forboth (lc , indexIds , lc2 , newIndexIds )
3412
+ foreach (lc , newIndexIds )
3407
3413
{
3408
- Relation indexRel ;
3409
- Oid oldIndexId = lfirst_oid (lc );
3410
- Oid newIndexId = lfirst_oid (lc2 );
3414
+ Relation newIndexRel ;
3415
+ Oid newIndexId = lfirst_oid (lc );
3411
3416
Oid heapId ;
3417
+ Oid indexam ;
3412
3418
3413
3419
/* Start new transaction for this index's concurrent build */
3414
3420
StartTransactionCommand ();
@@ -3427,9 +3433,21 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3427
3433
* Index relation has been closed by previous commit, so reopen it to
3428
3434
* get its information.
3429
3435
*/
3430
- indexRel = index_open (oldIndexId , ShareUpdateExclusiveLock );
3431
- heapId = indexRel -> rd_index -> indrelid ;
3432
- index_close (indexRel , NoLock );
3436
+ newIndexRel = index_open (newIndexId , ShareUpdateExclusiveLock );
3437
+ heapId = newIndexRel -> rd_index -> indrelid ;
3438
+ indexam = newIndexRel -> rd_rel -> relam ;
3439
+ index_close (newIndexRel , NoLock );
3440
+
3441
+ /*
3442
+ * Update progress for the index to build, with the correct parent
3443
+ * table involved.
3444
+ */
3445
+ pgstat_progress_start_command (PROGRESS_COMMAND_CREATE_INDEX , heapId );
3446
+ progress_vals [0 ] = PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY ;
3447
+ progress_vals [1 ] = PROGRESS_CREATEIDX_PHASE_BUILD ;
3448
+ progress_vals [2 ] = newIndexId ;
3449
+ progress_vals [3 ] = indexam ;
3450
+ pgstat_progress_update_multi_param (4 , progress_index , progress_vals );
3433
3451
3434
3452
/* Perform concurrent build of new index */
3435
3453
index_concurrently_build (heapId , newIndexId );
@@ -3458,6 +3476,8 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3458
3476
Oid heapId ;
3459
3477
TransactionId limitXmin ;
3460
3478
Snapshot snapshot ;
3479
+ Relation newIndexRel ;
3480
+ Oid indexam ;
3461
3481
3462
3482
StartTransactionCommand ();
3463
3483
@@ -3468,15 +3488,33 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3468
3488
*/
3469
3489
CHECK_FOR_INTERRUPTS ();
3470
3490
3471
- heapId = IndexGetRelation (newIndexId , false);
3472
-
3473
3491
/*
3474
3492
* Take the "reference snapshot" that will be used by validate_index()
3475
3493
* to filter candidate tuples.
3476
3494
*/
3477
3495
snapshot = RegisterSnapshot (GetTransactionSnapshot ());
3478
3496
PushActiveSnapshot (snapshot );
3479
3497
3498
+ /*
3499
+ * Index relation has been closed by previous commit, so reopen it to
3500
+ * get its information.
3501
+ */
3502
+ newIndexRel = index_open (newIndexId , ShareUpdateExclusiveLock );
3503
+ heapId = newIndexRel -> rd_index -> indrelid ;
3504
+ indexam = newIndexRel -> rd_rel -> relam ;
3505
+ index_close (newIndexRel , NoLock );
3506
+
3507
+ /*
3508
+ * Update progress for the index to build, with the correct parent
3509
+ * table involved.
3510
+ */
3511
+ pgstat_progress_start_command (PROGRESS_COMMAND_CREATE_INDEX , heapId );
3512
+ progress_vals [0 ] = PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY ;
3513
+ progress_vals [1 ] = PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN ;
3514
+ progress_vals [2 ] = newIndexId ;
3515
+ progress_vals [3 ] = indexam ;
3516
+ pgstat_progress_update_multi_param (4 , progress_index , progress_vals );
3517
+
3480
3518
validate_index (heapId , newIndexId , snapshot );
3481
3519
3482
3520
/*
@@ -3611,7 +3649,7 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3611
3649
*/
3612
3650
3613
3651
pgstat_progress_update_param (PROGRESS_CREATEIDX_PHASE ,
3614
- PROGRESS_CREATEIDX_PHASE_WAIT_4 );
3652
+ PROGRESS_CREATEIDX_PHASE_WAIT_5 );
3615
3653
WaitForLockersMultiple (lockTags , AccessExclusiveLock , true);
3616
3654
3617
3655
PushActiveSnapshot (GetTransactionSnapshot ());
0 commit comments