Re: Make COPY format extendable: Extract COPY TO format implementations

Vladlen Popolitov <v.popolitov@postgrespro.ru>

From: Vladlen Popolitov <v.popolitov@postgrespro.ru>
To: Álvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Sutou Kouhei <kou@clear-code.com>, sawada.mshk@gmail.com, zhjwpku@gmail.com, michael@paquier.xyz, pgsql-hackers@postgresql.org
Date: 2025-02-05T15:26:14Z
Lists: pgsql-hackers
Álvaro Herrera писал(а) 2025-02-05 18:49:
> On 2025-Feb-03, Vladlen Popolitov wrote:
> 
>> You use FORMAT option to add new formats, filling it with routine name
>> in shared library. As result any caller can call any routine in 
>> PostgreSQL
>> kernel.
>> I think, it will start competition, who can find most dangerous 
>> routine
>> to call just from COPY FROM command.
> 
> Hah.
> 
> Maybe it would be a better UI to require that COPY format handlers are
> registered explicitly before they can be used:
> 
>  CREATE ACCESS METHOD copy_yaml TYPE copy HANDLER copy_yaml_handler;
> 
> ... and then when the FORMAT is not recognized as one of the hardcoded
> methods, we go look in pg_am for one with amtype='c' and the given 
> name.
> That gives you the function that initializes the Copy state.
> 
> This is convenient enough because system administrators can add COPY
> formats that anyone can use, and doesn't allow to call arbitrary
> functions via COPY.

Yes! It is what I propose. This looks much safer and already used in 
access methods creation.

-- 
Best regards,

Vladlen Popolitov.



Commits

  1. Refactor Copy{From|To}GetRoutine() to use pass-by-reference argument.

  2. Refactor COPY FROM to use format callback functions.

  3. Refactor COPY TO to use format callback functions.

  4. Another try to fix BF failure introduced in commit ddd5f4f54a.

  5. Revert "Refactor CopyReadAttributes{CSV,Text}() to use a callback in COPY FROM"

  6. Improve COPY TO performance when server and client encodings match

  7. Simplify signature of CopyAttributeOutCSV() in copyto.c

  8. Revert "Refactor CopyAttributeOut{CSV,Text}() to use a callback in COPY TO"

  9. Refactor CopyAttributeOut{CSV,Text}() to use a callback in COPY TO

  10. Refactor CopyReadAttributes{CSV,Text}() to use a callback in COPY FROM

  11. Add progress reporting of skipped tuples during COPY FROM.

  12. pgbench: Add \syncpipeline

  13. meson: Make gzip and tar optional

  14. Export the external file reader used in COPY FROM as APIs.