Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit48c192c

Browse files
committed
Revise pgstat's tracking of tuple changes to improve the reliability of
decisions about when to auto-analyze.The previous code depended on n_live_tuples + n_dead_tuples - last_anl_tuples,where all three of these numbers could be bad estimates from ANALYZE itself.Even worse, in the presence of a steady flow of HOT updates and matchingHOT-tuple reclamations, auto-analyze might never trigger at all, even if allthree numbers are exactly right, because n_dead_tuples could hold steady.To fix, replace last_anl_tuples with an accurately tracked count of the totalnumber of committed tuple inserts + updates + deletes since the last ANALYZEon the table. This can still be compared to the same threshold as before, butit's much more trustworthy than the old computation. Tracking this requiresone more intra-transaction counter per modified table within backends, but noadditional memory space in the stats collector. There probably isn't anymeasurable speed difference; if anything it might be a bit faster than before,since I was able to eliminate some per-tuple arithmetic operations in favor ofadding sums once per (sub)transaction.Also, simplify the logic around pgstat vacuum and analyze reporting messagesby not trying to fold VACUUM ANALYZE into a single pgstat message.The original thought behind this patch was to allow scheduling of analyzeson parent tables by artificially inflating their changes_since_analyze count.I've left that for a separate patch since this change seems to stand on itsown merit.
1 parent6761cff commit48c192c

File tree

6 files changed

+152
-135
lines changed

6 files changed

+152
-135
lines changed

‎src/backend/commands/analyze.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.144 2009/12/29 20:11:44 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.145 2009/12/30 20:32:14 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -535,16 +535,13 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
535535
}
536536

537537
/*
538-
* Update pages/tuples stats in pg_class.
538+
* Update pages/tuples stats in pg_class, but not if we're inside a
539+
* VACUUM that got a more precise number.
539540
*/
540541
if (update_reltuples)
541-
{
542542
vac_update_relstats(onerel,
543543
RelationGetNumberOfBlocks(onerel),
544544
totalrows,hasindex,InvalidTransactionId);
545-
/* report results to the stats collector, too */
546-
pgstat_report_analyze(onerel,totalrows,totaldeadrows);
547-
}
548545

549546
/*
550547
* Same for indexes. Vacuum always scans all indexes, so if we're part of
@@ -565,6 +562,13 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
565562
}
566563
}
567564

565+
/*
566+
* Report ANALYZE to the stats collector, too; likewise, tell it to
567+
* adopt these numbers only if we're not inside a VACUUM that got a
568+
* better number.
569+
*/
570+
pgstat_report_analyze(onerel,update_reltuples,totalrows,totaldeadrows);
571+
568572
/* We skip to here if there were no analyzable columns */
569573
cleanup:
570574

‎src/backend/commands/vacuum.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.400 2009/12/29 20:11:44 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.401 2009/12/30 20:32:14 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1332,7 +1332,6 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
13321332
pgstat_report_vacuum(RelationGetRelid(onerel),
13331333
onerel->rd_rel->relisshared,
13341334
true,
1335-
(vacstmt->options&VACOPT_ANALYZE)!=0,
13361335
vacrelstats->rel_tuples);
13371336

13381337
returnheldoff;

‎src/backend/commands/vacuumlazy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
*
3131
* IDENTIFICATION
32-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.125 2009/12/19 01:32:34 sriggs Exp $
32+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.126 2009/12/30 20:32:14 tgl Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -237,7 +237,6 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
237237
pgstat_report_vacuum(RelationGetRelid(onerel),
238238
onerel->rd_rel->relisshared,
239239
vacrelstats->scanned_all,
240-
(vacstmt->options&VACOPT_ANALYZE)!=0,
241240
vacrelstats->rel_tuples);
242241

243242
/* and log the action if appropriate */

‎src/backend/postmaster/autovacuum.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
*
5757
* IDENTIFICATION
58-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.105 2009/11/16 21:32:06 tgl Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.106 2009/12/30 20:32:14 tgl Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -2591,8 +2591,7 @@ relation_needs_vacanalyze(Oid relid,
25912591
{
25922592
reltuples=classForm->reltuples;
25932593
vactuples=tabentry->n_dead_tuples;
2594-
anltuples=tabentry->n_live_tuples+tabentry->n_dead_tuples-
2595-
tabentry->last_anl_tuples;
2594+
anltuples=tabentry->changes_since_analyze;
25962595

25972596
vacthresh= (float4)vac_base_thresh+vac_scale_factor*reltuples;
25982597
anlthresh= (float4)anl_base_thresh+anl_scale_factor*reltuples;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp