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

Commit5f3e0e8

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 parent4a21c6f commit5f3e0e8

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
@@ -616,10 +616,13 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt,
616616
/*
617617
* Report ANALYZE to the stats collector, too. However, if doing
618618
* inherited stats we shouldn't report, because the stats collector only
619-
* tracks per-table stats.
619+
* tracks per-table stats. Reset the changes_since_analyze counter only
620+
* if we analyzed all columns; otherwise, there is still work for
621+
* auto-analyze to do.
620622
*/
621623
if (!inh)
622-
pgstat_report_analyze(onerel,totalrows,totaldeadrows);
624+
pgstat_report_analyze(onerel,totalrows,totaldeadrows,
625+
(vacstmt->va_cols==NIL));
623626

624627
/* If this isn't part of VACUUM ANALYZE, let index AMs do cleanup */
625628
if (!(vacstmt->options&VACOPT_VACUUM))

‎src/backend/postmaster/pgstat.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,11 +1329,15 @@ pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter tuples)
13291329
* pgstat_report_analyze() -
13301330
*
13311331
*Tell the collector about the table we just analyzed.
1332+
*
1333+
* Caller must provide new live- and dead-tuples estimates, as well as a
1334+
* flag indicating whether to reset the changes_since_analyze counter.
13321335
* --------
13331336
*/
13341337
void
13351338
pgstat_report_analyze(Relationrel,
1336-
PgStat_Counterlivetuples,PgStat_Counterdeadtuples)
1339+
PgStat_Counterlivetuples,PgStat_Counterdeadtuples,
1340+
boolresetcounter)
13371341
{
13381342
PgStat_MsgAnalyzemsg;
13391343

@@ -1370,6 +1374,7 @@ pgstat_report_analyze(Relation rel,
13701374
msg.m_databaseid=rel->rd_rel->relisshared ?InvalidOid :MyDatabaseId;
13711375
msg.m_tableoid=RelationGetRelid(rel);
13721376
msg.m_autovacuum=IsAutoVacuumWorkerProcess();
1377+
msg.m_resetcounter=resetcounter;
13731378
msg.m_analyzetime=GetCurrentTimestamp();
13741379
msg.m_live_tuples=livetuples;
13751380
msg.m_dead_tuples=deadtuples;
@@ -4842,10 +4847,12 @@ pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len)
48424847
tabentry->n_dead_tuples=msg->m_dead_tuples;
48434848

48444849
/*
4845-
* We reset changes_since_analyze to zero, forgetting any changes that
4846-
* occurred while the ANALYZE was in progress.
4850+
* If commanded, reset changes_since_analyze to zero. This forgets any
4851+
* changes that were committed while the ANALYZE was in progress, but we
4852+
* have no good way to estimate how many of those there were.
48474853
*/
4848-
tabentry->changes_since_analyze=0;
4854+
if (msg->m_resetcounter)
4855+
tabentry->changes_since_analyze=0;
48494856

48504857
if (msg->m_autovacuum)
48514858
{

‎src/include/pgstat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ typedef struct PgStat_MsgAnalyze
359359
Oidm_databaseid;
360360
Oidm_tableoid;
361361
boolm_autovacuum;
362+
boolm_resetcounter;
362363
TimestampTzm_analyzetime;
363364
PgStat_Counterm_live_tuples;
364365
PgStat_Counterm_dead_tuples;
@@ -788,7 +789,8 @@ extern void pgstat_report_autovac(Oid dboid);
788789
externvoidpgstat_report_vacuum(Oidtableoid,boolshared,
789790
PgStat_Countertuples);
790791
externvoidpgstat_report_analyze(Relationrel,
791-
PgStat_Counterlivetuples,PgStat_Counterdeadtuples);
792+
PgStat_Counterlivetuples,PgStat_Counterdeadtuples,
793+
boolresetcounter);
792794

793795
externvoidpgstat_report_recovery_conflict(intreason);
794796
externvoidpgstat_report_deadlock(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp