From: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
---|---|
To: | Jeff Davis <pgsql(at)j-davis(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(at)paquier(dot)xyz>, jian he <jian(dot)universality(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Stephen Frost <sfrost(at)snowman(dot)net>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, alvherre(at)alvh(dot)no-ip(dot)org |
Subject: | Re: Statistics Import and Export |
Date: | 2025-02-24 01:03:45 |
Message-ID: | CADkLM=ckXu5wzSQZ3Y_fvAaL8rZ+upZdSecBLf5FCTMj7M6T-A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sun, Feb 23, 2025 at 7:22 PM Jeff Davis <pgsql(at)j-davis(dot)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);
to:
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.
>
> 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2025-02-24 01:05:26 | Re: Fix logging for invalid recovery timeline |
Previous Message | Michael Paquier | 2025-02-24 00:57:49 | Re: Remove wal_[sync|write][_time] from pg_stat_wal and track_wal_io_timing |