1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Fix CREATE INDEX progress reporting for multi-level partitioning.

The "partitions_total" and "partitions_done" fields were updated
as though the current level of partitioning was the only one.
In multi-level cases, not only could partitions_total change
over the course of the command, but partitions_done could go
backwards or exceed the currently-reported partitions_total.

Fix by setting partitions_total to the total number of direct
and indirect children once at command start, and then just
incrementing partitions_done at appropriate points.  Invent
a new progress monitoring function "pgstat_progress_incr_param"
to simplify doing the latter.  We can avoid adding cost for the
former when doing CREATE INDEX, because ProcessUtility already
enumerates the children and it's pretty easy to pass the count
down to DefineIndex.  In principle the same could be done in
ALTER TABLE, but that's structurally difficult; for now, just
eat the cost of an extra find_all_inheritors scan in that case.

Ilya Gladyshev and Justin Pryzby

Discussion: https://postgr.es/m/a15f904a70924ffa4ca25c3c744cff31e0e6e143.camel@gmail.com
This commit is contained in:
Tom Lane
2023-03-25 15:33:56 -04:00
parent 81a6d57e33
commit 27f5c712b2
8 changed files with 106 additions and 15 deletions

View File

@ -6817,7 +6817,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
<structfield>pid</structfield> <type>integer</type>
</para>
<para>
Process ID of backend.
Process ID of the backend creating indexes.
</para></entry>
</row>
@ -6863,7 +6863,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
<structfield>command</structfield> <type>text</type>
</para>
<para>
The command that is running: <literal>CREATE INDEX</literal>,
Specific command type: <literal>CREATE INDEX</literal>,
<literal>CREATE INDEX CONCURRENTLY</literal>,
<literal>REINDEX</literal>, or <literal>REINDEX CONCURRENTLY</literal>.
</para></entry>
@ -6946,9 +6946,10 @@ FROM pg_stat_get_backend_idset() AS backendid;
<structfield>partitions_total</structfield> <type>bigint</type>
</para>
<para>
When creating an index on a partitioned table, this column is set to
the total number of partitions on which the index is to be created.
This field is <literal>0</literal> during a <literal>REINDEX</literal>.
Total number of partitions on which the index is to be created
or attached, including both direct and indirect partitions.
<literal>0</literal> during a <literal>REINDEX</literal>, or when
the index is not partitioned.
</para></entry>
</row>
@ -6957,9 +6958,10 @@ FROM pg_stat_get_backend_idset() AS backendid;
<structfield>partitions_done</structfield> <type>bigint</type>
</para>
<para>
When creating an index on a partitioned table, this column is set to
the number of partitions on which the index has been created.
This field is <literal>0</literal> during a <literal>REINDEX</literal>.
Number of partitions on which the index has already been created
or attached, including both direct and indirect partitions.
<literal>0</literal> during a <literal>REINDEX</literal>, or when
the index is not partitioned.
</para></entry>
</row>
</tbody>