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

Commitf64340e

Browse files
committed
Don't reset changes_since_analyze after a selective-columns ANALYZE.
If we ANALYZE only selected columns of a table, we should not postponeauto-analyze because of that; other columns may well still need statsupdates. As committed, the counter is left alone if a column list isgiven, whether or not it includes all analyzable columns of the table.Per complaint from Tomasz Ostrowski.It's been like this a long time, so back-patch to all supported branches.Report: <ef99c1bd-ff60-5f32-2733-c7b504eb960c@ato.waw.pl>
1 parentc6dbf1f commitf64340e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

‎src/backend/commands/analyze.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,13 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
611611
/*
612612
* Report ANALYZE to the stats collector, too. However, if doing
613613
* inherited stats we shouldn't report, because the stats collector only
614-
* tracks per-table stats.
614+
* tracks per-table stats. Reset the changes_since_analyze counter only
615+
* if we analyzed all columns; otherwise, there is still work for
616+
* auto-analyze to do.
615617
*/
616618
if (!inh)
617-
pgstat_report_analyze(onerel,totalrows,totaldeadrows);
619+
pgstat_report_analyze(onerel,totalrows,totaldeadrows,
620+
(va_cols==NIL));
618621

619622
/* If this isn't part of VACUUM ANALYZE, let index AMs do cleanup */
620623
if (!(options&VACOPT_VACUUM))

‎src/backend/postmaster/pgstat.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,11 +1340,15 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
13401340
* pgstat_report_analyze() -
13411341
*
13421342
*Tell the collector about the table we just analyzed.
1343+
*
1344+
* Caller must provide new live- and dead-tuples estimates, as well as a
1345+
* flag indicating whether to reset the changes_since_analyze counter.
13431346
* --------
13441347
*/
13451348
void
13461349
pgstat_report_analyze(Relationrel,
1347-
PgStat_Counterlivetuples,PgStat_Counterdeadtuples)
1350+
PgStat_Counterlivetuples,PgStat_Counterdeadtuples,
1351+
boolresetcounter)
13481352
{
13491353
PgStat_MsgAnalyzemsg;
13501354

@@ -1381,6 +1385,7 @@ pgstat_report_analyze(Relation rel,
13811385
msg.m_databaseid=rel->rd_rel->relisshared ?InvalidOid :MyDatabaseId;
13821386
msg.m_tableoid=RelationGetRelid(rel);
13831387
msg.m_autovacuum=IsAutoVacuumWorkerProcess();
1388+
msg.m_resetcounter=resetcounter;
13841389
msg.m_analyzetime=GetCurrentTimestamp();
13851390
msg.m_live_tuples=livetuples;
13861391
msg.m_dead_tuples=deadtuples;
@@ -5263,10 +5268,12 @@ pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len)
52635268
tabentry->n_dead_tuples=msg->m_dead_tuples;
52645269

52655270
/*
5266-
* We reset changes_since_analyze to zero, forgetting any changes that
5267-
* occurred while the ANALYZE was in progress.
5271+
* If commanded, reset changes_since_analyze to zero. This forgets any
5272+
* changes that were committed while the ANALYZE was in progress, but we
5273+
* have no good way to estimate how many of those there were.
52685274
*/
5269-
tabentry->changes_since_analyze=0;
5275+
if (msg->m_resetcounter)
5276+
tabentry->changes_since_analyze=0;
52705277

52715278
if (msg->m_autovacuum)
52725279
{

‎src/include/pgstat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ typedef struct PgStat_MsgAnalyze
383383
Oidm_databaseid;
384384
Oidm_tableoid;
385385
boolm_autovacuum;
386+
boolm_resetcounter;
386387
TimestampTzm_analyzetime;
387388
PgStat_Counterm_live_tuples;
388389
PgStat_Counterm_dead_tuples;
@@ -970,7 +971,8 @@ extern void pgstat_report_autovac(Oid dboid);
970971
externvoidpgstat_report_vacuum(Oidtableoid,boolshared,
971972
PgStat_Counterlivetuples,PgStat_Counterdeadtuples);
972973
externvoidpgstat_report_analyze(Relationrel,
973-
PgStat_Counterlivetuples,PgStat_Counterdeadtuples);
974+
PgStat_Counterlivetuples,PgStat_Counterdeadtuples,
975+
boolresetcounter);
974976

975977
externvoidpgstat_report_recovery_conflict(intreason);
976978
externvoidpgstat_report_deadlock(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp