PostgreSQL Source Code git master
|
#include "postgres.h"
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
#include "access/tableam.h"
#include "commands/copyapi.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 "pgstat.h"
#include "storage/fd.h"
#include "tcop/tcopprot.h"
#include "utils/lsyscache.h"
#include "utils/memutils.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_FRONTEND , COPY_CALLBACK } |
Variables | |
static const char | BinarySignature [11] = "PGCOPY\n\377\r\n\0" |
static const CopyToRoutine | CopyToRoutineText |
static const CopyToRoutine | CopyToRoutineCSV |
static const CopyToRoutine | CopyToRoutineBinary |
#define DUMPSOFAR | ( | ) |
typedef struct CopyToStateData CopyToStateData |
enum CopyDest |
CopyToState BeginCopyTo | ( | ParseState * | pstate, |
Relation | rel, | ||
RawStmt * | raw_query, | ||
Oid | queryRelId, | ||
const char * | filename, | ||
bool | is_program, | ||
copy_data_dest_cb | data_dest_cb, | ||
List * | attnamelist, | ||
List * | options | ||
) |
Definition at line 623 of file copyto.c.
References AllocateFile(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), attnum, CopyToStateData::attnumlist, CopyToStateData::bytes_processed, CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_SELECT, CMD_UPDATE, Query::commandType, COPY_CALLBACK, CopyToStateData::copy_dest, COPY_FILE, CopyToStateData::copy_file, CopyToStateData::copycontext, CopyGetAttnums(), CopyToGetRoutine(), CreateDestReceiver(), CreateQueryDesc(), cur, CurrentMemoryContext, CURSOR_OPT_PARALLEL_OK, CopyToStateData::data_dest_cb, generate_unaccent_rules::dest, DestCopyOut, DestRemote, elog, CopyToStateData::encoding_embeds_ascii, ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, ExecutorStart(), CopyToStateData::file_encoding, CopyFormatOptions::file_encoding, CopyToStateData::filename, filename, CopyFormatOptions::force_quote, CopyFormatOptions::force_quote_all, CopyFormatOptions::force_quote_flags, fstat, GetActiveSnapshot(), GetDatabaseEncoding(), InvalidOid, InvalidSnapshot, is_absolute_path, CopyToStateData::is_program, IsA, lfirst_int, lfirst_node, linitial_node, list_length(), list_member_int(), list_member_oid(), MemoryContextSwitchTo(), MemSet, NameStr, TupleDescData::natts, CopyToStateData::need_transcoding, NIL, OpenPipeStream(), CopyToStateData::opts, ParseState::p_sourcetext, palloc0(), pg_analyze_and_rewrite_fixedparams(), PG_BINARY_W, PG_ENCODING_IS_CLIENT_ONLY, PG_END_TRY, PG_FINALLY, pg_get_client_encoding(), pg_plan_query(), PG_SQL_ASCII, PG_TRY, pgstat_progress_start_command(), pgstat_progress_update_multi_param(), plan, ProcessCopyOptions(), PROGRESS_COMMAND_COPY, PROGRESS_COPY_COMMAND, PROGRESS_COPY_COMMAND_TO, PROGRESS_COPY_TYPE, PROGRESS_COPY_TYPE_CALLBACK, PROGRESS_COPY_TYPE_FILE, PROGRESS_COPY_TYPE_PIPE, PROGRESS_COPY_TYPE_PROGRAM, pstrdup(), PushCopiedSnapshot(), QSRC_NON_INSTEAD_RULE, QSRC_QUAL_INSTEAD_RULE, CopyToStateData::queryDesc, RelationData::rd_rel, CopyToStateData::rel, RelationGetDescr, RelationGetRelationName, RelationGetRelid, Query::returningList, CopyToStateData::routine, S_ISDIR, S_IWGRP, S_IWOTH, stat::st_mode, generate_unaccent_rules::stdout, QueryDesc::tupDesc, TupleDescAttr(), UpdateActiveSnapshotCommandId(), Query::utilityStmt, and whereToSendOutput.
Referenced by DoCopy(), and test_copy_to_callback().
|
static |
Definition at line 562 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 1424 of file copyto.c.
References pfree().
Referenced by CreateCopyDestReceiver().
|
static |
Definition at line 1396 of file copyto.c.
References CopyOneRowTo(), DR_copy::cstate, pgstat_progress_update_param(), DR_copy::processed, and PROGRESS_COPY_TUPLES_PROCESSED.
Referenced by CreateCopyDestReceiver().
|
static |
Definition at line 1415 of file copyto.c.
Referenced by CreateCopyDestReceiver().
|
static |
Definition at line 1387 of file copyto.c.
Referenced by CreateCopyDestReceiver().
|
static |
Definition at line 1298 of file copyto.c.
References CopyToStateData::attnumlist, CopySendChar(), CopySendString(), CopyFormatOptions::delim, DUMPSOFAR, CopyToStateData::encoding_embeds_ascii, CopyFormatOptions::escape, CopyToStateData::file_encoding, IS_HIGHBIT_SET, list_length(), CopyToStateData::need_transcoding, CopyFormatOptions::null_print, CopyToStateData::opts, pg_encoding_mblen(), pg_server_to_any(), CopyFormatOptions::quote, and start.
Referenced by CopyToTextLikeOneRow(), and CopyToTextLikeStart().
|
static |
Definition at line 1145 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(), pg_server_to_any(), and start.
Referenced by CopyToTextLikeOneRow(), and CopyToTextLikeStart().
|
inlinestatic |
Definition at line 1120 of file copyto.c.
References CopyToRoutine::CopyToOneRow, MemoryContextReset(), MemoryContextSwitchTo(), CopyToStateData::routine, CopyToStateData::rowcontext, and slot_getallattrs().
Referenced by copy_dest_receive(), and DoCopyTo().
|
static |
Definition at line 439 of file copyto.c.
References appendStringInfoCharMacro, and CopyToStateData::fe_msgbuf.
Referenced by CopyAttributeOutCSV(), CopyAttributeOutText(), CopySendTextLikeEndOfRow(), CopyToTextLikeOneRow(), and CopyToTextLikeStart().
|
static |
Definition at line 427 of file copyto.c.
References appendBinaryStringInfo(), and CopyToStateData::fe_msgbuf.
Referenced by CopySendInt16(), CopySendInt32(), CopyToBinaryOneRow(), and CopyToBinaryStart().
|
static |
Definition at line 445 of file copyto.c.
References CopyToStateData::bytes_processed, ClosePipeToProgram(), COPY_CALLBACK, CopyToStateData::copy_dest, COPY_FILE, CopyToStateData::copy_file, COPY_FRONTEND, StringInfoData::data, CopyToStateData::data_dest_cb, ereport, errcode_for_file_access(), errmsg(), ERROR, CopyToStateData::fe_msgbuf, CopyToStateData::is_program, StringInfoData::len, pgstat_progress_update_param(), pq_putmessage, PqMsg_CopyData, PROGRESS_COPY_BYTES_PROCESSED, and resetStringInfo().
Referenced by CopySendTextLikeEndOfRow(), CopyToBinaryEnd(), and CopyToBinaryOneRow().
|
inlinestatic |
Definition at line 550 of file copyto.c.
References buf, CopySendData(), pg_hton16, and val.
Referenced by CopyToBinaryEnd(), and CopyToBinaryOneRow().
|
inlinestatic |
Definition at line 538 of file copyto.c.
References buf, CopySendData(), pg_hton32, and val.
Referenced by CopyToBinaryOneRow(), and CopyToBinaryStart().
|
static |
Definition at line 433 of file copyto.c.
References appendBinaryStringInfo(), CopyToStateData::fe_msgbuf, and str.
Referenced by CopyAttributeOutCSV(), CopySendTextLikeEndOfRow(), and CopyToTextLikeOneRow().
|
inlinestatic |
Definition at line 506 of file copyto.c.
References CopyToStateData::copy_dest, COPY_FILE, COPY_FRONTEND, CopySendChar(), CopySendEndOfRow(), and CopySendString().
Referenced by CopyToTextLikeOneRow(), and CopyToTextLikeStart().
|
static |
Definition at line 378 of file copyto.c.
References CopySendEndOfRow(), and CopySendInt16().
|
static |
Definition at line 345 of file copyto.c.
References attnum, CopyToStateData::attnumlist, CopySendData(), CopySendEndOfRow(), CopySendInt16(), CopySendInt32(), foreach_int, list_length(), CopyToStateData::out_functions, SendFunctionCall(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, value, VARDATA, VARHDRSZ, and VARSIZE.
|
static |
Definition at line 333 of file copyto.c.
References fmgr_info(), and getTypeBinaryOutputInfo().
|
static |
Definition at line 314 of file copyto.c.
References BinarySignature, CopySendData(), and CopySendInt32().
|
static |
Definition at line 252 of file copyto.c.
References CopyToTextLikeOneRow().
|
static |
Definition at line 177 of file copyto.c.
References CopyToRoutineBinary, CopyToRoutineCSV, CopyToRoutineText, and opts.
Referenced by BeginCopyTo().
|
static |
|
static |
Definition at line 264 of file copyto.c.
References attnum, CopyToStateData::attnumlist, CopyAttributeOutCSV(), CopyAttributeOutText(), CopySendChar(), CopySendString(), CopySendTextLikeEndOfRow(), CopyFormatOptions::delim, CopyFormatOptions::force_quote_flags, foreach_int, CopyFormatOptions::null_print_client, CopyToStateData::opts, CopyToStateData::out_functions, OutputFunctionCall(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, and value.
Referenced by CopyToCSVOneRow(), and CopyToTextOneRow().
|
static |
Definition at line 233 of file copyto.c.
References fmgr_info(), and getTypeOutputInfo().
|
static |
Definition at line 190 of file copyto.c.
References attname, attnum, CopyToStateData::attnumlist, CopyAttributeOutCSV(), CopyAttributeOutText(), CopySendChar(), CopySendTextLikeEndOfRow(), CopyFormatOptions::csv_mode, cur, CopyFormatOptions::delim, CopyToStateData::file_encoding, CopyFormatOptions::header_line, lfirst_int, NameStr, CopyToStateData::need_transcoding, CopyFormatOptions::null_print, CopyFormatOptions::null_print_client, CopyFormatOptions::null_print_len, CopyToStateData::opts, pg_server_to_any(), and TupleDescAttr().
|
static |
Definition at line 245 of file copyto.c.
References CopyToTextLikeOneRow().
DestReceiver * CreateCopyDestReceiver | ( | void | ) |
Definition at line 1433 of file copyto.c.
References copy_dest_destroy(), copy_dest_receive(), copy_dest_shutdown(), copy_dest_startup(), DR_copy::cstate, DestCopyOut, _DestReceiver::mydest, palloc(), DR_copy::processed, DR_copy::pub, _DestReceiver::rDestroy, _DestReceiver::receiveSlot, _DestReceiver::rShutdown, and _DestReceiver::rStartup.
Referenced by CreateDestReceiver().
uint64 DoCopyTo | ( | CopyToState | cstate | ) |
Definition at line 1024 of file copyto.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, attnum, CopyToStateData::attnumlist, CHECK_FOR_INTERRUPTS, CopyOneRowTo(), CopyToRoutine::CopyToEnd, CopyToRoutine::CopyToOutFunc, CopyToRoutine::CopyToStart, cur, CurrentMemoryContext, CopyToStateData::data_dest_cb, QueryDesc::dest, DestRemote, ExecDropSingleTupleTableSlot(), ExecutorRun(), CopyToStateData::fe_msgbuf, CopyToStateData::filename, ForwardScanDirection, GetActiveSnapshot(), lfirst_int, makeStringInfo(), MemoryContextDelete(), TupleDescData::natts, CopyFormatOptions::null_print, CopyFormatOptions::null_print_client, CopyToStateData::opts, CopyToStateData::out_functions, palloc(), pgstat_progress_update_param(), PROGRESS_COPY_TUPLES_PROCESSED, CopyToStateData::queryDesc, CopyToStateData::rel, RelationGetDescr, CopyToStateData::routine, CopyToStateData::rowcontext, SendCopyBegin(), SendCopyEnd(), slot_getallattrs(), table_beginscan(), table_endscan(), table_scan_getnextslot(), table_slot_create(), QueryDesc::tupDesc, TupleDescAttr(), and whereToSendOutput.
Referenced by DoCopy(), and test_copy_to_callback().
|
static |
Definition at line 587 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 1003 of file copyto.c.
References EndCopy(), ExecutorEnd(), ExecutorFinish(), FreeQueryDesc(), PopActiveSnapshot(), and CopyToStateData::queryDesc.
Referenced by DoCopy(), and test_copy_to_callback().
|
static |
Definition at line 391 of file copyto.c.
References CopyToStateData::attnumlist, CopyFormatOptions::binary, buf, CopyToStateData::copy_dest, COPY_FRONTEND, format, i, list_length(), CopyToStateData::opts, pq_beginmessage(), pq_endmessage(), pq_sendbyte(), pq_sendint16(), and PqMsg_CopyOutResponse.
Referenced by DoCopyTo().
|
static |
Definition at line 408 of file copyto.c.
References Assert(), CopyToStateData::fe_msgbuf, StringInfoData::len, pq_putemptymessage(), and PqMsg_CopyDone.
Referenced by DoCopyTo().
|
static |
Definition at line 109 of file copyto.c.
Referenced by CopyToBinaryStart().
|
static |
Definition at line 168 of file copyto.c.
Referenced by CopyToGetRoutine().
|
static |
Definition at line 160 of file copyto.c.
Referenced by CopyToGetRoutine().
|
static |
Definition at line 152 of file copyto.c.
Referenced by CopyToGetRoutine().