Re: Clean up command argument assembly

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Clean up command argument assembly
Date: 2023-07-04 12:14:41
Message-ID: 709c4e53-62cc-1405-3a35-6f9badf4cb9d@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 26/06/2023 12:33, Peter Eisentraut wrote:
> This is a small code cleanup patch.
>
> Several commands internally assemble command lines to call other
> commands. This includes initdb, pg_dumpall, and pg_regress. (Also
> pg_ctl, but that is different enough that I didn't consider it here.)
> This has all evolved a bit organically, with fixed-size buffers, and
> various optional command-line arguments being injected with
> confusing-looking code, and the spacing between options handled in
> inconsistent ways. This patch cleans all this up a bit to look clearer
> and be more easily extensible with new arguments and options.

+1

> We start each command with printfPQExpBuffer(), and then append
> arguments as necessary with appendPQExpBuffer(). Also standardize on
> using initPQExpBuffer() over createPQExpBuffer() where possible.
> pg_regress uses StringInfo instead of PQExpBuffer, but many of the
> same ideas apply.

It's a bit bogus to use PQExpBuffer for these. If you run out of memory,
you silently get an empty string instead. StringInfo, which exits the
process on OOM, would be more appropriate. We have tons of such
inappropriate uses of PQExpBuffer in all our client programs, though, so
I don't insist on fixing this particular case right now.

--
Heikki Linnakangas
Neon (https://neon.tech)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2023-07-04 12:34:28 Re: [PATCH]Feature improvement for MERGE tab completion
Previous Message David Rowley 2023-07-04 12:02:06 Re: Improve the performance of nested loop join in the case of partitioned inner table