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 1lUSK5-0006D3-Qs for pgsql-committers@arkaria.postgresql.org; Thu, 08 Apr 2021 10:55:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lUSK4-0008Mu-6o for pgsql-committers@arkaria.postgresql.org; Thu, 08 Apr 2021 10:55:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lUSK4-0008Mn-07 for pgsql-committers@lists.postgresql.org; Thu, 08 Apr 2021 10:55:40 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lUSK2-0004OY-H7 for pgsql-committers@lists.postgresql.org; Thu, 08 Apr 2021 10:55:39 +0000 Received: by mail-pj1-x1031.google.com with SMTP id lr1-20020a17090b4b81b02900ea0a3f38c1so4612722pjb.0 for ; Thu, 08 Apr 2021 03:55:38 -0700 (PDT) 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=0IsqZtLi3FqN29d1Z3LvMgHcINHxFUxuWCdlIQlIV1Q=; b=J0gW5wEIjo/4GrFXJ//gDtSrvSuE0Yq12cf1rmR4AZ8K6C55gofJKeHkTwySLGEfu/ yQT0oYF3qWdEuc8jYW2mM4ZaQ9nJYTgJEUWZ+CtrVVhjRZhubeGHSOJEZSOohGwoGRBK /Pq1ypGo3a7W/2MzwODe3BiVBmf9eGvlfo2vP6EsqRlw/lIfqrmU2QQJoVd/mEuve69p B/vxgIx3akweJGXN2IMmtXLMn6q/VnBhhWaD6MazGcIpgtgNj3QoL9GFrH7TAONVu5r7 OTIPEMgNl97OlTyZKOrZxMGt6b1r5I/LLXSXXkhwHk454jmL7iyQd4tReJCbHrYmakok fXOw== 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=0IsqZtLi3FqN29d1Z3LvMgHcINHxFUxuWCdlIQlIV1Q=; b=cR/yrtP4Xed5VAwMpiRKrQNH7HDDx3KSWo43k1+hOkUknX6SioZ93YQAnYsIJT+VYy vTjtF8zJzExpVGcwhSCDDZk1HOY+QXRJCpfN26PhmEacD94OCyvmzvUlmuajV4Nv2MaG +pbqcFZAIDvz/3JU/kJqziOtY0Lhk2oq7qRozfsTm1Qa/AZ7PH3s+vxPSyx+RI2WiWGi fdtTGMOR8DEn1xTDndO4oj++CpDFSK09oU/T33WGqQL5iKVGoiI1Q8ysVqPjxhMe633f qnQhDe9AFr+2aLN8/OhmDQGxfoev0vZxYZkKSvDFuE8RcuLxxvuppGRxaWZAbgnXJKwS lFeQ== X-Gm-Message-State: AOAM531OtqMwtFy9hjPlwPNnbOZ81riwpdcE1LGRfOZaErZoj2j6UIX+ Ywjx6jwtN1GXeQxZNmHCkss= X-Google-Smtp-Source: ABdhPJwi0lbdMSmeld1EqkjLe70rxcrHBkuVCyMPNI3/dPhTFZxDJTPTTDwt8Jp1YbUp/Pr90BAtzA== X-Received: by 2002:a17:90b:4c02:: with SMTP id na2mr7708097pjb.77.1617879336811; Thu, 08 Apr 2021 03:55:36 -0700 (PDT) Received: from nol (2001-b011-0008-9647-4c71-2a6f-a895-f450.dynamic-ip6.hinet.net. [2001:b011:8:9647:4c71:2a6f:a895:f450]) by smtp.gmail.com with ESMTPSA id p5sm8135731pfg.85.2021.04.08.03.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 03:55:36 -0700 (PDT) Date: Thu, 8 Apr 2021 18:56:09 +0800 From: Julien Rouhaud To: Amit Kapila Cc: Andres Freund , Bruce Momjian , pgsql-committers Subject: Re: pgsql: Move pg_stat_statements query jumbling to core. Message-ID: <20210408105609.ducxkeqidufygwqr@nol> References: <20210408051735.lfbdzun5zdlax5gd@alap3.anarazel.de> <20210408061102.xripofnfvqt7qcrg@nol> <20210408064919.bxqnzpi2ctt3rfzg@nol> <20210408094221.s7nyhqe7h22htr7n@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: Archived-At: Precedence: bulk On Thu, Apr 08, 2021 at 03:52:02PM +0530, Amit Kapila wrote: > On Thu, Apr 8, 2021 at 3:11 PM Julien Rouhaud wrote: > > > > On Thu, Apr 08, 2021 at 02:52:26PM +0530, Amit Kapila wrote: > > > > > > Yeah, we do pass instrumentation flags from leader to worker but not > > > the one allocated via pg_stat_staments (pgss_ExecutorStart {... > > > queryDesc->totaltime ...}. > > > > Ah indeed, I now remember that problem that I had to deal with in some > > extensions [1]. For the record this was initially raised by Tomas in [2], but > > unfortunately that thread got forgotten and probably all third-party extensions > > ended up allocating some shmem for their need. > > > > > However, I guess prior to this patch those > > > were anyway not allocated separately because queryid was not passed to > > > workers. So, I think you are right it shouldn't change the previous > > > behavior. > > > > I think that previously parallel workers always added the required > > instrumentation if pg_stat_statements is loaded, > > > > How? AFAICS, in pgss_ExecutorStart(), we allocate the instrumentation > structure only if queryid is non-zero which prior to this patch > shouldn't happen. Doh right, I think I need some sleep :) So I tried to run that scenario against pg13 and master + the ignore parallel worker patch: CREATE TABLE pgss AS SELECT generate_series(1, 10000) id; ALTER TABLE pgss SET (max_parallel_workers = 10); SET force_parallel_mode = on; SET parallel_leader_participation = off; SET parallel_setup_cost = 0; SET parallel_tuple_cost = 0; SELECT version(); SELECT pg_prewarm('pgss'); EXPLAIN (ANALYZE, VERBOSE, BUFFERS, COSTS OFF) SELECT COUNT(*) FROM pgss; SELECT pg_stat_statements_reset(); SELECT COUNT(*) FROM pgss; SELECT query, shared_blks_hit FROM pg_stat_statements WHERE query LIKE '%pgss%'; On pg13, I get: pg_prewarm ------------ 45 (1 row) version --------------------------------------------------------------------------------------------------------- PostgreSQL 13.2@49076fd3ba on x86_64-pc-linux-gnu, compiled by gcc (Gentoo 10.2.0-r5 p6) 10.2.0, 64-bit (1 row) QUERY PLAN ----------------------------------------------------------------------------------- Gather (actual time=8.124..9.004 rows=1 loops=1) Output: (count(*)) Workers Planned: 1 Workers Launched: 1 Single Copy: true Buffers: shared hit=45 -> Aggregate (actual time=3.649..3.650 rows=1 loops=1) Output: count(*) Buffers: shared hit=45 Worker 0: actual time=3.649..3.650 rows=1 loops=1 Buffers: shared hit=45 -> Seq Scan on public.pgss (actual time=0.057..2.331 rows=10000 loops=1) Output: id Buffers: shared hit=45 Worker 0: actual time=0.057..2.331 rows=10000 loops=1 Buffers: shared hit=45 Planning: Buffers: shared hit=15 read=5 Planning Time: 0.211 ms Execution Time: 9.051 ms (20 rows) pg_stat_statements_reset -------------------------- (1 row) count ------- 10000 (1 row) query | shared_blks_hit ---------------------------+----------------- SELECT COUNT(*) FROM pgss | 45 (1 row) On head + patch: pg_prewarm ------------ 45 (1 row) ------------------------------------------------------------------------------------------------------> PostgreSQL 14devel-O0@45885bee58 on x86_64-pc-linux-gnu, compiled by gcc (Gentoo 10.2.0-r5 p6) 10.2.0,> (1 row) QUERY PLAN ------------------------------------------------------------------------------------ Gather (actual time=39.278..42.912 rows=1 loops=1) Output: (count(*)) Workers Planned: 1 Workers Launched: 1 Single Copy: true Buffers: shared hit=45 -> Aggregate (actual time=20.251..20.254 rows=1 loops=1) Output: count(*) Buffers: shared hit=45 Worker 0: actual time=20.251..20.254 rows=1 loops=1 Buffers: shared hit=45 -> Seq Scan on public.pgss (actual time=0.214..13.746 rows=10000 loops=1) Output: id Buffers: shared hit=45 Worker 0: actual time=0.214..13.746 rows=10000 loops=1 Buffers: shared hit=45 Query Identifier: 5605505304133078562 Planning: Buffers: shared hit=21 Planning Time: 0.857 ms Execution Time: 43.237 ms (21 rows) pg_stat_statements_reset -------------------------- (1 row) count ------- 10000 (1 row) query | shared_blks_hit ---------------------------+----------------- SELECT COUNT(*) FROM pgss | 45 (1 row) And I get the exact same results if I change the scenario to SET force_parallel_mode = off. So it seems that it was working as expected as I can see the 45 buffers being access, and is still working as expected, although I'm not exactly sure why right now if queryDesc->totaltime isn't somehow gathered by the parallel worker instrastructure. (Note that 45885bee58 is my local commit for "Ignore parallel workers in pg_stat_statements"). Also note that the buffers shown in the planning part are due to the catcache population, so they're not expected on the 2nd query planning.