mirror of
https://github.com/postgres/postgres.git
synced 2025-07-12 21:01:52 +03:00
Refactor CopyOneRowTo
The handling of binary and text formats are quite different here, so it's more clear to check for the format first and have two separate loops. Author: jian he <jian.universality@gmail.com> Reviewed-by: Ilia Evdokimov, Junwang Zhao Discussion: https://www.postgresql.org/message-id/CACJufxFzHCeFBQF0M%2BSgk_NwknWuQ4oU7tS1isVeBrbhcKOHkg@mail.gmail.com
This commit is contained in:
@ -902,11 +902,8 @@ DoCopyTo(CopyToState cstate)
|
|||||||
static void
|
static void
|
||||||
CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
|
CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
|
||||||
{
|
{
|
||||||
bool need_delim = false;
|
|
||||||
FmgrInfo *out_functions = cstate->out_functions;
|
FmgrInfo *out_functions = cstate->out_functions;
|
||||||
MemoryContext oldcontext;
|
MemoryContext oldcontext;
|
||||||
ListCell *cur;
|
|
||||||
char *string;
|
|
||||||
|
|
||||||
MemoryContextReset(cstate->rowcontext);
|
MemoryContextReset(cstate->rowcontext);
|
||||||
oldcontext = MemoryContextSwitchTo(cstate->rowcontext);
|
oldcontext = MemoryContextSwitchTo(cstate->rowcontext);
|
||||||
@ -920,29 +917,23 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
|
|||||||
/* Make sure the tuple is fully deconstructed */
|
/* Make sure the tuple is fully deconstructed */
|
||||||
slot_getallattrs(slot);
|
slot_getallattrs(slot);
|
||||||
|
|
||||||
foreach(cur, cstate->attnumlist)
|
|
||||||
{
|
|
||||||
int attnum = lfirst_int(cur);
|
|
||||||
Datum value = slot->tts_values[attnum - 1];
|
|
||||||
bool isnull = slot->tts_isnull[attnum - 1];
|
|
||||||
|
|
||||||
if (!cstate->opts.binary)
|
if (!cstate->opts.binary)
|
||||||
{
|
{
|
||||||
|
bool need_delim = false;
|
||||||
|
|
||||||
|
foreach_int(attnum, cstate->attnumlist)
|
||||||
|
{
|
||||||
|
Datum value = slot->tts_values[attnum - 1];
|
||||||
|
bool isnull = slot->tts_isnull[attnum - 1];
|
||||||
|
char *string;
|
||||||
|
|
||||||
if (need_delim)
|
if (need_delim)
|
||||||
CopySendChar(cstate, cstate->opts.delim[0]);
|
CopySendChar(cstate, cstate->opts.delim[0]);
|
||||||
need_delim = true;
|
need_delim = true;
|
||||||
}
|
|
||||||
|
|
||||||
if (isnull)
|
if (isnull)
|
||||||
{
|
|
||||||
if (!cstate->opts.binary)
|
|
||||||
CopySendString(cstate, cstate->opts.null_print_client);
|
CopySendString(cstate, cstate->opts.null_print_client);
|
||||||
else
|
else
|
||||||
CopySendInt32(cstate, -1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!cstate->opts.binary)
|
|
||||||
{
|
{
|
||||||
string = OutputFunctionCall(&out_functions[attnum - 1],
|
string = OutputFunctionCall(&out_functions[attnum - 1],
|
||||||
value);
|
value);
|
||||||
@ -952,10 +943,20 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
|
|||||||
else
|
else
|
||||||
CopyAttributeOutText(cstate, string);
|
CopyAttributeOutText(cstate, string);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
foreach_int(attnum, cstate->attnumlist)
|
||||||
|
{
|
||||||
|
Datum value = slot->tts_values[attnum - 1];
|
||||||
|
bool isnull = slot->tts_isnull[attnum - 1];
|
||||||
bytea *outputbytes;
|
bytea *outputbytes;
|
||||||
|
|
||||||
|
if (isnull)
|
||||||
|
CopySendInt32(cstate, -1);
|
||||||
|
else
|
||||||
|
{
|
||||||
outputbytes = SendFunctionCall(&out_functions[attnum - 1],
|
outputbytes = SendFunctionCall(&out_functions[attnum - 1],
|
||||||
value);
|
value);
|
||||||
CopySendInt32(cstate, VARSIZE(outputbytes) - VARHDRSZ);
|
CopySendInt32(cstate, VARSIZE(outputbytes) - VARHDRSZ);
|
||||||
|
Reference in New Issue
Block a user