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 {
"force_not_null", AttributeRelationId},
81 {
"force_null", AttributeRelationId},
156 List **other_options);
165 Cost *startup_cost,
Cost *total_cost);
168 double *totalrows,
double *totaldeadrows);
206 DefElem *force_not_null = NULL;
215 foreach(cell, options_list)
222 const char *closest_match;
224 bool has_valid_options =
false;
235 has_valid_options =
true;
242 (
errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
244 has_valid_options ? closest_match ?
245 errhint(
"Perhaps you meant the option \"%s\".",
247 errhint(
"There are no valid options in this context.")));
254 if (strcmp(def->
defname,
"filename") == 0 ||
255 strcmp(def->
defname,
"program") == 0)
259 (
errcode(ERRCODE_SYNTAX_ERROR),
260 errmsg(
"conflicting or redundant options")));
281 if (strcmp(def->
defname,
"filename") == 0 &&
284 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
285 errmsg(
"permission denied to set the \"%s\" option of a file_fdw foreign table",
287 errdetail(
"Only roles with privileges of the \"%s\" role may set this option.",
288 "pg_read_server_files")));
290 if (strcmp(def->
defname,
"program") == 0 &&
293 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
294 errmsg(
"permission denied to set the \"%s\" option of a file_fdw foreign table",
296 errdetail(
"Only roles with privileges of the \"%s\" role may set this option.",
297 "pg_execute_server_program")));
306 else if (strcmp(def->
defname,
"force_not_null") == 0)
310 (
errcode(ERRCODE_SYNTAX_ERROR),
311 errmsg(
"conflicting or redundant options"),
312 errhint(
"Option \"force_not_null\" supplied more than once for a column.")));
313 force_not_null = def;
318 else if (strcmp(def->
defname,
"force_null") == 0)
322 (
errcode(ERRCODE_SYNTAX_ERROR),
323 errmsg(
"conflicting or redundant options"),
324 errhint(
"Option \"force_null\" supplied more than once for a column.")));
329 other_options =
lappend(other_options, def);
341 if (catalog == ForeignTableRelationId &&
filename == NULL)
343 (
errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
344 errmsg(
"either filename or program is required for file_fdw foreign tables")));
374 char **
filename,
bool *is_program,
List **other_options)
410 if (strcmp(def->
defname,
"filename") == 0)
416 else if (strcmp(def->
defname,
"program") == 0)
430 elog(
ERROR,
"either filename or program is required for file_fdw foreign tables");
457 natts = tupleDesc->
natts;
463 List *column_options;
467 if (attr->attisdropped)
471 foreach(lc, column_options)
475 if (strcmp(def->
defname,
"force_not_null") == 0)
484 else if (strcmp(def->
defname,
"force_null") == 0)
503 if (fnncolumns !=
NIL)
506 if (fncolumns !=
NIL)
533 baserel->fdw_private = (
void *) fdw_private;
563 (
Node *) columns, -1));
567 &startup_cost, &total_cost);
656 struct stat stat_buf;
711 festate->is_program = is_program;
713 festate->cstate = cstate;
736 errcallback.
arg = (
void *) cstate;
845 errmsg_plural(
"%llu row was skipped due to data type incompatibility",
846 "%llu rows were skipped due to data type incompatibility",
865 struct stat stat_buf;
887 errmsg(
"could not stat file \"%s\": %m",
894 *totalpages = (stat_buf.
st_size + (BLCKSZ - 1)) / BLCKSZ;
935 bool has_wholerow =
false;
949 if (strcmp(def->
defname,
"format") == 0)
953 if (strcmp(
format,
"binary") == 0)
999 if (attr->attisdropped)
1006 if (attr->attgenerated)
1014 for (
i = 0;
i < tupleDesc->
natts;
i++)
1018 if (attr->attisdropped)
1053 struct stat stat_buf;
1064 stat_buf.
st_size = 10 * BLCKSZ;
1069 pages = (stat_buf.
st_size + (BLCKSZ - 1)) / BLCKSZ;
1072 fdw_private->
pages = pages;
1086 density = baserel->
tuples / (double) baserel->
pages;
1104 (
double) tuple_width);
1106 fdw_private->
ntuples = ntuples;
1122 baserel->
rows = nrows;
1133 Cost *startup_cost,
Cost *total_cost)
1136 double ntuples = fdw_private->
ntuples;
1155 run_cost += cpu_per_tuple * ntuples;
1156 *total_cost = *startup_cost + run_cost;
1177 double *totalrows,
double *totaldeadrows)
1180 double rowstoskip = -1;
1199 nulls = (
bool *)
palloc(tupDesc->
natts *
sizeof(
bool));
1215 "file_fdw temporary context",
1223 errcallback.
arg = (
void *) cstate;
1266 if (numrows < targrows)
1280 if (rowstoskip <= 0)
1288 Assert(k >= 0 && k < targrows);
1309 errmsg_plural(
"%llu row was skipped due to data type incompatibility",
1310 "%llu rows were skipped due to data type incompatibility",
1323 (
errmsg(
"\"%s\": file contains %.0f rows; "
1324 "%d rows in sample",
1326 *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)
bool defGetBoolean(DefElem *def)
char * defGetString(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)
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
ForeignServer * GetForeignServer(Oid serverid)
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()
void add_path(RelOptInfo *parent_rel, Path *new_path)
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)
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
#define foreach_delete_current(lst, var_or_cell)
MemoryContextSwitchTo(old_ctx)
#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)
#define TupleDescAttr(tupdesc, i)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
void vacuum_delay_point(void)
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)