@@ -2837,6 +2837,13 @@ ReindexRelationConcurrently(Oid relationOid, int options)
2837
2837
char * relationName = NULL ;
2838
2838
char * relationNamespace = NULL ;
2839
2839
PGRUsage ru0 ;
2840
+ const int progress_index [] = {
2841
+ PROGRESS_CREATEIDX_COMMAND ,
2842
+ PROGRESS_CREATEIDX_PHASE ,
2843
+ PROGRESS_CREATEIDX_INDEX_OID ,
2844
+ PROGRESS_CREATEIDX_ACCESS_METHOD_OID
2845
+ };
2846
+ int64 progress_vals [4 ];
2840
2847
2841
2848
/*
2842
2849
* Create a memory context that will survive forced transaction commits we
@@ -3079,12 +3086,11 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3079
3086
3080
3087
pgstat_progress_start_command (PROGRESS_COMMAND_CREATE_INDEX ,
3081
3088
RelationGetRelid (heapRel ));
3082
- pgstat_progress_update_param (PROGRESS_CREATEIDX_COMMAND ,
3083
- PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY );
3084
- pgstat_progress_update_param (PROGRESS_CREATEIDX_INDEX_OID ,
3085
- indexId );
3086
- pgstat_progress_update_param (PROGRESS_CREATEIDX_ACCESS_METHOD_OID ,
3087
- indexRel -> rd_rel -> relam );
3089
+ progress_vals [0 ] = PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY ;
3090
+ progress_vals [1 ] = 0 ; /* initializing */
3091
+ progress_vals [2 ] = indexId ;
3092
+ progress_vals [3 ] = indexRel -> rd_rel -> relam ;
3093
+ pgstat_progress_update_multi_param (4 , progress_index , progress_vals );
3088
3094
3089
3095
/* Choose a temporary relation name for the new index */
3090
3096
concurrentName = ChooseRelationName (get_rel_name (indexId ),
@@ -3188,12 +3194,12 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3188
3194
WaitForLockersMultiple (lockTags , ShareLock , true);
3189
3195
CommitTransactionCommand ();
3190
3196
3191
- forboth (lc , indexIds , lc2 , newIndexIds )
3197
+ foreach (lc , newIndexIds )
3192
3198
{
3193
- Relation indexRel ;
3194
- Oid oldIndexId = lfirst_oid (lc );
3195
- Oid newIndexId = lfirst_oid (lc2 );
3199
+ Relation newIndexRel ;
3200
+ Oid newIndexId = lfirst_oid (lc );
3196
3201
Oid heapId ;
3202
+ Oid indexam ;
3197
3203
3198
3204
/* Start new transaction for this index's concurrent build */
3199
3205
StartTransactionCommand ();
@@ -3212,9 +3218,21 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3212
3218
* Index relation has been closed by previous commit, so reopen it to
3213
3219
* get its information.
3214
3220
*/
3215
- indexRel = index_open (oldIndexId , ShareUpdateExclusiveLock );
3216
- heapId = indexRel -> rd_index -> indrelid ;
3217
- index_close (indexRel , NoLock );
3221
+ newIndexRel = index_open (newIndexId , ShareUpdateExclusiveLock );
3222
+ heapId = newIndexRel -> rd_index -> indrelid ;
3223
+ indexam = newIndexRel -> rd_rel -> relam ;
3224
+ index_close (newIndexRel , NoLock );
3225
+
3226
+ /*
3227
+ * Update progress for the index to build, with the correct parent
3228
+ * table involved.
3229
+ */
3230
+ pgstat_progress_start_command (PROGRESS_COMMAND_CREATE_INDEX , heapId );
3231
+ progress_vals [0 ] = PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY ;
3232
+ progress_vals [1 ] = PROGRESS_CREATEIDX_PHASE_BUILD ;
3233
+ progress_vals [2 ] = newIndexId ;
3234
+ progress_vals [3 ] = indexam ;
3235
+ pgstat_progress_update_multi_param (4 , progress_index , progress_vals );
3218
3236
3219
3237
/* Perform concurrent build of new index */
3220
3238
index_concurrently_build (heapId , newIndexId );
@@ -3243,6 +3261,8 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3243
3261
Oid heapId ;
3244
3262
TransactionId limitXmin ;
3245
3263
Snapshot snapshot ;
3264
+ Relation newIndexRel ;
3265
+ Oid indexam ;
3246
3266
3247
3267
StartTransactionCommand ();
3248
3268
@@ -3253,15 +3273,33 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3253
3273
*/
3254
3274
CHECK_FOR_INTERRUPTS ();
3255
3275
3256
- heapId = IndexGetRelation (newIndexId , false);
3257
-
3258
3276
/*
3259
3277
* Take the "reference snapshot" that will be used by validate_index()
3260
3278
* to filter candidate tuples.
3261
3279
*/
3262
3280
snapshot = RegisterSnapshot (GetTransactionSnapshot ());
3263
3281
PushActiveSnapshot (snapshot );
3264
3282
3283
+ /*
3284
+ * Index relation has been closed by previous commit, so reopen it to
3285
+ * get its information.
3286
+ */
3287
+ newIndexRel = index_open (newIndexId , ShareUpdateExclusiveLock );
3288
+ heapId = newIndexRel -> rd_index -> indrelid ;
3289
+ indexam = newIndexRel -> rd_rel -> relam ;
3290
+ index_close (newIndexRel , NoLock );
3291
+
3292
+ /*
3293
+ * Update progress for the index to build, with the correct parent
3294
+ * table involved.
3295
+ */
3296
+ pgstat_progress_start_command (PROGRESS_COMMAND_CREATE_INDEX , heapId );
3297
+ progress_vals [0 ] = PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY ;
3298
+ progress_vals [1 ] = PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN ;
3299
+ progress_vals [2 ] = newIndexId ;
3300
+ progress_vals [3 ] = indexam ;
3301
+ pgstat_progress_update_multi_param (4 , progress_index , progress_vals );
3302
+
3265
3303
validate_index (heapId , newIndexId , snapshot );
3266
3304
3267
3305
/*
@@ -3396,7 +3434,7 @@ ReindexRelationConcurrently(Oid relationOid, int options)
3396
3434
*/
3397
3435
3398
3436
pgstat_progress_update_param (PROGRESS_CREATEIDX_PHASE ,
3399
- PROGRESS_CREATEIDX_PHASE_WAIT_4 );
3437
+ PROGRESS_CREATEIDX_PHASE_WAIT_5 );
3400
3438
WaitForLockersMultiple (lockTags , AccessExclusiveLock , true);
3401
3439
3402
3440
PushActiveSnapshot (GetTransactionSnapshot ());
0 commit comments