Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkM0K-0006Tr-61 for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Dec 2020 06:52:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkM0J-0003Ku-5C for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Dec 2020 06:52:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkM0I-0003Km-Ug for pgsql-hackers@lists.postgresql.org; Wed, 02 Dec 2020 06:52:42 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkM0G-0006aD-O6 for pgsql-hackers@lists.postgresql.org; Wed, 02 Dec 2020 06:52:41 +0000 Received: from hnk.local (p1295030-ipngn4902funabasi.chiba.ocn.ne.jp [153.166.85.30]) by oss.nttdata.com (Postfix) with ESMTPSA id 90EC1625CF; Wed, 2 Dec 2020 15:52:37 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: pg_stat_statements oddity with track = all To: Julien Rouhaud , Nikolay Samokhvalov Cc: PostgreSQL Hackers References: <20201202040516.GA43757@nol> <20201202063241.GA51769@nol> From: Fujii Masao Message-ID: Date: Wed, 2 Dec 2020 15:52:37 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <20201202063241.GA51769@nol> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020/12/02 15:32, Julien Rouhaud wrote: > On Tue, Dec 01, 2020 at 10:08:06PM -0800, Nikolay Samokhvalov wrote: >> On Tue, Dec 1, 2020 at 8:05 PM Julien Rouhaud wrote: >> >>> Someone raised an interested point recently on pg_stat_kcache extension for >>> handling nested statements, which also applies to pg_stat_statements. >>> >> ... >> >>> The only idea I have for that is to add a new field to entry key, for >>> instance >>> is_toplevel. >> >> >> This particular problem often bothered me when dealing with >> pg_stat_statements contents operating under "track = all" (especially when >> performing the aggregated analysis, like you showed). >> >> I think the idea of having a flag to distinguish the top-level entries is >> great. >> > > Ok! > >>> The immediate cons is obviously that it could amplify quite a lot >>> the number of entries tracked, so people may need to increase >>> pg_stat_statements.max to avoid slowdown if that makes them reach frequent >>> entry eviction. >>> >> >> If all top-level records in pg_stat_statements have "true" in the new >> column (is_toplevel), how would this lead to the need to increase >> pg_stat_statements.max? The number of records would remain the same, as >> before extending pg_stat_statements. > > If the same query is getting executed both at top level and as a nested > statement, two entries will then be created. That's probably unlikely for > things like RI trigger queries, but I don't know what to expect for client > application queries. Just idea; instead of boolean is_toplevel flag, what about counting the number of times when the statement is executed in toplevel, and also in nested level? Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION