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 1pckuv-0000pl-7c for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Mar 2023 10:33:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pckut-00011d-3R for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Mar 2023 10:33:03 +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 1pckus-00010y-Of for pgsql-hackers@lists.postgresql.org; Thu, 16 Mar 2023 10:33:02 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pckup-0008Uq-Vm for pgsql-hackers@lists.postgresql.org; Thu, 16 Mar 2023 10:33:01 +0000 Received: by mail-wr1-x42d.google.com with SMTP id l1so1017589wry.12 for ; Thu, 16 Mar 2023 03:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678962778; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Iohq/u9DBP+/j2tNFdi0qXfjzXeCO6Mud/e8WMWR7NA=; b=QttMZsYW87Ivf/KHrkJGUwfORcoy6topPLU7pQhZBIn3q5Vbmnoi9RgVkZA+2fH+l2 Sq4azGn7OeX8+3U1HMS4PoEF8LJ0VG0+sRynEsy5LzJeVXUQtleMQBGb1pSIqj6TYo+U O0JM2TMWCV64cdoXwKsmm1tWYH6SGixLPOswOYzbdYsGbEWwvaxW/XTscE9a+Okd9/mR GDNG0FVnVpJj/mtK3YaulLw0e2HFAB8AOWFYal/74Y1LGrxvGmvWIK5pkgG8kNXlJijS Eibm26sNwpmsOKeN3YQIdp2RoeFE2d7PQADnATTz3Aotaf/T0Llwy9CmkiXeE44vnhVU +BJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678962778; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Iohq/u9DBP+/j2tNFdi0qXfjzXeCO6Mud/e8WMWR7NA=; b=fkWo1gQiQvnHLiycO5tTsA7JT5f5XNCQVvd7Rfso/A1jyTA+8r47axEqJ3fssvj2Ln k4H7Wq4CQlVzrs0mrl++lmttsFaJaHnxRC5YoL2YIpN/6sjF0xdku55ymmfR5iVhcajC IX+XHTcbK1DTroel3KreKd8aqgy8q/6mKEehf0E41X2GWsHb3nRA67rbRFHrHEOvG8kM thHrJBT0fHAfcVwTNNUwY1GidAJpdBpvpyCE9Ja3MW4Iuhcwz/VzYT2t6zQIrAE8CMnY +C3JBPoV3/zLBLJzD7Bqi8pT6giuycHY9C8eKC8hCsFySeN+ncFwUjHuUyEI0FDbMWY3 h2hA== X-Gm-Message-State: AO0yUKWbB7SOaY4qmN+BpydVoxO7lMCu7jqbJfegbRj5TrOjJHRTAWAG 9ByOEOl9E6dydwTaxyHtjZM= X-Google-Smtp-Source: AK7set+P5VBykpa/bA46kG+7iMmiUiXQt9eEplZ5OE6GEMYqSzdVrMDffKVICy+Y6CE0T8pBsSV1VQ== X-Received: by 2002:a5d:4d8f:0:b0:2d1:bbe3:29b8 with SMTP id b15-20020a5d4d8f000000b002d1bbe329b8mr1932419wru.28.1678962777879; Thu, 16 Mar 2023 03:32:57 -0700 (PDT) Received: from [192.168.22.74] ([54.239.6.186]) by smtp.gmail.com with ESMTPSA id w17-20020adfd4d1000000b002c70ce264bfsm6859102wrk.76.2023.03.16.03.32.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Mar 2023 03:32:57 -0700 (PDT) Message-ID: <621ed53c-4d9a-8f77-ab8c-20235f2d95a1@gmail.com> Date: Thu, 16 Mar 2023 11:32:56 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: Reconcile stats in find_tabstat_entry() and get rid of PgStat_BackendFunctionEntry Content-Language: en-US To: Michael Paquier Cc: Andres Freund , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org References: <20230214.151102.1070436528757437157.horikyota.ntt@gmail.com> <9262b2a9-6785-1f83-bf7f-7fcf90c2c113@gmail.com> <20230215.095644.822493184688844040.horikyota.ntt@gmail.com> <130095b4-7c6d-b6f1-69d4-94f66231f81d@gmail.com> <20230216212121.uvav7xgdh2ysqjy5@awork3.anarazel.de> From: "Drouvot, Bertrand" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 3/16/23 7:29 AM, Michael Paquier wrote: > On Mon, Mar 06, 2023 at 08:33:15AM +0100, Drouvot, Bertrand wrote: >> Thanks for having looked at it! > > Looking at that, I have a few comments. > > + tabentry = (PgStat_TableStatus *) entry_ref->pending; > + tablestatus = palloc(sizeof(PgStat_TableStatus)); > + *tablestatus = *tabentry; > + > [...] > + for (trans = tabentry->trans; trans != NULL; trans = trans->upper) > + { > + tablestatus->t_counts.t_tuples_inserted += trans->tuples_inserted; > + tablestatus->t_counts.t_tuples_updated += trans->tuples_updated; > + tablestatus->t_counts.t_tuples_deleted += trans->tuples_deleted; > + } > > - if (entry_ref) > - return entry_ref->pending; > - return NULL; > + return tablestatus; > > From what I get with this change, the number of tuples changed by DMLs > have their computations done a bit earlier, Thanks for looking at it! Right, but note this is in a dedicated new tablestatus (created within find_tabstat_entry()). > meaning that it would make > all the callers of find_tabstat_entry() pay the computation cost. Right. Another suggested approach was to add a flag but then we'd not really hide the internal from pgstatfuncs. > Still it is not really going to matter, because we will just do the > computation once when looking at any pending changes of > pg_stat_xact_all_tables for each entry. Yes. > There are 9 callers of > find_tabstat_entry, with 7 being used for pg_stat_xact_all_tables. Right, those are: pg_stat_get_xact_numscans() pg_stat_get_xact_tuples_returned() pg_stat_get_xact_tuples_fetched() pg_stat_get_xact_tuples_inserted() pg_stat_get_xact_tuples_updated() pg_stat_get_xact_tuples_deleted() pg_stat_get_xact_tuples_hot_updated() > How much do we need to care about the remaining two callers > pg_stat_get_xact_blocks_fetched() and pg_stat_get_xact_blocks_hit()? Regarding pg_stat_get_xact_blocks_fetched() and pg_stat_get_xact_blocks_hit() the callers (if any) are outside of the core PG (as from what I can see they are not used at all). I don't think we should pay any particular attention to those 2 ones as anyway nothing prevent the 7 others to be called outside of the pg_stat_xact_all_tables view. > Could it be a problem if these two also pay the extra computation cost > if a transaction with many subtransactions (aka )needs to look at their > data? These two are used nowhere, they have pg_proc entries and they > are undocumented, so it is hard to say the impact of this change on > them.. > Right, and that's the same for the 7 others as nothing prevent them to be called outside of the pg_stat_xact_all_tables view. Do you think it would be better to add the extra flag then? > Second question: once the data from the subtransactions is copied, > would it be cleaner to set trans to NULL after the data copy is done? > That would not hurt but I'm not sure it's worth it (well, it's currently not done in pg_stat_get_xact_tuples_inserted() for example). > It would feel a bit safer to me to document that find_tabstat_entry() > is currently only used for this xact system view.. The extra > computation could lead to surprises, actually, if this routine is used > outside this context? Perhaps that's OK, but it does not give me a > warm feeling, just to reshape three functions of pgstatfuncs.c with > macros. That's a fair point. On the other hand those 9 functions (which can all be used outside of the pg_stat_xact_all_tables view) are not documented, so I'm not sure this is that much of a concern (and if we think it is we still gave the option to add an extra flag to indicate whether or not the extra computation is needed.) Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com