mirror of
https://github.com/zebrajr/postgres.git
synced 2025-12-06 12:20:15 +01:00
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@clear-code.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com> Reviewed-by: Junwang Zhao <zhjwpku@gmail.com> Discussion: https://postgr.es/m/20231204.153548.2126325458835528809.kou@clear-code.com
58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* copyapi.h
|
|
* API for COPY TO handlers
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* src/include/commands/copyapi.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef COPYAPI_H
|
|
#define COPYAPI_H
|
|
|
|
#include "commands/copy.h"
|
|
|
|
/*
|
|
* API structure for a COPY TO format implementation. Note this must be
|
|
* allocated in a server-lifetime manner, typically as a static const struct.
|
|
*/
|
|
typedef struct CopyToRoutine
|
|
{
|
|
/*
|
|
* Set output function information. This callback is called once at the
|
|
* beginning of COPY TO.
|
|
*
|
|
* 'finfo' can be optionally filled to provide the catalog information of
|
|
* the output function.
|
|
*
|
|
* 'atttypid' is the OID of data type used by the relation's attribute.
|
|
*/
|
|
void (*CopyToOutFunc) (CopyToState cstate, Oid atttypid,
|
|
FmgrInfo *finfo);
|
|
|
|
/*
|
|
* Start a COPY TO. This callback is called once at the beginning of COPY
|
|
* TO.
|
|
*
|
|
* 'tupDesc' is the tuple descriptor of the relation from where the data
|
|
* is read.
|
|
*/
|
|
void (*CopyToStart) (CopyToState cstate, TupleDesc tupDesc);
|
|
|
|
/*
|
|
* Write one row stored in 'slot' to the destination.
|
|
*/
|
|
void (*CopyToOneRow) (CopyToState cstate, TupleTableSlot *slot);
|
|
|
|
/*
|
|
* End a COPY TO. This callback is called once at the end of COPY TO.
|
|
*/
|
|
void (*CopyToEnd) (CopyToState cstate);
|
|
} CopyToRoutine;
|
|
|
|
#endif /* COPYAPI_H */
|