pgsql: Improve COPY TO performance when server and client encodings mat

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve COPY TO performance when server and client encodings mat
Date: 2024-02-09 00:31:26
Message-ID: E1rYEne-005Jmw-16@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve COPY TO performance when server and client encodings match

This commit fixes an oversight introduced in c61a2f58418e, where COPY TO
would attempt to do encoding conversions even if the encodings of the
client and the server matched for multi-byte encodings. All conversions
go through pg_any_to_server() that makes the conversion a no-op when the
encodings of the client and the server match, even for multi-byte
encodings.

The logic was fine, but setting CopyToStateData->need_transcoding would
cause strlen() to be called for nothing for each attribute of all the
rows copied, and that was showing high in some profiles (more attributes
make that easier to reach). This change improves the runtime of some
worst-case COPY TO queries by 15%~ (number present at least here).

This is a performance improvement, so no backpatch is done out of
caution as this is not a regression.

Reported-by: Andres Freund
Analyzed-by: Andres Freund
Author: Michael Paquier
Reviewed-by: Heikki Linnakangas
Discussion: https://postgr.es/m/20240206020504.edijzczkgd25ek6z@awork3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b619852086ed2b5df76631f5678f60d3bebd3745

Modified Files
--------------
src/backend/commands/copyto.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2024-02-09 02:05:20 pgsql: Fix indentation of copyto.c
Previous Message Peter Eisentraut 2024-02-08 20:23:26 pgsql: Apply pg_dump test cleanups to test_pg_dump as well