Re: Statistics Import and Export - Mailing list pgsql-hackers
From | Corey Huinker |
---|---|
Subject | Re: Statistics Import and Export |
Date | |
Msg-id | CADkLM=ckXu5wzSQZ3Y_fvAaL8rZ+upZdSecBLf5FCTMj7M6T-A@mail.gmail.com Whole thread Raw |
In response to | Re: Statistics Import and Export (Jeff Davis <pgsql@j-davis.com>) |
Responses |
Re: Statistics Import and Export
Re: Statistics Import and Export |
List | pgsql-hackers |
On Sun, Feb 23, 2025 at 7:22 PM Jeff Davis <pgsql@j-davis.com> wrote:
On Sat, 2025-02-22 at 00:00 -0500, Corey Huinker wrote:
>
> Attached is the first optimization, which gets rid of the pg_class
> queries entirely, instead getting the same information from the
> existing queries in getTables and getIndexes.
Attached a revised version. The main changes are that the only struct
it changes is RelStatsInfo, and it doesn't carry around string values.
IIUC, your version carried around the string values so that there would
be no conversion; it would hold the string from one result to the next.
That makes sense, but it seemed to change a lot of struct fields, and
have unnecessary string copying and memory usage which was not freed.
Instead, I used float_to_shortest_decimal_buf(), which is what
float4out() uses, which should be a consistent way to convert the float
value.
If we're fine with giving up on appendNamedArgument() for relstats, wouldn't we also want to mash these into a single call?
appendPQExpBuffer(out, "\t'relation', '%s'::regclass,\n", qualname);
appendPQExpBuffer(out, "\t'version', '%u'::integer,\n",
fout->remoteVersion);
appendPQExpBuffer(out, "\t'relpages', '%d'::integer,\n", rsinfo->relpages);
appendPQExpBuffer(out, "\t'reltuples', '%s'::real,\n", reltuples_str);
appendPQExpBuffer(out, "\t'relallvisible', '%d'::integer\n);\n",
rsinfo->relallvisible);
appendPQExpBuffer(out, "\t'version', '%u'::integer,\n",
fout->remoteVersion);
appendPQExpBuffer(out, "\t'relpages', '%d'::integer,\n", rsinfo->relpages);
appendPQExpBuffer(out, "\t'reltuples', '%s'::real,\n", reltuples_str);
appendPQExpBuffer(out, "\t'relallvisible', '%d'::integer\n);\n",
rsinfo->relallvisible);
to:
appendPQExpBuffer(out, "\t'relation', '%s'::regclass"
",\n\t'version', '%u'::integer"
appendPQExpBuffer(out, "\t'relation', '%s'::regclass"
",\n\t'version', '%u'::integer"
",\n\t'relpages', '%d'::integer"
",\n\t'reltuples', '%s'::real"
",\n\t'relallvisible', '%d'::integer",
qualname, fout->remoteVersion, rsinfo->relpages,
rsinfo->reltuples_str, rsinfo->relallvisible);
appendPQExpBufferStr(out, "\n);\n");
Also, there's work elsewhere that may add relallfrozen to pg_class, which would be something we'd want to add depending on the remoteVersion, and this format will make that change pretty clear.
rsinfo->reltuples_str, rsinfo->relallvisible);
appendPQExpBufferStr(out, "\n);\n");
Also, there's work elsewhere that may add relallfrozen to pg_class, which would be something we'd want to add depending on the remoteVersion, and this format will make that change pretty clear.
That meant that we couldn't use appendNamedArgument() as easily, but it
wasn't helping much in that function anyway, because it was no longer a
loop.
It still served to encapsulate the format of a kwarg pair, but little more, agreed.
I didn't measure any performance difference between your version and
mine, but avoiding a few allocations couldn't hurt. It seems to save
just under 20% on an unoptimized build.
Part of me thinks we'd want to do the reverse - change the struct to store char[32] to for each of relpages, reltuples, and relallvisible, and then convert reltpages to int in the one place where we actually need to use in its numeric form, and even then only in one place. Conversions to and from other data types introduce the possibility, though very remote, of the converted-and-then-unconverted value being cosmetically different from what we got from the server, and if down the road we're dealing with more complex data types, those conversions might become significant.
pgsql-hackers by date: