Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite66bcfb

Browse files
committed
Fix progress reporting of REINDEX CONCURRENTLY
This addresses a couple of issues with the so-said subject:- Report the correct parent relation with the index actually beingrebuilt or validated. Previously, the command status remained set tothe last index created for the progress of the index build andvalidation, which would be incorrect when working on a table that hasmore than one index.- Use the correct phase when waiting before the drop of the oldindexes. Previously, this was reported with the same status as whenwaiting before the old indexes are marked as dead.Author: Matthias van de Meent, Michael PaquierDiscussion:https://postgr.es/m/CAEze2WhqFgcwe1_tv=sFYhLWV2AdpfukumotJ6JNcAOQs3jufg@mail.gmail.comBackpatch-through: 12
1 parent56fe008 commite66bcfb

File tree

1 file changed

+54
-16
lines changed

1 file changed

+54
-16
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,13 @@ ReindexRelationConcurrently(Oid relationOid, int options)
30153015
char*relationName=NULL;
30163016
char*relationNamespace=NULL;
30173017
PGRUsageru0;
3018+
constintprogress_index[]= {
3019+
PROGRESS_CREATEIDX_COMMAND,
3020+
PROGRESS_CREATEIDX_PHASE,
3021+
PROGRESS_CREATEIDX_INDEX_OID,
3022+
PROGRESS_CREATEIDX_ACCESS_METHOD_OID
3023+
};
3024+
int64progress_vals[4];
30183025

30193026
/*
30203027
* Create a memory context that will survive forced transaction commits we
@@ -3294,12 +3301,11 @@ ReindexRelationConcurrently(Oid relationOid, int options)
32943301

32953302
pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX,
32963303
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);
33033309

33043310
/* Choose a temporary relation name for the new index */
33053311
concurrentName=ChooseRelationName(get_rel_name(indexId),
@@ -3403,12 +3409,12 @@ ReindexRelationConcurrently(Oid relationOid, int options)
34033409
WaitForLockersMultiple(lockTags,ShareLock, true);
34043410
CommitTransactionCommand();
34053411

3406-
forboth(lc,indexIds,lc2,newIndexIds)
3412+
foreach(lc,newIndexIds)
34073413
{
3408-
RelationindexRel;
3409-
OidoldIndexId=lfirst_oid(lc);
3410-
OidnewIndexId=lfirst_oid(lc2);
3414+
RelationnewIndexRel;
3415+
OidnewIndexId=lfirst_oid(lc);
34113416
OidheapId;
3417+
Oidindexam;
34123418

34133419
/* Start new transaction for this index's concurrent build */
34143420
StartTransactionCommand();
@@ -3427,9 +3433,21 @@ ReindexRelationConcurrently(Oid relationOid, int options)
34273433
* Index relation has been closed by previous commit, so reopen it to
34283434
* get its information.
34293435
*/
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);
34333451

34343452
/* Perform concurrent build of new index */
34353453
index_concurrently_build(heapId,newIndexId);
@@ -3458,6 +3476,8 @@ ReindexRelationConcurrently(Oid relationOid, int options)
34583476
OidheapId;
34593477
TransactionIdlimitXmin;
34603478
Snapshotsnapshot;
3479+
RelationnewIndexRel;
3480+
Oidindexam;
34613481

34623482
StartTransactionCommand();
34633483

@@ -3468,15 +3488,33 @@ ReindexRelationConcurrently(Oid relationOid, int options)
34683488
*/
34693489
CHECK_FOR_INTERRUPTS();
34703490

3471-
heapId=IndexGetRelation(newIndexId, false);
3472-
34733491
/*
34743492
* Take the "reference snapshot" that will be used by validate_index()
34753493
* to filter candidate tuples.
34763494
*/
34773495
snapshot=RegisterSnapshot(GetTransactionSnapshot());
34783496
PushActiveSnapshot(snapshot);
34793497

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+
34803518
validate_index(heapId,newIndexId,snapshot);
34813519

34823520
/*
@@ -3611,7 +3649,7 @@ ReindexRelationConcurrently(Oid relationOid, int options)
36113649
*/
36123650

36133651
pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE,
3614-
PROGRESS_CREATEIDX_PHASE_WAIT_4);
3652+
PROGRESS_CREATEIDX_PHASE_WAIT_5);
36153653
WaitForLockersMultiple(lockTags,AccessExclusiveLock, true);
36163654

36173655
PushActiveSnapshot(GetTransactionSnapshot());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp