refactor the CopyOneRowTo - Mailing list pgsql-hackers

From jian he
Subject refactor the CopyOneRowTo
Date
Msg-id CACJufxFzHCeFBQF0M+Sgk_NwknWuQ4oU7tS1isVeBrbhcKOHkg@mail.gmail.com
Whole thread Raw
Responses Re: refactor the CopyOneRowTo
Re: refactor the CopyOneRowTo
List pgsql-hackers
original CopyOneRowTo:
https://git.postgresql.org/cgit/postgresql.git/tree/src/backend/commands/copyto.c#n922
I change it to:
-----------------------
if (!cstate->opts.binary)
{
foreach_int(attnum, cstate->attnumlist)
{
Datum value = slot->tts_values[attnum - 1];
bool isnull = slot->tts_isnull[attnum - 1];

if (need_delim)
CopySendChar(cstate, cstate->opts.delim[0]);
need_delim = true;

if (isnull)
CopySendString(cstate, cstate->opts.null_print_client);
else
{
string = OutputFunctionCall(&out_functions[attnum - 1],
value);
if (cstate->opts.csv_mode)
CopyAttributeOutCSV(cstate, string,
cstate->opts.force_quote_flags[attnum - 1]);
else
CopyAttributeOutText(cstate, string);
}
}
}
else
{
foreach_int(attnum, cstate->attnumlist)
{
Datum value = slot->tts_values[attnum - 1];
bool isnull = slot->tts_isnull[attnum - 1];
bytea    *outputbytes;

if (isnull)
CopySendInt32(cstate, -1);
else
{
outputbytes = SendFunctionCall(&out_functions[attnum - 1],
value);
CopySendInt32(cstate, VARSIZE(outputbytes) - VARHDRSZ);
CopySendData(cstate, VARDATA(outputbytes),
VARSIZE(outputbytes) - VARHDRSZ);
}
}
}


overall less "if else" logic,
also copy format don't change during copy, we don't need to check
binary or nor for each datum value.

Attachment

pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: Special-case executor expression steps for common combinations
Next
From: Heikki Linnakangas
Date:
Subject: Re: thread-safety: gmtime_r(), localtime_r()