Skip to content

Commit 6b8544f

Browse files
qoops-1hackorum
authored andcommitted
partition_relid column for create index progress
1 parent 8d6d6c9 commit 6b8544f

6 files changed

Lines changed: 32 additions & 10 deletions

File tree

doc/src/sgml/monitoring.sgml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7250,6 +7250,15 @@ FROM pg_stat_get_backend_idset() AS backendid;
72507250
<literal>0</literal> when the index is not partitioned.
72517251
</para></entry>
72527252
</row>
7253+
<row>
7254+
<entry role="catalog_table_entry"><para role="column_definition">
7255+
<structfield>partition_relid</structfield> <type>bigint</type>
7256+
</para>
7257+
<para>
7258+
OID of the partition on which the index is currently being created.
7259+
<literal>0</literal> when the index is not partitioned.
7260+
</para></entry>
7261+
</row>
72537262
</tbody>
72547263
</tgroup>
72557264
</table>

src/backend/catalog/index.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,17 +3703,19 @@ reindex_index(const ReindexStmt *stmt, Oid indexId,
37033703
{
37043704
const int progress_cols[] = {
37053705
PROGRESS_CREATEIDX_COMMAND,
3706-
PROGRESS_CREATEIDX_INDEX_OID
3706+
PROGRESS_CREATEIDX_INDEX_OID,
3707+
PROGRESS_CREATEIDX_PARTITION_RELID
37073708
};
37083709
const int64 progress_vals[] = {
37093710
PROGRESS_CREATEIDX_COMMAND_REINDEX,
3710-
indexId
3711+
indexId,
3712+
partition ? heapId : 0
37113713
};
37123714

37133715
if (!partition)
37143716
pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX,
37153717
heapId);
3716-
pgstat_progress_update_multi_param(2, progress_cols, progress_vals);
3718+
pgstat_progress_update_multi_param(3, progress_cols, progress_vals);
37173719
}
37183720

37193721
/*

src/backend/catalog/system_views.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,8 @@ CREATE VIEW pg_stat_progress_create_index AS
14391439
S.param12 AS tuples_total,
14401440
S.param13 AS tuples_done,
14411441
S.param14 AS partitions_total,
1442-
S.param15 AS partitions_done
1442+
S.param15 AS partitions_done,
1443+
S.param18 AS partition_relid
14431444
FROM pg_stat_get_progress_info('CREATE INDEX') AS S
14441445
LEFT JOIN pg_database D ON S.datid = D.oid;
14451446

src/backend/commands/indexcmds.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,10 @@ DefineIndex(ParseState *pstate,
643643
PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY :
644644
PROGRESS_CREATEIDX_COMMAND_CREATE);
645645
}
646+
else
647+
{
648+
pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITION_RELID, tableId);
649+
}
646650

647651
/*
648652
* No index OID to report yet
@@ -3791,9 +3795,10 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
37913795
PROGRESS_CREATEIDX_COMMAND,
37923796
PROGRESS_CREATEIDX_PHASE,
37933797
PROGRESS_CREATEIDX_INDEX_OID,
3794-
PROGRESS_CREATEIDX_ACCESS_METHOD_OID
3798+
PROGRESS_CREATEIDX_ACCESS_METHOD_OID,
3799+
PROGRESS_CREATEIDX_PARTITION_RELID
37953800
};
3796-
int64 progress_vals[4];
3801+
int64 progress_vals[5];
37973802

37983803
/*
37993804
* Create a memory context that will survive forced transaction commits we
@@ -4145,7 +4150,8 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
41454150
progress_vals[1] = 0; /* initializing */
41464151
progress_vals[2] = idx->indexId;
41474152
progress_vals[3] = idx->amId;
4148-
pgstat_progress_update_multi_param(4, progress_index, progress_vals);
4153+
progress_vals[4] = partition ? idx->tableId : 0;
4154+
pgstat_progress_update_multi_param(5, progress_index, progress_vals);
41494155

41504156
/* Choose a temporary relation name for the new index */
41514157
concurrentName = ChooseRelationName(get_rel_name(idx->indexId),
@@ -4323,7 +4329,8 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
43234329
progress_vals[1] = PROGRESS_CREATEIDX_PHASE_BUILD;
43244330
progress_vals[2] = newidx->indexId;
43254331
progress_vals[3] = newidx->amId;
4326-
pgstat_progress_update_multi_param(4, progress_index, progress_vals);
4332+
progress_vals[4] = partition ? newidx->tableId : 0;
4333+
pgstat_progress_update_multi_param(5, progress_index, progress_vals);
43274334

43284335
/* Perform concurrent build of new index */
43294336
index_concurrently_build(newidx->tableId, newidx->indexId);
@@ -4390,7 +4397,8 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
43904397
progress_vals[1] = PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN;
43914398
progress_vals[2] = newidx->indexId;
43924399
progress_vals[3] = newidx->amId;
4393-
pgstat_progress_update_multi_param(4, progress_index, progress_vals);
4400+
progress_vals[4] = partition ? newidx->tableId : 0;
4401+
pgstat_progress_update_multi_param(5, progress_index, progress_vals);
43944402

43954403
validate_index(newidx->tableId, newidx->indexId, snapshot);
43964404

src/include/commands/progress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
#define PROGRESS_CREATEIDX_PARTITIONS_TOTAL 13
118118
#define PROGRESS_CREATEIDX_PARTITIONS_DONE 14
119119
/* 15 and 16 reserved for "block number" metrics */
120+
#define PROGRESS_CREATEIDX_PARTITION_RELID 17
120121

121122
/* Phases of CREATE INDEX (as advertised via PROGRESS_CREATEIDX_PHASE) */
122123
#define PROGRESS_CREATEIDX_PHASE_WAIT_1 1

src/test/regress/expected/rules.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,8 @@ pg_stat_progress_create_index| SELECT s.pid,
21052105
s.param12 AS tuples_total,
21062106
s.param13 AS tuples_done,
21072107
s.param14 AS partitions_total,
2108-
s.param15 AS partitions_done
2108+
s.param15 AS partitions_done,
2109+
s.param18 AS partition_relid
21092110
FROM (pg_stat_get_progress_info('CREATE INDEX'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20)
21102111
LEFT JOIN pg_database d ON ((s.datid = d.oid)));
21112112
pg_stat_progress_data_checksums| SELECT s.pid,

0 commit comments

Comments
 (0)