Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c181f2e

Browse files
committed
Fix briefly showing old progress stats for ANALYZE on inherited tables.
ANALYZE on a table with inheritance children analyzes all the child tables in a loop. When stepping to next child table, it updated the child rel ID value in the command progress stats, but did not reset the 'sample_blks_total' and 'sample_blks_scanned' counters. acquire_sample_rows() updates 'sample_blks_total' as soon as the scan starts and 'sample_blks_scanned' after processing the first block, but until then, pg_stat_progress_analyze would display a bogus combination of the new child table relid with old counter values from the previously processed child table. Fix by resetting 'sample_blks_total' and 'sample_blks_scanned' to zero at the same time that 'current_child_table_relid' is updated. Backpatch to v13, where pg_stat_progress_analyze view was introduced. Reported-by: Justin Pryzby Discussion: https://www.postgresql.org/message-id/20230122162345.GP13860%40telsasoft.com
1 parent 1d5caec commit c181f2e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/backend/commands/analyze.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,8 +1531,25 @@ acquire_inherited_sample_rows(Relation onerel, int elevel,
15311531
AcquireSampleRowsFunc acquirefunc = acquirefuncs[i];
15321532
double childblocks = relblocks[i];
15331533

1534-
pgstat_progress_update_param(PROGRESS_ANALYZE_CURRENT_CHILD_TABLE_RELID,
1535-
RelationGetRelid(childrel));
1534+
/*
1535+
* Report progress. The sampling function will normally report blocks
1536+
* done/total, but we need to reset them to 0 here, so that they don't
1537+
* show an old value until that.
1538+
*/
1539+
{
1540+
const int progress_index[] = {
1541+
PROGRESS_ANALYZE_CURRENT_CHILD_TABLE_RELID,
1542+
PROGRESS_ANALYZE_BLOCKS_DONE,
1543+
PROGRESS_ANALYZE_BLOCKS_TOTAL
1544+
};
1545+
const int64 progress_vals[] = {
1546+
RelationGetRelid(childrel),
1547+
0,
1548+
0,
1549+
};
1550+
1551+
pgstat_progress_update_multi_param(3, progress_index, progress_vals);
1552+
}
15361553

15371554
if (childblocks > 0)
15381555
{

0 commit comments

Comments
 (0)