From: | Daniel Gustafsson <daniel(at)yesql(dot)se> |
---|---|
To: | Michael Paquier <michael(at)paquier(dot)xyz> |
Cc: | Peter Smith <smithpb2250(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Redundant strlen(query) in get_rel_infos |
Date: | 2023-05-11 09:57:37 |
Message-ID: | 80BFC3E2-89C5-415A-BEF4-04B5F1E8A7FD@yesql.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> On 11 May 2023, at 06:24, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Thu, May 11, 2023 at 01:06:42PM +1000, Peter Smith wrote:
>> While reviewing another patch to the file info.c, I noticed there seem
>> to be some unnecessary calls to strlen(query) in get_rel_infos()
>> function.
>>
>> i.e. The query is explicitly initialized to an empty string
>> immediately prior, so why the strlen?
>
> It just looks like this was copied from a surrounding area like
> get_db_infos(). Keeping the code as it is is no big deal, either, but
> yes we could just remove them and save the two calls. So ok by me.
I think it's intentionally done in 73b9952e82 as defensive coding, and given
that this is far from a hot codepath I think leaving them is better.
Instead I think it would be more worthwhile to remove these snprintf() made
queries and use PQExpbuffers. 29aeda6e4e6 introduced that in pg_upgrade and it
is more in line with how we build queries in other tools.
Looking at the snprintf sites made me remember a patchset I worked on last year
(but I don't remember if I ended up submitting); there is no need to build one
of the queries on the stack as it has no variables. The attached 0003 (which
needs a reindent of the query text) comes from that patchset. I think we
should do this regardless.
--
Daniel Gustafsson
Attachment | Content-Type | Size |
---|---|---|
0003-pg_upgrade-Avoid-storing-query-on-the-stack.patch | application/octet-stream | 1.3 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Daniel Gustafsson | 2023-05-11 10:11:30 | Re: de-catalog one error message |
Previous Message | Zhijie Hou (Fujitsu) | 2023-05-11 09:42:39 | RE: walsender performance regression due to logical decoding on standby changes |