summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2024-08-16 10:48:10 +0000
committerHeikki Linnakangas2024-08-16 10:48:10 +0000
commit3943da46bc54006ec4849bc7541cf4e674b700eb (patch)
tree51687bbe4a56ef92dc7b5f95feb77240b9eac1fa
parent1153422edac5d27eeffd61fca2be348fa0714ce9 (diff)
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 <[email protected]> Reviewed-by: Ilia Evdokimov, Junwang Zhao Discussion: https://www.postgresql.org/message-id/CACJufxFzHCeFBQF0M%[email protected]
-rw-r--r--src/backend/commands/copyto.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c
index eb1d3d8fbb..91de442f43 100644
--- a/src/backend/commands/copyto.c
+++ b/src/backend/commands/copyto.c
@@ -902,11 +902,8 @@ DoCopyTo(CopyToState cstate)
static void
CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
{
- bool need_delim = false;
FmgrInfo *out_functions = cstate->out_functions;
MemoryContext oldcontext;
- ListCell *cur;
- char *string;
MemoryContextReset(cstate->rowcontext);
oldcontext = MemoryContextSwitchTo(cstate->rowcontext);
@@ -920,29 +917,23 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
/* Make sure the tuple is fully deconstructed */
slot_getallattrs(slot);
- foreach(cur, cstate->attnumlist)
+ if (!cstate->opts.binary)
{
- int attnum = lfirst_int(cur);
- Datum value = slot->tts_values[attnum - 1];
- bool isnull = slot->tts_isnull[attnum - 1];
+ bool need_delim = false;
- if (!cstate->opts.binary)
+ foreach_int(attnum, cstate->attnumlist)
{
+ Datum value = slot->tts_values[attnum - 1];
+ bool isnull = slot->tts_isnull[attnum - 1];
+ char *string;
+
if (need_delim)
CopySendChar(cstate, cstate->opts.delim[0]);
need_delim = true;
- }
- if (isnull)
- {
- if (!cstate->opts.binary)
+ if (isnull)
CopySendString(cstate, cstate->opts.null_print_client);
else
- CopySendInt32(cstate, -1);
- }
- else
- {
- if (!cstate->opts.binary)
{
string = OutputFunctionCall(&out_functions[attnum - 1],
value);
@@ -952,10 +943,20 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
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
{
- bytea *outputbytes;
-
outputbytes = SendFunctionCall(&out_functions[attnum - 1],
value);
CopySendInt32(cstate, VARSIZE(outputbytes) - VARHDRSZ);