Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rVW5o-00HMMJ-Dp for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2024 12:22:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rVW5n-004D9n-BM for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2024 12:22:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rVW5n-004D9f-2C for pgsql-hackers@lists.postgresql.org; Thu, 01 Feb 2024 12:22:55 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rVW5j-004VG8-T2 for pgsql-hackers@postgresql.org; Thu, 01 Feb 2024 12:22:53 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id 0C1F160FA0; Thu, 1 Feb 2024 21:22:48 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at oss.nttdata.com MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 01 Feb 2024 21:22:48 +0900 From: Shinya Kato To: Michael Paquier Cc: pgsql-hackers@postgresql.org Subject: Re: Fix bugs not to discard statistics when changing stats_fetch_consistency In-Reply-To: References: User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: Shinya11.Kato@oss.nttdata.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-02-01 17:33, Michael Paquier wrote: > On Thu, Jan 11, 2024 at 06:18:38PM +0900, Shinya Kato wrote: >> Hi, hackers > > (Sorry for the delay, this thread was on my TODO list for some time.) >> There is below description in docs for stats_fetch_consistency. >> "Changing this parameter in a transaction discards the statistics >> snapshot." >> >> However, I wonder if changes stats_fetch_consistency in a transaction, >> statistics is not discarded in some cases. > > Yep, you're right. This is inconsistent with the documentation where > we need to clean up the cached data when changing this GUC. I was > considering a few options regarding the location of the extra > pgstat_clear_snapshot(), but at the end I see the point in doing it in > a path even if it creates a duplicate with pgstat_build_snapshot() > when pgstat_fetch_consistency is using the snapshot mode. A location > better than your patch is pgstat_snapshot_fixed(), though, so as new > stats kinds will be able to get the call. > > I have been banging my head on my desk for a bit when thinking about a > way to test that in a predictible way, until I remembered that these > stats are only flushed at commit, so this requires at least two > sessions, with one of them having a transaction opened while > manipulating stats_fetch_consistency. TAP would be one option, but > I'm not really tempted about spending more cycles with a > background_psql just for this case. If I'm missing something, feel > free. Thank you for the review and pushing! I think it is better and more concise than my implementation. -- Regards, Shinya Kato NTT DATA GROUP CORPORATION