pgsql: Add more efficient functions to pqformat API.

Started by Andres Freundalmost 9 years ago4 messagescomitters
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t206433
psql -h localhost -U postgres

Built from patchset v2 (message #2), July 29, 2026 at 01:04 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t206433_2 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t206433_2 && git checkout t206433_2

Patchset v2 (message #2) is on t206433_2

Jump to latest
#1Andres Freund
andres@anarazel.de

Add more efficient functions to pqformat API.

There's three prongs to achieve greater efficiency here:

1) Allow reusing a stringbuffer across pq_beginmessage/endmessage,
with the new pq_beginmessage_reuse/endmessage_reuse. This can be
beneficial both because it avoids allocating the initial buffer,
and because it's more likely to already have an correctly sized
buffer.

2) Replacing pq_sendint() with pq_sendint$width() inline
functions. Previously unnecessary and unpredictable branches in
pq_sendint() were needed. Additionally the replacement functions
are implemented more efficiently. pq_sendint is now deprecated, a
separate commit will convert all in-tree callers.

3) Add pq_writeint$width(), pq_writestring(). These rely on sufficient
space in the StringInfo's buffer, avoiding individual space checks
& potential individual resizing. To allow this to be used for
strings, expose mbutil.c's MAX_CONVERSION_GROWTH.

Followup commits will make use of these facilities.

Author: Andres Freund
Discussion: /messages/by-id/20170914063418.sckdzgjfrsbekae4@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1de09ad8eb1fa673ee7899d6dfbb2b49ba204818

Modified Files
--------------
src/backend/libpq/pqformat.c | 88 ++++++++-------------
src/backend/utils/mb/mbutils.c | 11 ---
src/include/libpq/pqformat.h | 168 ++++++++++++++++++++++++++++++++++++++++-
src/include/mb/pg_wchar.h | 11 +++
4 files changed, 208 insertions(+), 70 deletions(-)

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Andres Freund (#1)
Re: [COMMITTERS] pgsql: Add more efficient functions to pqformat API.

On 10/11/17 19:11, Andres Freund wrote:

3) Add pq_writeint$width(), pq_writestring(). These rely on sufficient
space in the StringInfo's buffer, avoiding individual space checks
& potential individual resizing. To allow this to be used for
strings, expose mbutil.c's MAX_CONVERSION_GROWTH.

This has been causing warnings from cpluspluscheck. I suggest the
attached patch to address that.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

t206433_2
0001-Fix-warnings-from-cpluspluscheck.patchtext/plain; charset=UTF-8; name=0001-Fix-warnings-from-cpluspluscheck.patch; x-mac-creator=0; x-mac-type=0Download+4-5
#3Peter Eisentraut
peter_e@gmx.net
In reply to: Peter Eisentraut (#2)
Re: [COMMITTERS] pgsql: Add more efficient functions to pqformat API.

On 11/30/17 14:49, Peter Eisentraut wrote:

On 10/11/17 19:11, Andres Freund wrote:

3) Add pq_writeint$width(), pq_writestring(). These rely on sufficient
space in the StringInfo's buffer, avoiding individual space checks
& potential individual resizing. To allow this to be used for
strings, expose mbutil.c's MAX_CONVERSION_GROWTH.

This has been causing warnings from cpluspluscheck. I suggest the
attached patch to address that.

committed

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#4Andres Freund
andres@anarazel.de
In reply to: Peter Eisentraut (#3)
Re: [COMMITTERS] pgsql: Add more efficient functions to pqformat API.

On 2017-12-04 19:58:01 -0500, Peter Eisentraut wrote:

On 11/30/17 14:49, Peter Eisentraut wrote:

On 10/11/17 19:11, Andres Freund wrote:

3) Add pq_writeint$width(), pq_writestring(). These rely on sufficient
space in the StringInfo's buffer, avoiding individual space checks
& potential individual resizing. To allow this to be used for
strings, expose mbutil.c's MAX_CONVERSION_GROWTH.

This has been causing warnings from cpluspluscheck. I suggest the
attached patch to address that.

committed

Thanks!

Greetings,

Andres Freund