Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1we614-004Ycu-13 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2026 07:02:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1we611-001Vpv-2s for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Jun 2026 07:02:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1we611-001Vpm-1x for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2026 07:02:47 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1we60z-00000000iiS-2SNS for pgsql-hackers@lists.postgresql.org; Mon, 29 Jun 2026 07:02:46 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-4720d22c94aso1033623f8f.1 for ; Mon, 29 Jun 2026 00:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782716562; x=1783321362; darn=lists.postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=qQWt6J/FGTIcUsAtZQhUXa+L6Z/hqRG0B8hQDIULWFY=; b=CEaY7n8CMzP8zQMUaUiF6aKx0XHCZA09CptJdcCUJBPNowo30dkzKAIgUVhExiH/K9 LL6vrExl1NplhHwVPDFFwYQIJWF949TndkHX842LIXyxaCaZEG4e7/djZGp8GibCaWUC jvdMAf8BfBns0daBjScq3F9askaP7HpPBEHyN0MYNyOUKx/pOHnm330IqqbLhgr0CSWg F14qVV3Js9sGCKfFTlNzIApWM61kubnutdW+nDjtAVo2vt2XRs2v+1c+jVrT4bj7mg5j RYEhVLda0LPQhKyba9NGe2fzdnnKG1KezV0om/7pM7fnoYpn5D1w0OPo0FbytDoFjMwd PdvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782716562; x=1783321362; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qQWt6J/FGTIcUsAtZQhUXa+L6Z/hqRG0B8hQDIULWFY=; b=OwBXIdWfpYKiCPvDVNbkNwYRt2Ah6HjvP9JX77spIUk2Cx/kjbulnco/gl8emrJ6Hk R/zbc6ppnD8k0g1LUD1xdEwB3lxy/G4aAu5Awe0MCwIxcY26DF8MX5U2ryCG5i3BvmDj 9QAPiauE5X87iG+0MuB5KzWVnGZZ1NXOA9w8s2aWL/QNyTSQnuOuyHkoZ3JlEKPXRzSt jN96wZaHpbwJoSWiyoOPTzxPzJhr5v8OA0BteEYPSVRfft3mv35n/iUF6ha8nTYpepJO p3ot/xC9cK1L/w5BjeWYZKxOsyd/RkjTkfWZm2lsOtu3dlIb1SKJkXi1ymsoPqO3A0e5 8eOQ== X-Gm-Message-State: AOJu0Ywy+UtzFXBS3oguaqNYpYQpJJTIqNxnGbgQETdF/EkjTS/86u7c e6sZAAYOpciGz7mTSxHNYUKDM1oJgbLrzujX8B+k+dD50xM2jWVUd7tDLGbKUA== X-Gm-Gg: AfdE7cmnx/Piu4Sp3nEnVqT+xdt88L31QbecThCw1i6glHRxUTuZBF3QRL2xaqd1o1S ftL989gmu5XjmrWqON4DmEBPW126UhKV7cMV62A6yACtbo4VFWFHm77OEgJxtI3dMQCruDo1mFt yabvncIu9Hs81+4bbaI8JsEJuHOBlt1uKe9HiUR472sM4d6ASM49hZvGA1h63oaEEofxmJX571P c6JeY4WLA4nKueOmgy329BIugfYDUt0+369rj18Puux7KEvUDhzM6CmlOUjOxI0joqY8z+AeP/S oDX7Fhv7GhV2iYffExbkGUoytiM4LpcKR6+I/VZFCSCPNj/kgP/Rwg0Q8drF9Nli0eUgZZE4QwG CLEF58AG+hdKTS6Myaroi4ccrnzasqdXqq3lcuib10jtyZ0nEnv0L09A6sPDyopBPEacFm3WkUg gtWc8/dyW21YoGQeW1WJJZEU6+f/zJQzNOwViuXVo/c/5vwlrm8Cc4FjczyUSakAdpK4cn1l95 X-Received: by 2002:a05:6000:4289:b0:45e:f302:95b with SMTP id ffacd0b85a97d-46dc18a5a3amr26364261f8f.37.1782716562100; Mon, 29 Jun 2026 00:02:42 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-472797ef029sm14247604f8f.16.2026.06.29.00.02.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2026 00:02:41 -0700 (PDT) Date: Mon, 29 Jun 2026 07:02:40 +0000 From: Bertrand Drouvot To: pgsql-hackers@lists.postgresql.org Subject: Fix floating-point noise in pg_stat_us_to_ms() Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="TXuqZKQhWXLuSKvO" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --TXuqZKQhWXLuSKvO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi hackers, while reviewing [1], I noticed that the IO timings displayed in pg_stat_io can produce floating-point noise like: postgres=# select read_time from pg_stat_io where read_time > 0; read_time --------------------- 2.2640000000000002 0.08700000000000001 That's because 0.001 cannot be represented exactly in binary floating point. I think this output looks weird, even if understandable. Note that with extra_float_digits set to 0 you don't see the noise (but 1 is the default). The attached patch changes pg_stat_us_to_ms() so that it uses a division by 1000.0 instead as it's correctly rounded, see for example: postgres=# SELECT (9 * 0.001::float8)::text; text ---------------------- 0.009000000000000001 (1 row) postgres=# SELECT (9::float8 / 1000.0)::text; text ------- 0.009 (1 row) Given that / 1000.0 is the most common way to do this kind of computation in the code tree, I think that it makes sense to update pg_stat_us_to_ms() to do so. Thoughts? [1]: https://www.postgresql.org/message-id/akH0SxXlXPNjD%2BR5%40bdtpg Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --TXuqZKQhWXLuSKvO Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Fix-floating-point-noise-in-pg_stat_us_to_ms.patch" From 6e3ee0d38af6cf649355daf8a9afe27355e93fef Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot Date: Mon, 29 Jun 2026 06:31:58 +0000 Subject: [PATCH v1] Fix floating-point noise in pg_stat_us_to_ms() Multiplying by 0.001 can produce trailing-digit noise in displayed values (for example 0.009000000000000001 instead of 0.009, should extra_float_digits not being set to 0) because 0.001 cannot be represented exactly in binary floating point. Use division by 1000.0 instead as it is the most common way to deal with such computation in the code tree. Author: Bertrand Drouvot --- src/backend/utils/adt/pgstatfuncs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 100.0% src/backend/utils/adt/ diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 6f9c9c72de5..1e5f8293b28 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -1457,7 +1457,7 @@ pgstat_get_io_time_index(IOOp io_op) static inline double pg_stat_us_to_ms(PgStat_Counter val_ms) { - return val_ms * (double) 0.001; + return (double) val_ms / 1000.0; } /* -- 2.34.1 --TXuqZKQhWXLuSKvO--