pgsql: Refactor COPY TO to use format callback functions.

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Refactor COPY TO to use format callback functions.
Date: 2025-02-27 23:04:08
Message-ID: E1tnmvI-0003Bl-1n@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Refactor COPY TO to use format callback functions.

This commit introduces a new CopyToRoutine struct, which is a set of
callback routines to copy tuples in a specific format. It also makes
the existing formats (text, CSV, and binary) utilize these format
callbacks.

This change is a preliminary step towards making the COPY TO command
extensible in terms of output formats.

Additionally, this refactoring contributes to a performance
improvement by reducing the number of "if" branches that need to be
checked on a per-row basis when sending field representations in text
or CSV mode. The performance benchmark results showed ~5% performance
gain in text or CSV mode.

Author: Sutou Kouhei <kou(at)clear-code(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
Reviewed-by: Junwang Zhao <zhjwpku(at)gmail(dot)com>
Discussion: https://postgr.es/m/20231204.153548.2126325458835528809.kou@clear-code.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2e4127b6d2d8f3a9d67a21d1905703d5be46970c

Modified Files
--------------
src/backend/commands/copyto.c | 438 ++++++++++++++++++++++++++-------------
src/include/commands/copyapi.h | 57 +++++
src/tools/pgindent/typedefs.list | 1 +
3 files changed, 355 insertions(+), 141 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-02-28 01:16:34 pgsql: pg_upgrade: Fix inconsistency in memory freeing
Previous Message Mark Dilger 2025-02-27 22:17:27 Re: pgsql: Generalize hash and ordering support in amapi