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

Commit3943da4

Browse files
committed
Refactor CopyOneRowTo
The handling of binary and text formats are quite different here, soit's more clear to check for the format first and have two separateloops.Author: jian he <jian.universality@gmail.com>Reviewed-by: Ilia Evdokimov, Junwang ZhaoDiscussion:https://www.postgresql.org/message-id/CACJufxFzHCeFBQF0M%2BSgk_NwknWuQ4oU7tS1isVeBrbhcKOHkg@mail.gmail.com
1 parent1153422 commit3943da4

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

‎src/backend/commands/copyto.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,8 @@ DoCopyTo(CopyToState cstate)
902902
staticvoid
903903
CopyOneRowTo(CopyToStatecstate,TupleTableSlot*slot)
904904
{
905-
boolneed_delim= false;
906905
FmgrInfo*out_functions=cstate->out_functions;
907906
MemoryContextoldcontext;
908-
ListCell*cur;
909-
char*string;
910907

911908
MemoryContextReset(cstate->rowcontext);
912909
oldcontext=MemoryContextSwitchTo(cstate->rowcontext);
@@ -920,29 +917,23 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
920917
/* Make sure the tuple is fully deconstructed */
921918
slot_getallattrs(slot);
922919

923-
foreach(cur,cstate->attnumlist)
920+
if (!cstate->opts.binary)
924921
{
925-
intattnum=lfirst_int(cur);
926-
Datumvalue=slot->tts_values[attnum-1];
927-
boolisnull=slot->tts_isnull[attnum-1];
922+
boolneed_delim= false;
928923

929-
if (!cstate->opts.binary)
924+
foreach_int(attnum,cstate->attnumlist)
930925
{
926+
Datumvalue=slot->tts_values[attnum-1];
927+
boolisnull=slot->tts_isnull[attnum-1];
928+
char*string;
929+
931930
if (need_delim)
932931
CopySendChar(cstate,cstate->opts.delim[0]);
933932
need_delim= true;
934-
}
935933

936-
if (isnull)
937-
{
938-
if (!cstate->opts.binary)
934+
if (isnull)
939935
CopySendString(cstate,cstate->opts.null_print_client);
940936
else
941-
CopySendInt32(cstate,-1);
942-
}
943-
else
944-
{
945-
if (!cstate->opts.binary)
946937
{
947938
string=OutputFunctionCall(&out_functions[attnum-1],
948939
value);
@@ -952,10 +943,20 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
952943
else
953944
CopyAttributeOutText(cstate,string);
954945
}
946+
}
947+
}
948+
else
949+
{
950+
foreach_int(attnum,cstate->attnumlist)
951+
{
952+
Datumvalue=slot->tts_values[attnum-1];
953+
boolisnull=slot->tts_isnull[attnum-1];
954+
bytea*outputbytes;
955+
956+
if (isnull)
957+
CopySendInt32(cstate,-1);
955958
else
956959
{
957-
bytea*outputbytes;
958-
959960
outputbytes=SendFunctionCall(&out_functions[attnum-1],
960961
value);
961962
CopySendInt32(cstate,VARSIZE(outputbytes)-VARHDRSZ);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp