PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/tableam.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "commands/copy.h"
#include "commands/progress.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
#include "executor/tuptable.h"
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "optimizer/optimizer.h"
#include "pgstat.h"
#include "rewrite/rewriteHandler.h"
#include "storage/fd.h"
#include "tcop/tcopprot.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/partcache.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
Go to the source code of this file.
Data Structures | |
struct | CopyToStateData |
struct | DR_copy |
Macros | |
#define | DUMPSOFAR() |
Typedefs | |
typedef enum CopyDest | CopyDest |
typedef struct CopyToStateData | CopyToStateData |
Enumerations | |
enum | CopyDest { COPY_FILE, COPY_OLD_FE, COPY_NEW_FE } |
Functions | |
static void | EndCopy (CopyToState cstate) |
static void | ClosePipeToProgram (CopyToState cstate) |
static uint64 | CopyTo (CopyToState cstate) |
static void | CopyOneRowTo (CopyToState cstate, TupleTableSlot *slot) |
static void | CopyAttributeOutText (CopyToState cstate, char *string) |
static void | CopyAttributeOutCSV (CopyToState cstate, char *string, bool use_quote, bool single_attr) |
static void | SendCopyBegin (CopyToState cstate) |
static void | SendCopyEnd (CopyToState cstate) |
static void | CopySendData (CopyToState cstate, const void *databuf, int datasize) |
static void | CopySendString (CopyToState cstate, const char *str) |
static void | CopySendChar (CopyToState cstate, char c) |
static void | CopySendEndOfRow (CopyToState cstate) |
static void | CopySendInt32 (CopyToState cstate, int32 val) |
static void | CopySendInt16 (CopyToState cstate, int16 val) |
CopyToState | BeginCopyTo (ParseState *pstate, Relation rel, RawStmt *raw_query, Oid queryRelId, const char *filename, bool is_program, List *attnamelist, List *options) |
uint64 | DoCopyTo (CopyToState cstate) |
void | EndCopyTo (CopyToState cstate) |
static void | copy_dest_startup (DestReceiver *self, int operation, TupleDesc typeinfo) |
static bool | copy_dest_receive (TupleTableSlot *slot, DestReceiver *self) |
static void | copy_dest_shutdown (DestReceiver *self) |
static void | copy_dest_destroy (DestReceiver *self) |
DestReceiver * | CreateCopyDestReceiver (void) |
Variables | |
static const char | BinarySignature [11] = "PGCOPY\n\377\r\n\0" |
#define DUMPSOFAR | ( | ) |
Definition at line 1061 of file copyto.c.
Referenced by CopyAttributeOutCSV(), and CopyAttributeOutText().
typedef struct CopyToStateData CopyToStateData |
enum CopyDest |
Enumerator | |
---|---|
COPY_FILE | |
COPY_OLD_FE | |
COPY_NEW_FE |
CopyToState BeginCopyTo | ( | ParseState * | pstate, |
Relation | rel, | ||
RawStmt * | raw_query, | ||
Oid | queryRelId, | ||
const char * | filename, | ||
bool | is_program, | ||
List * | attnamelist, | ||
List * | options | ||
) |
Definition at line 383 of file copyto.c.
References AllocateFile(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, attnum, CopyToStateData::attnumlist, CopyToStateData::bytes_processed, CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, Query::commandType, CopyToStateData::copy_dest, COPY_FILE, CopyToStateData::copy_file, CopyToStateData::copycontext, CopyGetAttnums(), copyObject, CreateDestReceiver(), CreateQueryDesc(), cur, CurrentMemoryContext, CURSOR_OPT_PARALLEL_OK, generate_unaccent_rules::dest, DestCopyOut, DestRemote, CopyToStateData::encoding_embeds_ascii, ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, ExecutorStart(), CopyFormatOptions::file_encoding, CopyToStateData::file_encoding, CopyToStateData::filename, CopyFormatOptions::force_notnull, CopyFormatOptions::force_notnull_flags, CopyFormatOptions::force_null, CopyFormatOptions::force_null_flags, CopyFormatOptions::force_quote, CopyFormatOptions::force_quote_all, CopyFormatOptions::force_quote_flags, fstat, GetActiveSnapshot(), GetDatabaseEncoding(), i, InvalidOid, InvalidSnapshot, is_absolute_path, CopyToStateData::is_program, IsA, lfirst_int, lfirst_node, linitial_node, list_length(), list_member_int(), list_member_oid(), MemoryContextSwitchTo(), NameStr, TupleDescData::natts, CopyToStateData::need_transcoding, NIL, OpenPipeStream(), CopyToStateData::opts, ParseState::p_sourcetext, palloc0(), pg_analyze_and_rewrite(), PG_BINARY_W, pg_database_encoding_max_length(), PG_ENCODING_IS_CLIENT_ONLY, PG_END_TRY, PG_FINALLY, pg_get_client_encoding(), pg_plan_query(), PG_TRY, pgstat_progress_start_command(), ProcessCopyOptions(), PROGRESS_COMMAND_COPY, pstrdup(), PushCopiedSnapshot(), QSRC_NON_INSTEAD_RULE, QSRC_QUAL_INSTEAD_RULE, CopyToStateData::queryDesc, Query::querySource, RelationData::rd_rel, CopyToStateData::rel, RelationGetDescr, RelationGetRelationName, RelationGetRelid, PlannedStmt::relationOids, Query::returningList, S_ISDIR, S_IWGRP, S_IWOTH, stat::st_mode, generate_unaccent_rules::stdout, QueryDesc::tupDesc, TupleDescAttr, UpdateActiveSnapshotCommandId(), Query::utilityStmt, and whereToSendOutput.
Referenced by DoCopy().
|
static |
Definition at line 333 of file copyto.c.
References Assert, ClosePipeStream(), CopyToStateData::copy_file, ereport, errcode(), errcode_for_file_access(), errdetail_internal(), errmsg(), ERROR, CopyToStateData::filename, CopyToStateData::is_program, and wait_result_to_str().
Referenced by CopySendEndOfRow(), and EndCopy().
|
static |
Definition at line 1342 of file copyto.c.
References pfree().
Referenced by CreateCopyDestReceiver().
|
static |
Definition at line 1315 of file copyto.c.
References CopyOneRowTo(), DR_copy::cstate, pgstat_progress_update_param(), DR_copy::processed, and PROGRESS_COPY_LINES_PROCESSED.
Referenced by CreateCopyDestReceiver().
|
static |
Definition at line 1333 of file copyto.c.
Referenced by CreateCopyDestReceiver().
|
static |
Definition at line 1306 of file copyto.c.
Referenced by CreateCopyDestReceiver().
|
static |
Definition at line 1221 of file copyto.c.
References CopySendChar(), CopySendString(), CopyFormatOptions::delim, DUMPSOFAR, CopyToStateData::encoding_embeds_ascii, CopyFormatOptions::escape, CopyToStateData::file_encoding, IS_HIGHBIT_SET, CopyToStateData::need_transcoding, CopyFormatOptions::null_print, CopyToStateData::opts, pg_encoding_mblen(), pg_server_to_any(), and CopyFormatOptions::quote.
Referenced by CopyOneRowTo(), and CopyTo().
|
static |
Definition at line 1068 of file copyto.c.
References CopySendChar(), CopyFormatOptions::delim, DUMPSOFAR, CopyToStateData::encoding_embeds_ascii, CopyToStateData::file_encoding, IS_HIGHBIT_SET, CopyToStateData::need_transcoding, CopyToStateData::opts, pg_encoding_mblen(), and pg_server_to_any().
Referenced by CopyOneRowTo().
|
static |
Definition at line 987 of file copyto.c.
References attnum, CopyToStateData::attnumlist, CopyFormatOptions::binary, CopyAttributeOutCSV(), CopyAttributeOutText(), CopySendChar(), CopySendData(), CopySendEndOfRow(), CopySendInt16(), CopySendInt32(), CopySendString(), CopyFormatOptions::csv_mode, cur, CopyFormatOptions::delim, CopyFormatOptions::force_quote_flags, lfirst_int, list_length(), MemoryContextReset(), MemoryContextSwitchTo(), CopyFormatOptions::null_print_client, CopyToStateData::opts, CopyToStateData::out_functions, OutputFunctionCall(), CopyToStateData::rowcontext, SendFunctionCall(), slot_getallattrs(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, value, VARDATA, VARHDRSZ, and VARSIZE.
Referenced by copy_dest_receive(), and CopyTo().
|
static |
Definition at line 215 of file copyto.c.
References appendStringInfoCharMacro, and CopyToStateData::fe_msgbuf.
Referenced by CopyAttributeOutCSV(), CopyAttributeOutText(), CopyOneRowTo(), CopySendEndOfRow(), and CopyTo().
|
static |
Definition at line 203 of file copyto.c.
References appendBinaryStringInfo(), and CopyToStateData::fe_msgbuf.
Referenced by CopyOneRowTo(), CopySendInt16(), CopySendInt32(), CopyTo(), and SendCopyEnd().
|
static |
Definition at line 221 of file copyto.c.
References CopyFormatOptions::binary, CopyToStateData::bytes_processed, ClosePipeToProgram(), CopyToStateData::copy_dest, COPY_FILE, CopyToStateData::copy_file, COPY_NEW_FE, COPY_OLD_FE, CopySendChar(), CopySendString(), StringInfoData::data, ereport, errcode(), errcode_for_file_access(), errmsg(), ERROR, FATAL, CopyToStateData::fe_msgbuf, CopyToStateData::is_program, StringInfoData::len, CopyToStateData::opts, pgstat_progress_update_param(), pq_putbytes(), pq_putmessage, PROGRESS_COPY_BYTES_PROCESSED, and resetStringInfo().
Referenced by CopyOneRowTo(), CopyTo(), and SendCopyEnd().
|
inlinestatic |
Definition at line 321 of file copyto.c.
References buf, CopySendData(), and pg_hton16.
Referenced by CopyOneRowTo(), and CopyTo().
|
inlinestatic |
Definition at line 309 of file copyto.c.
References buf, CopySendData(), and pg_hton32.
Referenced by CopyOneRowTo(), and CopyTo().
|
static |
Definition at line 209 of file copyto.c.
References appendBinaryStringInfo(), and CopyToStateData::fe_msgbuf.
Referenced by CopyAttributeOutCSV(), CopyOneRowTo(), and CopySendEndOfRow().
|
static |
Definition at line 841 of file copyto.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, attname, attnum, CopyToStateData::attnumlist, CopyFormatOptions::binary, BinarySignature, CHECK_FOR_INTERRUPTS, CopyAttributeOutCSV(), CopyOneRowTo(), CopySendChar(), CopySendData(), CopySendEndOfRow(), CopySendInt16(), CopySendInt32(), cur, CurrentMemoryContext, CopyFormatOptions::delim, QueryDesc::dest, ExecDropSingleTupleTableSlot(), ExecutorRun(), CopyToStateData::fe_msgbuf, CopyToStateData::file_encoding, fmgr_info(), ForwardScanDirection, GetActiveSnapshot(), getTypeBinaryOutputInfo(), getTypeOutputInfo(), CopyFormatOptions::header_line, lfirst_int, list_length(), makeStringInfo(), MemoryContextDelete(), NameStr, TupleDescData::natts, CopyToStateData::need_transcoding, CopyFormatOptions::null_print, CopyFormatOptions::null_print_client, CopyFormatOptions::null_print_len, CopyToStateData::opts, CopyToStateData::out_functions, palloc(), pg_server_to_any(), pgstat_progress_update_param(), PROGRESS_COPY_LINES_PROCESSED, CopyToStateData::queryDesc, CopyToStateData::rel, RelationGetDescr, CopyToStateData::rowcontext, slot_getallattrs(), table_beginscan(), table_endscan(), table_scan_getnextslot(), table_slot_create(), QueryDesc::tupDesc, and TupleDescAttr.
Referenced by DoCopyTo().
DestReceiver* CreateCopyDestReceiver | ( | void | ) |
Definition at line 1351 of file copyto.c.
References copy_dest_destroy(), copy_dest_receive(), copy_dest_shutdown(), copy_dest_startup(), DestCopyOut, and palloc().
Referenced by CreateDestReceiver().
uint64 DoCopyTo | ( | CopyToState | cstate | ) |
Definition at line 787 of file copyto.c.
References CopyTo(), DestRemote, CopyToStateData::filename, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pq_endcopyout, SendCopyBegin(), SendCopyEnd(), and whereToSendOutput.
Referenced by DoCopy().
|
static |
Definition at line 358 of file copyto.c.
References ClosePipeToProgram(), CopyToStateData::copy_file, CopyToStateData::copycontext, ereport, errcode_for_file_access(), errmsg(), ERROR, CopyToStateData::filename, FreeFile(), CopyToStateData::is_program, MemoryContextDelete(), pfree(), and pgstat_progress_end_command().
Referenced by EndCopyTo().
void EndCopyTo | ( | CopyToState | cstate | ) |
Definition at line 822 of file copyto.c.
References EndCopy(), ExecutorEnd(), ExecutorFinish(), FreeQueryDesc(), PopActiveSnapshot(), and CopyToStateData::queryDesc.
Referenced by DoCopy().
|
static |
Definition at line 141 of file copyto.c.
References CopyToStateData::attnumlist, CopyFormatOptions::binary, buf, CopyToStateData::copy_dest, COPY_NEW_FE, COPY_OLD_FE, ereport, errcode(), errmsg(), ERROR, format, FrontendProtocol, i, list_length(), CopyToStateData::opts, PG_PROTOCOL_MAJOR, pq_beginmessage(), pq_endmessage(), pq_putemptymessage(), pq_sendbyte(), pq_sendint16(), and pq_startcopyout.
Referenced by DoCopyTo().
|
static |
Definition at line 174 of file copyto.c.
References Assert, CopyToStateData::copy_dest, COPY_NEW_FE, CopySendData(), CopySendEndOfRow(), CopyToStateData::fe_msgbuf, StringInfoData::len, pq_endcopyout, and pq_putemptymessage().
Referenced by DoCopyTo().