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

Commit5acc58c

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 parenta7aa61f commit5acc58c

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
@@ -605,10 +605,13 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
605605
/*
606606
* Report ANALYZE to the stats collector, too. However, if doing
607607
* inherited stats we shouldn't report, because the stats collector only
608-
* tracks per-table stats.
608+
* tracks per-table stats. Reset the changes_since_analyze counter only
609+
* if we analyzed all columns; otherwise, there is still work for
610+
* auto-analyze to do.
609611
*/
610612
if (!inh)
611-
pgstat_report_analyze(onerel,totalrows,totaldeadrows);
613+
pgstat_report_analyze(onerel,totalrows,totaldeadrows,
614+
(va_cols==NIL));
612615

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

‎src/backend/postmaster/pgstat.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,11 +1346,15 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
13461346
* pgstat_report_analyze() -
13471347
*
13481348
*Tell the collector about the table we just analyzed.
1349+
*
1350+
* Caller must provide new live- and dead-tuples estimates, as well as a
1351+
* flag indicating whether to reset the changes_since_analyze counter.
13491352
* --------
13501353
*/
13511354
void
13521355
pgstat_report_analyze(Relationrel,
1353-
PgStat_Counterlivetuples,PgStat_Counterdeadtuples)
1356+
PgStat_Counterlivetuples,PgStat_Counterdeadtuples,
1357+
boolresetcounter)
13541358
{
13551359
PgStat_MsgAnalyzemsg;
13561360

@@ -1387,6 +1391,7 @@ pgstat_report_analyze(Relation rel,
13871391
msg.m_databaseid=rel->rd_rel->relisshared ?InvalidOid :MyDatabaseId;
13881392
msg.m_tableoid=RelationGetRelid(rel);
13891393
msg.m_autovacuum=IsAutoVacuumWorkerProcess();
1394+
msg.m_resetcounter=resetcounter;
13901395
msg.m_analyzetime=GetCurrentTimestamp();
13911396
msg.m_live_tuples=livetuples;
13921397
msg.m_dead_tuples=deadtuples;
@@ -5110,10 +5115,12 @@ pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len)
51105115
tabentry->n_dead_tuples=msg->m_dead_tuples;
51115116

51125117
/*
5113-
* We reset changes_since_analyze to zero, forgetting any changes that
5114-
* occurred while the ANALYZE was in progress.
5118+
* If commanded, reset changes_since_analyze to zero. This forgets any
5119+
* changes that were committed while the ANALYZE was in progress, but we
5120+
* have no good way to estimate how many of those there were.
51155121
*/
5116-
tabentry->changes_since_analyze=0;
5122+
if (msg->m_resetcounter)
5123+
tabentry->changes_since_analyze=0;
51175124

51185125
if (msg->m_autovacuum)
51195126
{

‎src/include/pgstat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ typedef struct PgStat_MsgAnalyze
382382
Oidm_databaseid;
383383
Oidm_tableoid;
384384
boolm_autovacuum;
385+
boolm_resetcounter;
385386
TimestampTzm_analyzetime;
386387
PgStat_Counterm_live_tuples;
387388
PgStat_Counterm_dead_tuples;
@@ -932,7 +933,8 @@ extern void pgstat_report_autovac(Oid dboid);
932933
externvoidpgstat_report_vacuum(Oidtableoid,boolshared,
933934
PgStat_Counterlivetuples,PgStat_Counterdeadtuples);
934935
externvoidpgstat_report_analyze(Relationrel,
935-
PgStat_Counterlivetuples,PgStat_Counterdeadtuples);
936+
PgStat_Counterlivetuples,PgStat_Counterdeadtuples,
937+
boolresetcounter);
936938

937939
externvoidpgstat_report_recovery_conflict(intreason);
938940
externvoidpgstat_report_deadlock(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp