Re: Make COPY format extendable: Extract COPY TO format implementations
Sutou Kouhei <kou@clear-code.com>
Hi, In <CAKFQuwbhSssKTJyeYo9rn20zffV3L7wdQSbEQ8zwRfC=uXLkVA@mail.gmail.com> "Re: Make COPY format extendable: Extract COPY TO format implementations" on Mon, 31 Mar 2025 10:05:34 -0700, "David G. Johnston" <david.g.johnston@gmail.com> wrote: > The CopyFromInFunc API allows for each attribute to somehow > have its I/O format individualized. But I don't see how that is practical > or useful, and it adds burden on API users. If an extension want to use I/O routines, it can use the CopyFromInFunc API. Otherwise it can provide an empty function. For example, https://github.com/MasahikoSawada/pg_copy_jsonlines/blob/master/copy_jsonlines.c uses the CopyFromInFunc API but https://github.com/kou/pg-copy-arrow/blob/main/copy_arrow.cc uses an empty function for the CopyFromInFunc API. The "it adds burden" means that "defining an empty function is inconvenient", right? See also our past discussion for this design: https://www.postgresql.org/message-id/ZbijVn9_51mljMAG%40paquier.xyz > Keeping empty options does not strike as a bad idea, because this > forces extension developers to think about this code path rather than > just ignore it. > I suggest we remove both .CopyFromInFunc and .CopyFromStart/End and add a > property to CopyFromRoutine (.ioMode?) with values of either Copy_IO_Text > or Copy_IO_Binary and then just branch to either: > > CopyFromTextLikeInFunc & CopyFromTextLikeStart/End > or > CopyFromBinaryInFunc & CopyFromStart/End > > So, in effect, the only method an extension needs to write is converting > to/from the 'serialized' form to the text/binary form (text being near > unanimous). I object this API. If we choose this API, we can create only custom COPY formats that compatible with PostgreSQL's text/binary form. For example, the above jsonlines format and Apache Arrow format aren't implemented. It's meaningless to introduce this custom COPY format mechanism with the suggested API. > It seems to me that CopyFromOneRow could simply produce a *string > collection, > one cell per attribute, and NextCopyFrom could do all of the above on a > for-loop over *string You suggest that we use a string collection instead of a Datum collection in CopyFromOneRow() and convert a string collection to a Datum collection in NextCopyFrom(), right? I object this API. Because it has needless string <-> Datum conversion overhead. For example, https://github.com/MasahikoSawada/pg_copy_jsonlines/blob/master/copy_jsonlines.c parses a JSON value to Datum. If we use this API, we need to convert parsed Datum to string in an extension and NextCopyFrom() re-converts the converted string to Datum. It will slow down custom COPY format. I want this custom COPY format feature for performance. So APIs that require needless overhead for non text/csv/binary formats isn't acceptable to me. Thanks, -- kou
Commits
-
Refactor Copy{From|To}GetRoutine() to use pass-by-reference argument.
- bacbc4863b3b 18.0 landed
-
Refactor COPY FROM to use format callback functions.
- 7717f6300693 18.0 landed
-
Refactor COPY TO to use format callback functions.
- 2e4127b6d2d8 18.0 landed
-
Another try to fix BF failure introduced in commit ddd5f4f54a.
- 9bc1eee988c3 17.0 cited
-
Revert "Refactor CopyReadAttributes{CSV,Text}() to use a callback in COPY FROM"
- 06bd311bce24 17.0 landed
-
Improve COPY TO performance when server and client encodings match
- b619852086ed 17.0 cited
-
Simplify signature of CopyAttributeOutCSV() in copyto.c
- b9d6038d7048 17.0 landed
-
Revert "Refactor CopyAttributeOut{CSV,Text}() to use a callback in COPY TO"
- 1aa8324b81fa 17.0 landed
-
Refactor CopyAttributeOut{CSV,Text}() to use a callback in COPY TO
- 2889fd23be56 17.0 landed
-
Refactor CopyReadAttributes{CSV,Text}() to use a callback in COPY FROM
- 95fb5b49024a 17.0 landed
-
Add progress reporting of skipped tuples during COPY FROM.
- 729439607ad2 17.0 cited
-
pgbench: Add \syncpipeline
- 94edfe250c6a 17.0 cited
-
meson: Make gzip and tar optional
- 9ca6e7b9411e 17.0 cited
-
Export the external file reader used in COPY FROM as APIs.
- 8ddc05fb01ee 9.1.0 cited