Re: Redundant strlen(query) in get_rel_infos

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
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-15 07:45:39
Message-ID: ZGHjI/XdYl+6XtI2@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, May 11, 2023 at 11:57:37AM +0200, Daniel Gustafsson wrote:
> 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.

Good idea to reduce the overall presence of QUERY_ALLOC in the
surroundings.

> 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.

Not sure that this is an improvement in itself as
get_tablespace_paths() includes QUERY_ALLOC because
executeQueryOrDie() does so, so this could become a problem if
someones decides to copy-paste this code with a query becomes longer
than QUERY_ALLOC once built? Perhaps that's not worth worrying, but I
like your suggestion of applying more PQExpbuffers, particularly if
applied in a consistent way across the board. It could matter if the
code of get_tablespace_paths() is changed to use a query with
parameters.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Laurenz Albe 2023-05-15 08:00:29 Re: psql: Could we get "-- " prefixing on the **** QUERY **** outputs? (ECHO_HIDDEN)
Previous Message Peter Smith 2023-05-15 07:39:57 Re: [PoC] pg_upgrade: allow to upgrade publisher node