pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Refactor pg_get_line() to expose an alternative StringInfo-based
Date: Sun, 06 Sep 2020 18:13:50 +0000
Message-ID: <E1kEzAk-0002hn-DA@gemulon.postgresql.org> (raw)

Refactor pg_get_line() to expose an alternative StringInfo-based API.

Letting the caller provide a StringInfo to read into is helpful when
the caller needs to merge lines or otherwise modify the data after
it's been read.  Notably, now the code added by commit 8f8154a50
can use pg_get_line_append() instead of having its own copy of that
logic.  A follow-on commit will also make use of this.

Also, since StringInfo buffers are a minimum of 1KB long, blindly
using pg_get_line() in a loop can eat a lot more memory than one would
expect.  I discovered for instance that commit e0f05cd5b caused initdb
to consume circa 10MB to read postgres.bki, even though that's under
1MB worth of data.  A less memory-hungry alternative is to re-use the
same StringInfo for all lines and pg_strdup the results.

Discussion: https://postgr.es/m/1315832.1599345736@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8e3c58e6e459b285d37edb6129e412ed25cd90c1

Modified Files
--------------
src/backend/libpq/hba.c     | 40 +++++++++-----------------
src/bin/initdb/initdb.c     | 12 ++++++--
src/common/pg_get_line.c    | 70 +++++++++++++++++++++++++++++++--------------
src/include/common/string.h |  3 ++
4 files changed, 75 insertions(+), 50 deletions(-)



view thread (11+ messages)  latest in thread

Message-ID: <E1kEzAk-0002hn-DA@gemulon.postgresql.org>
Permalink:  ../E1kEzAk-0002hn-DA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kEzAk-0002hn-DA@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Refactor pg_get_line() to expose an alternative StringInfo-based
  In-Reply-To: <E1kEzAk-0002hn-DA@gemulon.postgresql.org>
  References: <E1kEzAk-0002hn-DA@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox