mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +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:
@ -1216,6 +1216,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
|
||||
InvalidOid,
|
||||
RelationGetRelid(idxRel),
|
||||
constraintOid,
|
||||
-1,
|
||||
false, false, false, false, false);
|
||||
|
||||
index_close(idxRel, AccessShareLock);
|
||||
@ -8640,6 +8641,7 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
|
||||
InvalidOid, /* no predefined OID */
|
||||
InvalidOid, /* no parent index */
|
||||
InvalidOid, /* no parent constraint */
|
||||
-1, /* total_parts unknown */
|
||||
true, /* is_alter_table */
|
||||
check_rights,
|
||||
false, /* check_not_in_use - we did it already */
|
||||
@ -18106,6 +18108,7 @@ AttachPartitionEnsureIndexes(Relation rel, Relation attachrel)
|
||||
DefineIndex(RelationGetRelid(attachrel), stmt, InvalidOid,
|
||||
RelationGetRelid(idxRel),
|
||||
conOid,
|
||||
-1,
|
||||
true, false, false, false, false);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user