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

Commit1aa8324

Browse files
committed
Revert "Refactor CopyAttributeOut{CSV,Text}() to use a callback in COPY TO"
This reverts commit2889fd2, following a discussion with AndresFreund as this callback, being called once per attribute when sending arelation's row, can involve a lot of indirect function calls (moreattributes to deal with means more impact). The effects of a dispatchat this level would become more visible when improving the per-row codeexecution of COPY TO, impacting future potential performanceimprovements.Discussion:https://postgr.es/m/20240206014125.qofww7ew3dx3v3uk@awork3.anarazel.de
1 parente4b27b5 commit1aa8324

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

‎src/backend/commands/copyto.c

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ typedef enum CopyDest
5454
COPY_CALLBACK,/* to callback function */
5555
}CopyDest;
5656

57-
/*
58-
* Per-format callback to send output representation of one attribute for
59-
* a `string`. `use_quote` tracks if quotes are required in the output
60-
* representation.
61-
*/
62-
typedefvoid (*CopyAttributeOut) (CopyToStatecstate,constchar*string,
63-
booluse_quote);
64-
6557
/*
6658
* This struct contains all the state variables used throughout a COPY TO
6759
* operation.
@@ -105,7 +97,6 @@ typedef struct CopyToStateData
10597
MemoryContextcopycontext;/* per-copy execution context */
10698

10799
FmgrInfo*out_functions;/* lookup info for output functions */
108-
CopyAttributeOutcopy_attribute_out;/* output representation callback */
109100
MemoryContextrowcontext;/* per-row evaluation context */
110101
uint64bytes_processed;/* number of bytes processed so far */
111102
}CopyToStateData;
@@ -126,12 +117,9 @@ static const char BinarySignature[11] = "PGCOPY\n\377\r\n\0";
126117
staticvoidEndCopy(CopyToStatecstate);
127118
staticvoidClosePipeToProgram(CopyToStatecstate);
128119
staticvoidCopyOneRowTo(CopyToStatecstate,TupleTableSlot*slot);
129-
130-
/* Callbacks for copy_attribute_out */
131-
staticvoidCopyAttributeOutText(CopyToStatecstate,constchar*string,
132-
booluse_quote);
120+
staticvoidCopyAttributeOutText(CopyToStatecstate,constchar*string);
133121
staticvoidCopyAttributeOutCSV(CopyToStatecstate,constchar*string,
134-
booluse_quote);
122+
booluse_quote,boolsingle_attr);
135123

136124
/* Low-level communications functions */
137125
staticvoidSendCopyBegin(CopyToStatecstate);
@@ -445,15 +433,6 @@ BeginCopyTo(ParseState *pstate,
445433
/* Extract options from the statement node tree */
446434
ProcessCopyOptions(pstate,&cstate->opts, false/* is_from */ ,options);
447435

448-
/* Set output representation callback */
449-
if (!cstate->opts.binary)
450-
{
451-
if (cstate->opts.csv_mode)
452-
cstate->copy_attribute_out=CopyAttributeOutCSV;
453-
else
454-
cstate->copy_attribute_out=CopyAttributeOutText;
455-
}
456-
457436
/* Process the source/target relation or query */
458437
if (rel)
459438
{
@@ -857,8 +836,11 @@ DoCopyTo(CopyToState cstate)
857836

858837
colname=NameStr(TupleDescAttr(tupDesc,attnum-1)->attname);
859838

860-
/* Ignore quotes */
861-
cstate->copy_attribute_out(cstate,colname, false);
839+
if (cstate->opts.csv_mode)
840+
CopyAttributeOutCSV(cstate,colname, false,
841+
list_length(cstate->attnumlist)==1);
842+
else
843+
CopyAttributeOutText(cstate,colname);
862844
}
863845

864846
CopySendEndOfRow(cstate);
@@ -968,9 +950,12 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
968950
{
969951
string=OutputFunctionCall(&out_functions[attnum-1],
970952
value);
971-
972-
cstate->copy_attribute_out(cstate,string,
973-
cstate->opts.force_quote_flags[attnum-1]);
953+
if (cstate->opts.csv_mode)
954+
CopyAttributeOutCSV(cstate,string,
955+
cstate->opts.force_quote_flags[attnum-1],
956+
list_length(cstate->attnumlist)==1);
957+
else
958+
CopyAttributeOutText(cstate,string);
974959
}
975960
else
976961
{
@@ -1000,8 +985,7 @@ CopyOneRowTo(CopyToState cstate, TupleTableSlot *slot)
1000985
} while (0)
1001986

1002987
staticvoid
1003-
CopyAttributeOutText(CopyToStatecstate,constchar*string,
1004-
booluse_quote)
988+
CopyAttributeOutText(CopyToStatecstate,constchar*string)
1005989
{
1006990
constchar*ptr;
1007991
constchar*start;
@@ -1155,15 +1139,14 @@ CopyAttributeOutText(CopyToState cstate, const char *string,
11551139
*/
11561140
staticvoid
11571141
CopyAttributeOutCSV(CopyToStatecstate,constchar*string,
1158-
booluse_quote)
1142+
booluse_quote,boolsingle_attr)
11591143
{
11601144
constchar*ptr;
11611145
constchar*start;
11621146
charc;
11631147
chardelimc=cstate->opts.delim[0];
11641148
charquotec=cstate->opts.quote[0];
11651149
charescapec=cstate->opts.escape[0];
1166-
boolsingle_attr= (list_length(cstate->attnumlist)==1);
11671150

11681151
/* force quoting if it matches null_print (before conversion!) */
11691152
if (!use_quote&&strcmp(string,cstate->opts.null_print)==0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp