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

Commit8aa4496

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 parent29f20db commit8aa4496

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
@@ -2803,6 +2803,13 @@ ReindexRelationConcurrently(Oid relationOid, int options)
28032803
char*relationName=NULL;
28042804
char*relationNamespace=NULL;
28052805
PGRUsageru0;
2806+
constintprogress_index[]= {
2807+
PROGRESS_CREATEIDX_COMMAND,
2808+
PROGRESS_CREATEIDX_PHASE,
2809+
PROGRESS_CREATEIDX_INDEX_OID,
2810+
PROGRESS_CREATEIDX_ACCESS_METHOD_OID
2811+
};
2812+
int64progress_vals[4];
28062813

28072814
/*
28082815
* Create a memory context that will survive forced transaction commits we
@@ -3045,12 +3052,11 @@ ReindexRelationConcurrently(Oid relationOid, int options)
30453052

30463053
pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX,
30473054
RelationGetRelid(heapRel));
3048-
pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND,
3049-
PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY);
3050-
pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID,
3051-
indexId);
3052-
pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID,
3053-
indexRel->rd_rel->relam);
3055+
progress_vals[0]=PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY;
3056+
progress_vals[1]=0;/* initializing */
3057+
progress_vals[2]=indexId;
3058+
progress_vals[3]=indexRel->rd_rel->relam;
3059+
pgstat_progress_update_multi_param(4,progress_index,progress_vals);
30543060

30553061
/* Choose a temporary relation name for the new index */
30563062
concurrentName=ChooseRelationName(get_rel_name(indexId),
@@ -3154,12 +3160,12 @@ ReindexRelationConcurrently(Oid relationOid, int options)
31543160
WaitForLockersMultiple(lockTags,ShareLock, true);
31553161
CommitTransactionCommand();
31563162

3157-
forboth(lc,indexIds,lc2,newIndexIds)
3163+
foreach(lc,newIndexIds)
31583164
{
3159-
RelationindexRel;
3160-
OidoldIndexId=lfirst_oid(lc);
3161-
OidnewIndexId=lfirst_oid(lc2);
3165+
RelationnewIndexRel;
3166+
OidnewIndexId=lfirst_oid(lc);
31623167
OidheapId;
3168+
Oidindexam;
31633169

31643170
/* Start new transaction for this index's concurrent build */
31653171
StartTransactionCommand();
@@ -3178,9 +3184,21 @@ ReindexRelationConcurrently(Oid relationOid, int options)
31783184
* Index relation has been closed by previous commit, so reopen it to
31793185
* get its information.
31803186
*/
3181-
indexRel=index_open(oldIndexId,ShareUpdateExclusiveLock);
3182-
heapId=indexRel->rd_index->indrelid;
3183-
index_close(indexRel,NoLock);
3187+
newIndexRel=index_open(newIndexId,ShareUpdateExclusiveLock);
3188+
heapId=newIndexRel->rd_index->indrelid;
3189+
indexam=newIndexRel->rd_rel->relam;
3190+
index_close(newIndexRel,NoLock);
3191+
3192+
/*
3193+
* Update progress for the index to build, with the correct parent
3194+
* table involved.
3195+
*/
3196+
pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX,heapId);
3197+
progress_vals[0]=PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY;
3198+
progress_vals[1]=PROGRESS_CREATEIDX_PHASE_BUILD;
3199+
progress_vals[2]=newIndexId;
3200+
progress_vals[3]=indexam;
3201+
pgstat_progress_update_multi_param(4,progress_index,progress_vals);
31843202

31853203
/* Perform concurrent build of new index */
31863204
index_concurrently_build(heapId,newIndexId);
@@ -3209,6 +3227,8 @@ ReindexRelationConcurrently(Oid relationOid, int options)
32093227
OidheapId;
32103228
TransactionIdlimitXmin;
32113229
Snapshotsnapshot;
3230+
RelationnewIndexRel;
3231+
Oidindexam;
32123232

32133233
StartTransactionCommand();
32143234

@@ -3219,15 +3239,33 @@ ReindexRelationConcurrently(Oid relationOid, int options)
32193239
*/
32203240
CHECK_FOR_INTERRUPTS();
32213241

3222-
heapId=IndexGetRelation(newIndexId, false);
3223-
32243242
/*
32253243
* Take the "reference snapshot" that will be used by validate_index()
32263244
* to filter candidate tuples.
32273245
*/
32283246
snapshot=RegisterSnapshot(GetTransactionSnapshot());
32293247
PushActiveSnapshot(snapshot);
32303248

3249+
/*
3250+
* Index relation has been closed by previous commit, so reopen it to
3251+
* get its information.
3252+
*/
3253+
newIndexRel=index_open(newIndexId,ShareUpdateExclusiveLock);
3254+
heapId=newIndexRel->rd_index->indrelid;
3255+
indexam=newIndexRel->rd_rel->relam;
3256+
index_close(newIndexRel,NoLock);
3257+
3258+
/*
3259+
* Update progress for the index to build, with the correct parent
3260+
* table involved.
3261+
*/
3262+
pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX,heapId);
3263+
progress_vals[0]=PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY;
3264+
progress_vals[1]=PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN;
3265+
progress_vals[2]=newIndexId;
3266+
progress_vals[3]=indexam;
3267+
pgstat_progress_update_multi_param(4,progress_index,progress_vals);
3268+
32313269
validate_index(heapId,newIndexId,snapshot);
32323270

32333271
/*
@@ -3362,7 +3400,7 @@ ReindexRelationConcurrently(Oid relationOid, int options)
33623400
*/
33633401

33643402
pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE,
3365-
PROGRESS_CREATEIDX_PHASE_WAIT_4);
3403+
PROGRESS_CREATEIDX_PHASE_WAIT_5);
33663404
WaitForLockersMultiple(lockTags,AccessExclusiveLock, true);
33673405

33683406
PushActiveSnapshot(GetTransactionSnapshot());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp