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.94.2) (envelope-from ) id 1rbRfv-00FRTt-Lg for pgsql-general@arkaria.postgresql.org; Sat, 17 Feb 2024 20:52:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rbRfu-008Cey-37 for pgsql-general@arkaria.postgresql.org; Sat, 17 Feb 2024 20:52:42 +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.94.2) (envelope-from ) id 1rbRft-008Ceq-Iu for pgsql-general@lists.postgresql.org; Sat, 17 Feb 2024 20:52:41 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rbRfo-007GIa-Kx for pgsql-general@lists.postgresql.org; Sat, 17 Feb 2024 20:52:40 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id A997EBE6F; Sat, 17 Feb 2024 21:52:33 +0100 (CET) Date: Sat, 17 Feb 2024 21:52:33 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: How to do faster DML Message-ID: <20240217205233.nvzdigbxgfq6dyfh@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <20240211222230.tt3mpjdvgrimeodu@hjp.at> <20240213150234.ydiitfoowojhj2n3@hjp.at> <20240215233130.mutkz2rcjehhtixg@hjp.at> <20240216003401.dzjc5a5vn2au7yln@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="v5qkoicdlusmbbzd" Content-Disposition: inline In-Reply-To: <20240216003401.dzjc5a5vn2au7yln@hjp.at> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --v5qkoicdlusmbbzd Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2024-02-16 01:34:01 +0100, Peter J. Holzer wrote: > On 2024-02-15 16:51:56 -0700, David G. Johnston wrote: > > What you see with an exact type is what you get, which allows for imple= menting > > equality, unlike inexact which requires epsilon checking. >=20 > You can check binary fp values for equality. If they are equal, they > will compare equal. If they aren't, they won't. >=20 > What you can't expect is that the laws of commutativity, associativity, > etc. hold. If you compute a value in two different ways which should be > equivalent mathematically (e.g. a*b/c vs. a/c*b), the result may be > different and an equality test may fail. But that is also the case for > numeric (and of course integer). To illustrate that point: hjp=3D> create table t_n (a numeric, b numeric, c numeric); CREATE TABLE hjp=3D> insert into t_n values(47, 52, 10); INSERT 0 1 -- the numbers are not specially chosen. I just invoked -- select (random()*100)::int; -- three times, and they were the ones that came up. hjp=3D> select *, a / b * c, a * c / b, a / b * c =3D a * c / b from t_n; =E2=95=94=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A4=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=A4=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A4=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A4=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=A4=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=97 =E2=95=91 a =E2=94=82 b =E2=94=82 c =E2=94=82 ?column? =E2= =94=82 ?column? =E2=94=82 ?column? =E2=95=91 =E2=95=9F=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=95=A2 =E2=95=91 47 =E2=94=82 52 =E2=94=82 10 =E2=94=82 9.03846153846153846150 =E2= =94=82 9.0384615384615385 =E2=94=82 f =E2=95=91 =E2=95=9A=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A7=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=A7=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A7=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A7=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=A7=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=9D (1 row) So with type numeric two expressions which should be equal mathematically, aren't in fact equal. Now let's try the same thing with binary floating point: hjp=3D> create table t_f (a float8, b float8, c float8); CREATE TABLE hjp=3D> insert into t_f values(47, 52, 10); INSERT 0 1 hjp=3D> select *, a / b * c, a * c / b, a / b * c =3D a * c / b from t_f; =E2=95=94=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A4=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=A4=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A4=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=A4=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A4=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =97 =E2=95=91 a =E2=94=82 b =E2=94=82 c =E2=94=82 ?column? =E2=94= =82 ?column? =E2=94=82 ?column? =E2=95=91 =E2=95=9F=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=95= =A2 =E2=95=91 47 =E2=94=82 52 =E2=94=82 10 =E2=94=82 9.038461538461538 =E2=94= =82 9.038461538461538 =E2=94=82 t =E2=95=91 =E2=95=9A=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A7=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=A7=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A7=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=A7=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=A7=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =9D (1 row) Now they are indeed equal. This is *not* guaranteed and I got a bit lucky here, but the fact that I got lucky on the first try shows that "float bad, numeric good" is not backed up by reality. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --v5qkoicdlusmbbzd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmXRHIwACgkQ8g5IURL+ KF3oABAAk0OvhdZnjB/fTNZb5BoPl2ytVQshZbScEIuu/0rMfQFmc/eQDuuayIVR UzBOqa1Jl5KBZ6oWUOXnI+2j/bpAFf2sQ1Nc7Dc0vKevnrp/vgarSbFGx2fTNxxl 3LJx2cnUZIDM5bLG37hIpg3c/Bwm9osKAMI9QwcaiE97Mz2c/e4eukQbLS75SRkZ nhxWJdZiUM816vChIO0iVxXjtvLuCQO1fD/Y9BFQXpevgrLD+M3M+UNOJv9/lCq7 QBuf+ekmoY+p/pFGKHpl1r7q8ggOIWSmWdv/zuKzhjlEJyx1/urpofTkZUbuKOq2 YmcmGvB8EMdgfa1MIO2slh6gQWY/VqUZWKvvf1QC/eR47AH5nj8yt8btIsO7uT6I BnLybeaPETwmpeSIOKlIm8JeyHzjlSQVe50hCvGpIpj0eOzJODIko1XwoKCtAjoP 9mvO2zqSHfonzEkblEm1kshnAgeTwhKCu1AGvEytYy/J9sZYJSith8+7N9ZBBfRK FDo/kYIQbRBsxHRTXXeiN+Kvxqa6o3owmyYHIQttrUSH0McoUjozvyOrP73iKKJs r82v+frvPhyD4UwBUuldgBP8Y0ZOZuDPnl6ke5xVgWya2KEmskFqpEJZCyI6AQjT nFTcErC3BufM3bGHRXt9YQbdNKQ7uoDBkbT5OzN9RIm7AjoQo+A= =O1wh -----END PGP SIGNATURE----- --v5qkoicdlusmbbzd--