Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bA0i3-0005Ii-DX for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jun 2016 20:01:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bA0i2-0001QE-FR for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jun 2016 20:01:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bA0gg-0008JH-H2 for pgsql-hackers@postgresql.org; Mon, 06 Jun 2016 19:59:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bA0gZ-0000ud-Rv for pgsql-hackers@postgresql.org; Mon, 06 Jun 2016 19:59:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u56Jxb0j004218; Mon, 6 Jun 2016 15:59:38 -0400 From: Tom Lane To: Tomasz Ostrowski cc: pgsql-hackers@postgresql.org Subject: Re: [BUGS] Routine analyze of single column prevents standard autoanalyze from running at all In-reply-to: <28700.1465238280@sss.pgh.pa.us> References: <28700.1465238280@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 06 Jun 2016 14:38:00 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <4188.1465243145.0@sss.pgh.pa.us> Date: Mon, 06 Jun 2016 15:59:37 -0400 Message-ID: <4217.1465243177@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4188.1465243145.1@sss.pgh.pa.us> I wrote: > Tomasz Ostrowski writes: >> I suppose this is a bug - an analyze, which does not analyze all >> columns, should not reset pg_stat_user_tables(n_mod_since_analyze). What >> do you think? > I'm inclined to think that this is a reasonable complaint. A usage > pattern like that probably hasn't come up before; but now that it has, > it's clear it shouldn't block auto-analyze from happening. Attached is a draft patch for this, which I propose to apply and back-patch. Any objections? regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="analyze-conditionally-reset-counter.patch"; charset="us-ascii" Content-ID: <4188.1465243145.2@sss.pgh.pa.us> Content-Description: analyze-conditionally-reset-counter.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index cf8c816..97059e5 100644 *** a/src/backend/commands/analyze.c --- b/src/backend/commands/analyze.c *************** do_analyze_rel(Relation onerel, int opti *** 611,620 **** /* * Report ANALYZE to the stats collector, too. However, if doing * inherited stats we shouldn't report, because the stats collector only ! * tracks per-table stats. */ if (!inh) ! pgstat_report_analyze(onerel, totalrows, totaldeadrows); =20=20 /* If this isn't part of VACUUM ANALYZE, let index AMs do cleanup */ if (!(options & VACOPT_VACUUM)) --- 611,623 ---- /* * Report ANALYZE to the stats collector, too. However, if doing * inherited stats we shouldn't report, because the stats collector only ! * tracks per-table stats. Reset the changes_since_analyze counter only ! * if we analyzed all columns; otherwise, there is still work for ! * auto-analyze to do. */ if (!inh) ! pgstat_report_analyze(onerel, totalrows, totaldeadrows, ! (va_cols =3D=3D NIL)); =20=20 /* If this isn't part of VACUUM ANALYZE, let index AMs do cleanup */ if (!(options & VACOPT_VACUUM)) diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgsta= t.c index 44237f9..439fc06 100644 *** a/src/backend/postmaster/pgstat.c --- b/src/backend/postmaster/pgstat.c *************** pgstat_report_vacuum(Oid tableoid, bool=20 *** 1340,1350 **** * pgstat_report_analyze() - * * Tell the collector about the table we just analyzed. * -------- */ void pgstat_report_analyze(Relation rel, ! PgStat_Counter livetuples, PgStat_Counter deadtuples) { PgStat_MsgAnalyze msg; =20=20 --- 1340,1354 ---- * pgstat_report_analyze() - * * Tell the collector about the table we just analyzed. + * + * Caller must provide new live- and dead-tuples estimates, as well as a + * flag indicating whether to reset the changes_since_analyze counter. * -------- */ void pgstat_report_analyze(Relation rel, ! PgStat_Counter livetuples, PgStat_Counter deadtuples, ! bool resetcounter) { PgStat_MsgAnalyze msg; =20=20 *************** pgstat_report_analyze(Relation rel, *** 1381,1386 **** --- 1385,1391 ---- msg.m_databaseid =3D rel->rd_rel->relisshared ? InvalidOid : MyDatabaseI= d; msg.m_tableoid =3D RelationGetRelid(rel); msg.m_autovacuum =3D IsAutoVacuumWorkerProcess(); + msg.m_resetcounter =3D resetcounter; msg.m_analyzetime =3D GetCurrentTimestamp(); msg.m_live_tuples =3D livetuples; msg.m_dead_tuples =3D deadtuples; *************** pgstat_recv_analyze(PgStat_MsgAnalyze *m *** 5263,5272 **** tabentry->n_dead_tuples =3D msg->m_dead_tuples; =20=20 /* ! * We reset changes_since_analyze to zero, forgetting any changes that ! * occurred while the ANALYZE was in progress. */ ! tabentry->changes_since_analyze =3D 0; =20=20 if (msg->m_autovacuum) { --- 5268,5278 ---- tabentry->n_dead_tuples =3D msg->m_dead_tuples; =20=20 /* ! * If commanded, reset changes_since_analyze to zero, forgetting any ! * changes that occurred while the ANALYZE was in progress. */ ! if (msg->m_resetcounter) ! tabentry->changes_since_analyze =3D 0; =20=20 if (msg->m_autovacuum) { diff --git a/src/include/pgstat.h b/src/include/pgstat.h index a078b61..19c8387 100644 *** a/src/include/pgstat.h --- b/src/include/pgstat.h *************** typedef struct PgStat_MsgAnalyze *** 383,388 **** --- 383,389 ---- Oid m_databaseid; Oid m_tableoid; bool m_autovacuum; + bool m_resetcounter; TimestampTz m_analyzetime; PgStat_Counter m_live_tuples; PgStat_Counter m_dead_tuples; *************** extern void pgstat_report_autovac(Oid db *** 970,976 **** extern void pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples); extern void pgstat_report_analyze(Relation rel, ! PgStat_Counter livetuples, PgStat_Counter deadtuples); =20=20 extern void pgstat_report_recovery_conflict(int reason); extern void pgstat_report_deadlock(void); --- 971,978 ---- extern void pgstat_report_vacuum(Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples); extern void pgstat_report_analyze(Relation rel, ! PgStat_Counter livetuples, PgStat_Counter deadtuples, ! bool resetcounter); =20=20 extern void pgstat_report_recovery_conflict(int reason); extern void pgstat_report_deadlock(void); ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--