Re: How to do faster DML - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: How to do faster DML
Date
Msg-id 20240216003401.dzjc5a5vn2au7yln@hjp.at
Whole thread Raw
In response to Re: How to do faster DML  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: How to do faster DML
Re: How to do faster DML
List pgsql-general
On 2024-02-15 16:51:56 -0700, David G. Johnston wrote:
> On Thu, Feb 15, 2024 at 4:31 PM Peter J. Holzer <hjp-pgsql@hjp.at> wrote:
>     On 2024-02-14 22:55:01 -0700, David G. Johnston wrote:
>     > On Tuesday, February 13, 2024, veem v <veema0000@gmail.com> wrote:
>     >
>     >     float data types rather than numeric. This will give better
>     >     performance.
>     >
>     >
>     > Only use an inexact floating-point data type if you truly
>     > understand what you are getting yourself into.  Quickly getting
>     > the wrong answer isn’t tolerable solution.
>
>     Do NOT assume that a decimal type (even if it can grow to ridiculuous
>     lengths like PostgreSQL's numeric) is exact in the mathematical sense.
>     It isn't. It cannot represent almost all real numbers
>
>
> That is an unusual definition for exact, I wouldn't have considered the
> requirement to represent all real numbers to be included in it.
>
> What you see with an exact type is what you get, which allows for implementing
> equality, unlike inexact which requires epsilon checking.

You can check binary fp values for equality. If they are equal, they
will compare equal. If they aren't, they won't.

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). You might get around that by epsilon
checking, but whether that's the right thing to do depends on your
application.

And most importantly, and gets most people on the "oh noes, binary fp is
inexact" bandwagon is that decimal fractions (1/10, 1/100, ...) are not
exactly representable in binary, just like 1/3, 1/7, 1/11, ... aren't
exactly represntable in decimal. People are used the latter, but not
the former. But mathematically, that doesn't really make a difference.

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

pgsql-general by date:

Previous
From: Jay Stanley
Date:
Subject: Re: PostgreSQL DB in prod, test, debug
Next
From: veem v
Date:
Subject: Re: How to do faster DML