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

Commit06bd311

Browse files
committed
Revert "Refactor CopyReadAttributes{CSV,Text}() to use a callback in COPY FROM"
This reverts commit95fb5b4, for reasons similar to what led to1aa8324. In this case, the callback was called once per row, whichis less worse than the previous callback introduced for COPY TO calledonce per argument for each row, still the patch set discussed to plug incustom routines to the COPY paths would be able to know which subroutineto use depending on its CopyFromState, so this led to a suboptimalapproach at the end.For now, this part is reverted to consider better which approach to use.Discussion:https://postgr.es/m/20240206014125.qofww7ew3dx3v3uk@awork3.anarazel.de
1 parentd0071f9 commit06bd311

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

‎src/backend/commands/copyfrom.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,11 +1776,6 @@ BeginCopyFrom(ParseState *pstate,
17761776

17771777
cstate->max_fields=attr_count;
17781778
cstate->raw_fields= (char**)palloc(attr_count*sizeof(char*));
1779-
1780-
if (cstate->opts.csv_mode)
1781-
cstate->copy_read_attributes=CopyReadAttributesCSV;
1782-
else
1783-
cstate->copy_read_attributes=CopyReadAttributesText;
17841779
}
17851780

17861781
MemoryContextSwitchTo(oldcontext);

‎src/backend/commands/copyfromparse.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
* is copied into 'line_buf', with quotes and escape characters still
2626
* intact.
2727
*
28-
* 4. CopyReadAttributesText/CSV() function(via copy_read_attribute) takes
29-
*the input line from'line_buf', and splits it into fields, unescaping
30-
*the data as required.The fields are stored in 'attribute_buf', and
31-
*'raw_fields' array holdspointers to each field.
28+
* 4. CopyReadAttributesText/CSV() functiontakes the input line from
29+
* 'line_buf', and splits it into fields, unescaping the data as required.
30+
* The fields are stored in 'attribute_buf', and 'raw_fields' array holds
31+
* pointers to each field.
3232
*
3333
* If encoding conversion is not required, a shortcut is taken in step 2 to
3434
* avoid copying the data unnecessarily. The 'input_buf' pointer is set to
@@ -152,6 +152,8 @@ static const char BinarySignature[11] = "PGCOPY\n\377\r\n\0";
152152
/* non-export function prototypes */
153153
staticboolCopyReadLine(CopyFromStatecstate);
154154
staticboolCopyReadLineText(CopyFromStatecstate);
155+
staticintCopyReadAttributesText(CopyFromStatecstate);
156+
staticintCopyReadAttributesCSV(CopyFromStatecstate);
155157
staticDatumCopyReadBinaryAttribute(CopyFromStatecstate,FmgrInfo*flinfo,
156158
Oidtypioparam,int32typmod,
157159
bool*isnull);
@@ -773,7 +775,10 @@ NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
773775
{
774776
intfldnum;
775777

776-
fldct=cstate->copy_read_attributes(cstate);
778+
if (cstate->opts.csv_mode)
779+
fldct=CopyReadAttributesCSV(cstate);
780+
else
781+
fldct=CopyReadAttributesText(cstate);
777782

778783
if (fldct!=list_length(cstate->attnumlist))
779784
ereport(ERROR,
@@ -825,7 +830,10 @@ NextCopyFromRawFields(CopyFromState cstate, char ***fields, int *nfields)
825830
return false;
826831

827832
/* Parse the line into de-escaped field values */
828-
fldct=cstate->copy_read_attributes(cstate);
833+
if (cstate->opts.csv_mode)
834+
fldct=CopyReadAttributesCSV(cstate);
835+
else
836+
fldct=CopyReadAttributesText(cstate);
829837

830838
*fields=cstate->raw_fields;
831839
*nfields=fldct;
@@ -1494,7 +1502,7 @@ GetDecimalFromHex(char hex)
14941502
*
14951503
* The return value is the number of fields actually read.
14961504
*/
1497-
int
1505+
staticint
14981506
CopyReadAttributesText(CopyFromStatecstate)
14991507
{
15001508
chardelimc=cstate->opts.delim[0];
@@ -1748,7 +1756,7 @@ CopyReadAttributesText(CopyFromState cstate)
17481756
* CopyReadAttributesText, except we parse the fields according to
17491757
* "standard" (i.e. common) CSV usage.
17501758
*/
1751-
int
1759+
staticint
17521760
CopyReadAttributesCSV(CopyFromStatecstate)
17531761
{
17541762
chardelimc=cstate->opts.delim[0];

‎src/include/commands/copyfrom_internal.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ typedef enum CopyInsertMethod
5252
* ExecForeignBatchInsert only if valid */
5353
}CopyInsertMethod;
5454

55-
/*
56-
* Per-format callback to parse a line into separate fields.
57-
*
58-
* Returns the number of fields read.
59-
*/
60-
typedefint (*CopyReadAttributes) (CopyFromStatecstate);
61-
6255
/*
6356
* This struct contains all the state variables used throughout a COPY FROM
6457
* operation.
@@ -137,12 +130,6 @@ typedef struct CopyFromStateData
137130
intmax_fields;
138131
char**raw_fields;
139132

140-
/*
141-
* Per-format callback to parse lines, then fill raw_fields and
142-
* attribute_buf.
143-
*/
144-
CopyReadAttributescopy_read_attributes;
145-
146133
/*
147134
* Similarly, line_buf holds the whole input line being processed. The
148135
* input cycle is first to read the whole line into line_buf, and then
@@ -196,8 +183,4 @@ typedef struct CopyFromStateData
196183
externvoidReceiveCopyBegin(CopyFromStatecstate);
197184
externvoidReceiveCopyBinaryHeader(CopyFromStatecstate);
198185

199-
/* Callbacks for copy_read_attributes */
200-
externintCopyReadAttributesCSV(CopyFromStatecstate);
201-
externintCopyReadAttributesText(CopyFromStatecstate);
202-
203186
#endif/* COPYFROM_INTERNAL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp