Use pgstat_progress_update_multi_param() where possible
authorMichael Paquier <[email protected]>
Mon, 22 Feb 2021 05:21:40 +0000 (14:21 +0900)
committerMichael Paquier <[email protected]>
Mon, 22 Feb 2021 05:21:40 +0000 (14:21 +0900)
This commit changes one code path in REINDEX INDEX and one code path
in CREATE INDEX CONCURRENTLY to report the progress of each operation
using pgstat_progress_update_multi_param() rather than
multiple calls to pgstat_progress_update_param().  This has the
advantage to make the progress report more consistent to the end-user
without impacting the amount of information provided.

Author: Bharath Rupireddy
Discussion: https://postgr.es/m/CALj2ACV5zW7GxD8D_tyO==bcj6ZktQchEKWKPBOAGKiLhAQo=w@mail.gmail.com

src/backend/catalog/index.c
src/backend/commands/indexcmds.c

index b4ab0b88ad09e12a99ce1188d2a90f3f32c8e524..ea22256819c29cbfe1199fcbf806f35a05f666bd 100644 (file)
@@ -3686,12 +3686,18 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence,
 
    if (progress)
    {
+       const int   progress_cols[] = {
+           PROGRESS_CREATEIDX_COMMAND,
+           PROGRESS_CREATEIDX_INDEX_OID
+       };
+       const int64 progress_vals[] = {
+           PROGRESS_CREATEIDX_COMMAND_REINDEX,
+           indexId
+       };
+
        pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX,
                                      heapId);
-       pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND,
-                                    PROGRESS_CREATEIDX_COMMAND_REINDEX);
-       pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID,
-                                    indexId);
+       pgstat_progress_update_multi_param(2, progress_cols, progress_vals);
    }
 
    /*
index e1bed087d7cb9169ecaa8b98851173921e118daf..8bc652ecd39c401cfff2855013f294e54a33db3a 100644 (file)
@@ -1457,10 +1457,21 @@ DefineIndex(Oid relationId,
        set_indexsafe_procflags();
 
    /*
-    * The index is now visible, so we can report the OID.
+    * The index is now visible, so we can report the OID.  While on it,
+    * include the report for the beginning of phase 2.
     */
-   pgstat_progress_update_param(PROGRESS_CREATEIDX_INDEX_OID,
-                                indexRelationId);
+   {
+       const int   progress_cols[] = {
+           PROGRESS_CREATEIDX_INDEX_OID,
+           PROGRESS_CREATEIDX_PHASE
+       };
+       const int64 progress_vals[] = {
+           indexRelationId,
+           PROGRESS_CREATEIDX_PHASE_WAIT_1
+       };
+
+       pgstat_progress_update_multi_param(2, progress_cols, progress_vals);
+   }
 
    /*
     * Phase 2 of concurrent index build (see comments for validate_index()
@@ -1478,8 +1489,6 @@ DefineIndex(Oid relationId,
     * exclusive lock on our table.  The lock code will detect deadlock and
     * error out properly.
     */
-   pgstat_progress_update_param(PROGRESS_CREATEIDX_PHASE,
-                                PROGRESS_CREATEIDX_PHASE_WAIT_1);
    WaitForLockers(heaplocktag, ShareLock, true);
 
    /*