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 1kkLhB-0005qe-SH for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Dec 2020 06:32:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kkLhA-000809-HI for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Dec 2020 06:32:56 +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 1kkLhA-000802-5u for pgsql-hackers@lists.postgresql.org; Wed, 02 Dec 2020 06:32:56 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kkLh3-0006Qu-Lo for pgsql-hackers@lists.postgresql.org; Wed, 02 Dec 2020 06:32:54 +0000 Received: by mail-pf1-x434.google.com with SMTP id b10so608248pfo.4 for ; Tue, 01 Dec 2020 22:32:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=gmA86B2DOFKwg73wLI3usyJh01YNThC/PkzE2o6n0do=; b=sScgbJ9qvbTWCFf0bjCtC7UjI6zMoMxmHwZXMuiCei83i9QZv+X/l5wB+ZSfyBWGrA MntzgjdIW6TittHlS70TLmTMFnpNOZtB3jZbqP58KTGEG/yZX/ZNmFzXgKdzdmUN5po5 K9Xdqwl+CVjumnbu3UcLQWFGI6K3h9At9/a6yIBPP8EsMM9VOKzXOx4WfCEwEuGPAmD4 lHUVNQb0FoS0J0pvHcSjEVUu5zY+1axO2sAgNRECrYkd2ENUvDvqFv3KiwYJUKsgl7qZ G/n5udLpuQXNN9AfLZWLVbPqIhFuQ+lEQpqszhqKBL8XQPb501b+uIgJO9V2OvD8S00h LmuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=gmA86B2DOFKwg73wLI3usyJh01YNThC/PkzE2o6n0do=; b=Lfg9gBffDPi8ZQrnnS6X9R5ZsDZhM6EBf+4KdzbAM4U/iGy0KP9U97VuWh05qKKOO9 eqfwyWKqU2q8Uf8gDv1/+8DMBAlFUCbS440/I6kILPKU8gAltWNzRwijplKcXJpbHfSs CYuV26P/F/dUT5AXoQeIVt65oqBRCiUNvBfvMO8adMAqNnXw8HWs1JL7v8eo7pBTxzKB v74/6/J+GVFhbRqyyzyMW+2m875rS2TYOp41h/QqjyxnzUW8l5l4SddUwm856R5IxjJ2 ce7dhCNz+T4XnVumiyalzQkRQ0wh3Qhk16iJbKfSvG4isz/8p9raIoEPDfdOpfDXHAxM 0lMg== X-Gm-Message-State: AOAM5320qyyv3jDpV/00iBnYoDp1NJtwumDH+pWBiywFvgtG/REi1t6t NN7zgcwfmuDU4UgFIBmsh38= X-Google-Smtp-Source: ABdhPJxlkPISajhD/xLDWJvS91PzSOszWVmDnWDvMl8a/Yo+P4SZQwT+kv8Zp/p9SoTOe5A4NDck4g== X-Received: by 2002:a65:6401:: with SMTP id a1mr1318227pgv.149.1606890768287; Tue, 01 Dec 2020 22:32:48 -0800 (PST) Received: from nol (36-228-92-107.dynamic-ip.hinet.net. [36.228.92.107]) by smtp.gmail.com with ESMTPSA id h11sm1003263pfn.27.2020.12.01.22.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 22:32:47 -0800 (PST) Date: Wed, 2 Dec 2020 14:32:41 +0800 From: Julien Rouhaud To: Nikolay Samokhvalov Cc: PostgreSQL Hackers Subject: Re: pg_stat_statements oddity with track = all Message-ID: <20201202063241.GA51769@nol> References: <20201202040516.GA43757@nol> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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.