65 {
"filename", ForeignTableRelationId},
66 {
"program", ForeignTableRelationId},
70 {
"format", ForeignTableRelationId},
71 {
"header", ForeignTableRelationId},
72 {
"delimiter", ForeignTableRelationId},
73 {
"quote", ForeignTableRelationId},
74 {
"escape", ForeignTableRelationId},
75 {
"null", ForeignTableRelationId},
76 {
"default", ForeignTableRelationId},
77 {
"encoding", ForeignTableRelationId},
78 {
"on_error", ForeignTableRelationId},
79 {
"log_verbosity", ForeignTableRelationId},
80 {
"reject_limit", ForeignTableRelationId},
81 {
"force_not_null", AttributeRelationId},
82 {
"force_null", AttributeRelationId},
157 List **other_options);
166 Cost *startup_cost,
Cost *total_cost);
169 double *totalrows,
double *totaldeadrows);
207 DefElem *force_not_null = NULL;
216 foreach(cell, options_list)
223 const char *closest_match;
225 bool has_valid_options =
false;
236 has_valid_options =
true;
243 (
errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
245 has_valid_options ? closest_match ?
246 errhint(
"Perhaps you meant the option \"%s\".",
248 errhint(
"There are no valid options in this context.")));
255 if (strcmp(def->
defname,
"filename") == 0 ||
256 strcmp(def->
defname,
"program") == 0)
260 (
errcode(ERRCODE_SYNTAX_ERROR),
261 errmsg(
"conflicting or redundant options")));
282 if (strcmp(def->
defname,
"filename") == 0 &&
285 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
286 errmsg(
"permission denied to set the \"%s\" option of a file_fdw foreign table",
288 errdetail(
"Only roles with privileges of the \"%s\" role may set this option.",
289 "pg_read_server_files")));
291 if (strcmp(def->
defname,
"program") == 0 &&
294 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
295 errmsg(
"permission denied to set the \"%s\" option of a file_fdw foreign table",
297 errdetail(
"Only roles with privileges of the \"%s\" role may set this option.",
298 "pg_execute_server_program")));
307 else if (strcmp(def->
defname,
"force_not_null") == 0)
311 (
errcode(ERRCODE_SYNTAX_ERROR),
312 errmsg(
"conflicting or redundant options"),
313 errhint(
"Option \"force_not_null\" supplied more than once for a column.")));
314 force_not_null = def;
319 else if (strcmp(def->
defname,
"force_null") == 0)
323 (
errcode(ERRCODE_SYNTAX_ERROR),
324 errmsg(
"conflicting or redundant options"),
325 errhint(
"Option \"force_null\" supplied more than once for a column.")));
330 other_options =
lappend(other_options, def);
342 if (catalog == ForeignTableRelationId &&
filename == NULL)
344 (
errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
345 errmsg(
"either filename or program is required for file_fdw foreign tables")));
375 char **
filename,
bool *is_program,
List **other_options)
411 if (strcmp(def->
defname,
"filename") == 0)
417 else if (strcmp(def->
defname,
"program") == 0)
431 elog(
ERROR,
"either filename or program is required for file_fdw foreign tables");
458 natts = tupleDesc->
natts;
464 List *column_options;
468 if (attr->attisdropped)
472 foreach(lc, column_options)
476 if (strcmp(def->
defname,
"force_not_null") == 0)
485 else if (strcmp(def->
defname,
"force_null") == 0)
504 if (fnncolumns !=
NIL)
507 if (fncolumns !=
NIL)
534 baserel->fdw_private = fdw_private;
564 (
Node *) columns, -1));
568 &startup_cost, &total_cost);
657 struct stat stat_buf;
712 festate->is_program = is_program;
714 festate->cstate = cstate;
737 errcallback.
arg = cstate;
795 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
796 errmsg(
"skipped more than REJECT_LIMIT (%lld) rows due to data type incompatibility",
853 errmsg_plural(
"%llu row was skipped due to data type incompatibility",
854 "%llu rows were skipped due to data type incompatibility",
873 struct stat stat_buf;
895 errmsg(
"could not stat file \"%s\": %m",
902 *totalpages = (stat_buf.
st_size + (BLCKSZ - 1)) / BLCKSZ;
943 bool has_wholerow =
false;
957 if (strcmp(def->
defname,
"format") == 0)
961 if (strcmp(
format,
"binary") == 0)
1007 if (attr->attisdropped)
1014 if (attr->attgenerated)
1022 for (
i = 0;
i < tupleDesc->
natts;
i++)
1026 if (attr->attisdropped)
1061 struct stat stat_buf;
1072 stat_buf.
st_size = 10 * BLCKSZ;
1077 pages = (stat_buf.
st_size + (BLCKSZ - 1)) / BLCKSZ;
1080 fdw_private->
pages = pages;
1094 density = baserel->
tuples / (double) baserel->
pages;
1112 (
double) tuple_width);
1114 fdw_private->
ntuples = ntuples;
1130 baserel->
rows = nrows;
1141 Cost *startup_cost,
Cost *total_cost)
1144 double ntuples = fdw_private->
ntuples;
1163 run_cost += cpu_per_tuple * ntuples;
1164 *total_cost = *startup_cost + run_cost;
1185 double *totalrows,
double *totaldeadrows)
1188 double rowstoskip = -1;
1207 nulls = (
bool *)
palloc(tupDesc->
natts *
sizeof(
bool));
1223 "file_fdw temporary context",
1231 errcallback.
arg = cstate;
1274 if (numrows < targrows)
1288 if (rowstoskip <= 0)
1296 Assert(k >= 0 && k < targrows);
1317 errmsg_plural(
"%llu row was skipped due to data type incompatibility",
1318 "%llu rows were skipped due to data type incompatibility",
1331 (
errmsg(
"\"%s\": file contains %.0f rows; "
1332 "%d rows in sample",
1334 *totalrows, numrows)));
bool has_privs_of_role(Oid member, Oid role)
void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options)
int bms_next_member(const Bitmapset *a, int prevbit)
static Datum values[MAXATTR]
#define Assert(condition)
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
CopyFromState BeginCopyFrom(ParseState *pstate, Relation rel, Node *whereClause, const char *filename, bool is_program, copy_data_source_cb data_source_cb, List *attnamelist, List *options)
void EndCopyFrom(CopyFromState cstate)
void CopyFromErrorCallback(void *arg)
bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
double clamp_row_est(double nrows)
ForeignScan * make_foreignscan(List *qptlist, List *qpqual, Index scanrelid, List *fdw_exprs, List *fdw_private, List *fdw_scan_tlist, List *fdw_recheck_quals, Plan *outer_plan)
char * defGetString(DefElem *def)
bool defGetBoolean(DefElem *def)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errcode_for_file_access(void)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
EState * CreateExecutorState(void)
#define ResetPerTupleExprContext(estate)
#define GetPerTupleExprContext(estate)
#define GetPerTupleMemoryContext(estate)
#define EXEC_FLAG_EXPLAIN_ONLY
void ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es)
void ExplainPropertyInteger(const char *qlabel, const char *unit, int64 value, ExplainState *es)
int(* AcquireSampleRowsFunc)(Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
static ForeignScan * fileGetForeignPlan(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid, ForeignPath *best_path, List *tlist, List *scan_clauses, Plan *outer_plan)
static void fileEndForeignScan(ForeignScanState *node)
Datum file_fdw_handler(PG_FUNCTION_ARGS)
static bool check_selective_binary_conversion(RelOptInfo *baserel, Oid foreigntableid, List **columns)
static void fileGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
static void fileExplainForeignScan(ForeignScanState *node, ExplainState *es)
static List * get_file_fdw_attribute_options(Oid relid)
Datum file_fdw_validator(PG_FUNCTION_ARGS)
static void estimate_costs(PlannerInfo *root, RelOptInfo *baserel, FileFdwPlanState *fdw_private, Cost *startup_cost, Cost *total_cost)
static int file_acquire_sample_rows(Relation onerel, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
PG_FUNCTION_INFO_V1(file_fdw_handler)
static const struct FileFdwOption valid_options[]
static bool fileAnalyzeForeignTable(Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages)
static void fileReScanForeignScan(ForeignScanState *node)
struct FileFdwExecutionState FileFdwExecutionState
static bool is_valid_option(const char *option, Oid context)
static bool fileIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
static void fileGetForeignPaths(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
static void fileGetOptions(Oid foreigntableid, char **filename, bool *is_program, List **other_options)
static void estimate_size(PlannerInfo *root, RelOptInfo *baserel, FileFdwPlanState *fdw_private)
static void fileBeginForeignScan(ForeignScanState *node, int eflags)
static TupleTableSlot * fileIterateForeignScan(ForeignScanState *node)
struct FileFdwPlanState FileFdwPlanState
#define PG_GETARG_DATUM(n)
#define PG_RETURN_POINTER(x)
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
ForeignTable * GetForeignTable(Oid relid)
ForeignServer * GetForeignServer(Oid serverid)
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define SizeofHeapTupleHeader
@ COPY_LOG_VERBOSITY_DEFAULT
struct parser_state match_state[5]
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
DefElem * makeDefElem(char *name, Node *arg, int location)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CHECK_FOR_INTERRUPTS()
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
ForeignPath * create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, int disabled_nodes, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_restrictinfo, List *fdw_private)
void add_path(RelOptInfo *parent_rel, Path *new_path)
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
#define foreach_delete_current(lst, var_or_cell)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
List * untransformRelOptions(Datum options)
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
void reservoir_init_selection_state(ReservoirState rs, int n)
double sampler_random_fract(pg_prng_state *randstate)
double reservoir_get_next_S(ReservoirState rs, double t, int n)
ErrorSaveContext * escontext
struct ErrorContextCallback * previous
void(* callback)(void *arg)
ReScanForeignScan_function ReScanForeignScan
BeginForeignScan_function BeginForeignScan
IsForeignScanParallelSafe_function IsForeignScanParallelSafe
GetForeignPaths_function GetForeignPaths
GetForeignRelSize_function GetForeignRelSize
ExplainForeignScan_function ExplainForeignScan
EndForeignScan_function EndForeignScan
AnalyzeForeignTable_function AnalyzeForeignTable
IterateForeignScan_function IterateForeignScan
GetForeignPlan_function GetForeignPlan
struct PathTarget * reltarget
QualCost baserestrictcost
Relation ss_currentRelation
TupleTableSlot * ss_ScanTupleSlot
#define FirstLowInvalidHeapAttributeNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
void vacuum_delay_point(bool is_analyze)
String * makeString(char *str)
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
const char * getClosestMatch(ClosestMatchState *state)
void initClosestMatch(ClosestMatchState *state, const char *source, int max_d)
void updateClosestMatch(ClosestMatchState *state, const char *candidate)