Re: Statistics Import and Export - Mailing list pgsql-hackers

From Jeff Davis
Subject Re: Statistics Import and Export
Date
Msg-id bbdf2c731b5eda5deed427b2821e09109919595c.camel@j-davis.com
Whole thread Raw
In response to Re: Statistics Import and Export  (Corey Huinker <corey.huinker@gmail.com>)
Responses Re: Statistics Import and Export
List pgsql-hackers
On Mon, 2025-02-24 at 12:57 -0500, Corey Huinker wrote:
> As I see it, the point is that we're getting an input that is a
> string representation from the query, and the end-goal is to convey
> that value with fidelity to the destination database, so there's
> nothing we can do to get us closer to the string that we already
> have.

As Andres mentioned, for the float-to-string conversion, we're using
what the backend does, so it doesn't seem like a problem.

But you have a point in that float4in() does slightly more work than
strtof() to handle platform differences about NaN/Inf. I'm not sure how
much to weigh that concern, but I agree that there is non-zero
cognitive overhead here.

Should we solve that problem by moving some of that code to src/common
src/port somewhere?

> I don't have benchmark numbers beyond the instinct that
> doing something takes more time than doing nothing. Granted,
> "nothing" here means 96 bytes of memory and 3 strncpy()s, and
> "something" is 24 bytes of memory, 2 atoi()s, 1 strtof() plus
> whatever memory and processing we do back in converting back to
> strings.

To me, this argument is, at best, premature optimization. Even if there
were a few cycles saved here somewhere, you'd need to compare that
against the wasted memory. Using 2 int32s and a float4 is only 12 bytes
(not 24) versus 96 for the strings.

Anyone looking at the structure would be wondering (a) why we're using
32 bytes to store something where the natural representation is 4
bytes; and (b) whether that memory adds up to anything worth worrying
about. I'm sure we could analyze that and write an explanatory comment,
but that has non-zero cognitive overhead, as well.

Regards,
    Jeff Davis




pgsql-hackers by date:

Previous
From: Guillaume Lelarge
Date:
Subject: Re: PATCH: warn about, and deprecate, clear text passwords
Next
From: Yogesh Sharma
Date:
Subject: Securing PostgreSQL for rootless containers