Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb619852

Browse files
committed
Improve COPY TO performance when server and client encodings match
This commit fixes an oversight introduced inc61a2f5, where COPY TOwould attempt to do encoding conversions even if the encodings of theclient and the server matched for multi-byte encodings. All conversionsgo through pg_any_to_server() that makes the conversion a no-op when theencodings of the client and the server match, even for multi-byteencodings.The logic was fine, but setting CopyToStateData->need_transcoding wouldcause strlen() to be called for nothing for each attribute of all therows copied, and that was showing high in some profiles (more attributesmake that easier to reach). This change improves the runtime of someworst-case COPY TO queries by 15%~ (number present at least here).This is a performance improvement, so no backpatch is done out ofcaution as this is not a regression.Reported-by: Andres FreundAnalyzed-by: Andres FreundAuthor: Michael PaquierReviewed-by: Heikki LinnakangasDiscussion:https://postgr.es/m/20240206020504.edijzczkgd25ek6z@awork3.anarazel.de
1 parenta89fa00 commitb619852

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

‎src/backend/commands/copyto.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,15 @@ BeginCopyTo(ParseState *pstate,
612612
cstate->file_encoding=cstate->opts.file_encoding;
613613

614614
/*
615-
* Set up encoding conversion info. Even if the file and server encodings
616-
* are the same, we must apply pg_any_to_server() to validate data in
617-
* multibyte encodings.
615+
* Set up encoding conversion info if the file and server encodings
616+
* differ (see also pg_server_to_any).
618617
*/
619-
cstate->need_transcoding=
620-
(cstate->file_encoding!=GetDatabaseEncoding()||
621-
pg_database_encoding_max_length()>1);
618+
if (cstate->file_encoding==GetDatabaseEncoding()||
619+
cstate->file_encoding==PG_SQL_ASCII)
620+
cstate->need_transcoding= false;
621+
else
622+
cstate->need_transcoding= true;
623+
622624
/* See Multibyte encoding comment above */
623625
cstate->encoding_embeds_ascii=PG_ENCODING_IS_CLIENT_ONLY(cstate->file_encoding);
624626

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp