70 {
"filename", ForeignTableRelationId},
71 {
"program", ForeignTableRelationId},
75 {
"format", ForeignTableRelationId},
76 {
"header", ForeignTableRelationId},
77 {
"delimiter", ForeignTableRelationId},
78 {
"quote", ForeignTableRelationId},
79 {
"escape", ForeignTableRelationId},
80 {
"null", ForeignTableRelationId},
81 {
"default", ForeignTableRelationId},
82 {
"encoding", ForeignTableRelationId},
83 {
"on_error", ForeignTableRelationId},
84 {
"log_verbosity", ForeignTableRelationId},
85 {
"reject_limit", ForeignTableRelationId},
86 {
"force_not_null", AttributeRelationId},
87 {
"force_null", AttributeRelationId},
162 List **other_options);
171 Cost *startup_cost,
Cost *total_cost);
174 double *totalrows,
double *totaldeadrows);
212 DefElem *force_not_null = NULL;
221 foreach(cell, options_list)
228 const char *closest_match;
230 bool has_valid_options =
false;
241 has_valid_options =
true;
248 (
errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
250 has_valid_options ? closest_match ?
251 errhint(
"Perhaps you meant the option \"%s\".",
253 errhint(
"There are no valid options in this context.")));
260 if (strcmp(def->
defname,
"filename") == 0 ||
261 strcmp(def->
defname,
"program") == 0)
265 (
errcode(ERRCODE_SYNTAX_ERROR),
266 errmsg(
"conflicting or redundant options")));
287 if (strcmp(def->
defname,
"filename") == 0 &&
290 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
291 errmsg(
"permission denied to set the \"%s\" option of a file_fdw foreign table",
293 errdetail(
"Only roles with privileges of the \"%s\" role may set this option.",
294 "pg_read_server_files")));
296 if (strcmp(def->
defname,
"program") == 0 &&
299 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
300 errmsg(
"permission denied to set the \"%s\" option of a file_fdw foreign table",
302 errdetail(
"Only roles with privileges of the \"%s\" role may set this option.",
303 "pg_execute_server_program")));
312 else if (strcmp(def->
defname,
"force_not_null") == 0)
316 (
errcode(ERRCODE_SYNTAX_ERROR),
317 errmsg(
"conflicting or redundant options"),
318 errhint(
"Option \"force_not_null\" supplied more than once for a column.")));
319 force_not_null = def;
324 else if (strcmp(def->
defname,
"force_null") == 0)
328 (
errcode(ERRCODE_SYNTAX_ERROR),
329 errmsg(
"conflicting or redundant options"),
330 errhint(
"Option \"force_null\" supplied more than once for a column.")));
335 other_options =
lappend(other_options, def);
347 if (catalog == ForeignTableRelationId &&
filename == NULL)
349 (
errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
350 errmsg(
"either filename or program is required for file_fdw foreign tables")));
380 char **
filename,
bool *is_program,
List **other_options)
416 if (strcmp(def->
defname,
"filename") == 0)
422 else if (strcmp(def->
defname,
"program") == 0)
436 elog(
ERROR,
"either filename or program is required for file_fdw foreign tables");
463 natts = tupleDesc->
natts;
469 List *column_options;
473 if (attr->attisdropped)
477 foreach(lc, column_options)
481 if (strcmp(def->
defname,
"force_not_null") == 0)
490 else if (strcmp(def->
defname,
"force_null") == 0)
509 if (fnncolumns !=
NIL)
512 if (fncolumns !=
NIL)
539 baserel->fdw_private = fdw_private;
569 (
Node *) columns, -1));
573 &startup_cost, &total_cost);
662 struct stat stat_buf;
717 festate->is_program = is_program;
719 festate->cstate = cstate;
742 errcallback.
arg = cstate;
800 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
801 errmsg(
"skipped more than REJECT_LIMIT (%" PRId64
") rows due to data type incompatibility",
858 errmsg_plural(
"%" PRIu64
" row was skipped due to data type incompatibility",
859 "%" PRIu64
" rows were skipped due to data type incompatibility",
878 struct stat stat_buf;
900 errmsg(
"could not stat file \"%s\": %m",
907 *totalpages = (stat_buf.
st_size + (BLCKSZ - 1)) / BLCKSZ;
948 bool has_wholerow =
false;
958 foreach(lc,
table->options)
962 if (strcmp(def->
defname,
"format") == 0)
966 if (strcmp(
format,
"binary") == 0)
1012 if (attr->attisdropped)
1019 if (attr->attgenerated)
1027 for (
i = 0;
i < tupleDesc->
natts;
i++)
1031 if (attr->attisdropped)
1066 struct stat stat_buf;
1077 stat_buf.
st_size = 10 * BLCKSZ;
1082 pages = (stat_buf.
st_size + (BLCKSZ - 1)) / BLCKSZ;
1085 fdw_private->
pages = pages;
1099 density = baserel->
tuples / (double) baserel->
pages;
1117 (
double) tuple_width);
1119 fdw_private->
ntuples = ntuples;
1135 baserel->
rows = nrows;
1146 Cost *startup_cost,
Cost *total_cost)
1149 double ntuples = fdw_private->
ntuples;
1168 run_cost += cpu_per_tuple * ntuples;
1169 *total_cost = *startup_cost + run_cost;
1190 double *totalrows,
double *totaldeadrows)
1193 double rowstoskip = -1;
1212 nulls = (
bool *)
palloc(tupDesc->
natts *
sizeof(
bool));
1228 "file_fdw temporary context",
1236 errcallback.
arg = cstate;
1279 if (numrows < targrows)
1293 if (rowstoskip <= 0)
1301 Assert(k >= 0 && k < targrows);
1322 errmsg_plural(
"%" PRIu64
" row was skipped due to data type incompatibility",
1323 "%" PRIu64
" rows were skipped due to data type incompatibility",
1336 (
errmsg(
"\"%s\": file contains %.0f rows; "
1337 "%d rows in sample",
1339 *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]
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
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[]
PG_MODULE_MAGIC_EXT(.name="file_fdw",.version=PG_VERSION)
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)
Assert(PointerIsAligned(start, uint64))
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)
static const struct lconv_member_info table[]
#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)