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 1oXeoJ-0007tZ-0T for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Sep 2022 08:28:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oXeoG-00068c-Tt for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Sep 2022 08:28:52 +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 1oXeoG-00068T-3K for pgsql-hackers@lists.postgresql.org; Mon, 12 Sep 2022 08:28:52 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oXeo7-0006sB-WD for pgsql-hackers@postgresql.org; Mon, 12 Sep 2022 08:28:50 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id C05755C012A; Mon, 12 Sep 2022 04:28:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 12 Sep 2022 04:28:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1662971320; x= 1663057720; bh=g2ecvmryJuh7X5sA8CtQpHqZZnTMABk9qvdw7U+b2/c=; b=F Zu0MQrZcKo/8k3P279JJlmj/iGpyV0F7BHfEoh2exCbiZheUe8ZeZdVvvMI6yzAb mZjur5zlyigWSiCffUSs14zJYzLkuE1CKFN17pQlYbzLaoSklQ9Dzv2ya5RUJ0rh /JHtdSns5fITx6kOlBRkbGJEfLnUIFHA64rX+tuHrzibA9/mZNq9vBFZvRQgqoCc pznmOkkssVFXZGqLWg6miB6+BUbwu4wiT+WAzXio39ifldSIRuqYCRV9F6+Eg9cW 0cgQ2aATt8GLarXWPY/FbAkAa5Tu7qOXuX6mVsuHyqHjSx4s42NiTRaH3pdUJelA D1Mx2mDr0gpmfDHSagauw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeduvddgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfevfhfhjggtgfesth ejredttdefjeenucfhrhhomheprfgvthgvrhcugfhishgvnhhtrhgruhhtuceophgvthgv rhdrvghishgvnhhtrhgruhhtsegvnhhtvghrphhrihhsvggusgdrtghomheqnecuggftrf grthhtvghrnhepheelffeggedujeetiefhleetuddvieffhfffvdejvdffgeejkeduledu heduieefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epphgvthgvrhdrvghishgvnhhtrhgruhhtsegvnhhtvghrphhrihhsvggusgdrtghomh X-ME-Proxy: Feedback-ID: i131946ab:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Sep 2022 04:28:39 -0400 (EDT) Message-ID: Date: Mon, 12 Sep 2022 10:28:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: pg_walinspect float4/float8 confusion Content-Language: en-US To: Bharath Rupireddy Cc: pgsql-hackers References: <36ee692b-232f-0484-ce94-dc39d82021ad@enterprisedb.com> From: Peter Eisentraut 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 On 09.09.22 05:51, Bharath Rupireddy wrote: > On Thu, Sep 8, 2022 at 5:23 PM Peter Eisentraut > wrote: >> >> The pg_walinspect function pg_get_wal_stats() has output arguments >> declared as float4 (count_percentage, record_size_percentage, etc.), but >> the internal computations are all done in type double. Is there a >> reason why this is then converted to float4 for output? It probably >> doesn't matter in practice, but it seems unnecessarily confusing. Or at >> least add a comment so it doesn't look like an accident. Also compare >> with pgstattuple, which uses float8 in its SQL interface for similar data. > > Thanks for finding this. There's no specific reason as such. However, > it's good to be in sync with what code does internally and what it > exposes to the users. pg_walinspect uses double data type (double > precision floating point number) for internal calculations and cuts it > down to single precision floating point number float4 to the users. > Attaching a patch herewith. I'm not sure if this needs to be > backported, if at all, we were to, IMO it should be backported to > reduce the code diff. done > While on, I found that pgstattuple uses uint64 for internal percentile > calculations as opposed to double data type for others. Attaching a > small patch to fix it. Good find. I also changed the computation to use 100.0 instead of 100, so that you actually get non-integer values out of it. I didn't backpatch this, since it would probably result in a small behavior change and the results with the previous code are not wrong, just unnecessarily truncated.