64 {
"filename", ForeignTableRelationId},
65 {
"program", ForeignTableRelationId},
69 {
"format", ForeignTableRelationId},
70 {
"header", ForeignTableRelationId},
71 {
"delimiter", ForeignTableRelationId},
72 {
"quote", ForeignTableRelationId},
73 {
"escape", ForeignTableRelationId},
74 {
"null", ForeignTableRelationId},
75 {
"default", ForeignTableRelationId},
76 {
"encoding", ForeignTableRelationId},
77 {
"force_not_null", AttributeRelationId},
78 {
"force_null", AttributeRelationId},
153 List **other_options);
162 Cost *startup_cost,
Cost *total_cost);
165 double *totalrows,
double *totaldeadrows);
203 DefElem *force_not_null = NULL;
212 foreach(cell, options_list)
219 const char *closest_match;
221 bool has_valid_options =
false;
232 has_valid_options =
true;
239 (
errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
241 has_valid_options ? closest_match ?
242 errhint(
"Perhaps you meant the option \"%s\".",
244 errhint(
"There are no valid options in this context.")));
251 if (strcmp(def->
defname,
"filename") == 0 ||
252 strcmp(def->
defname,
"program") == 0)
256 (
errcode(ERRCODE_SYNTAX_ERROR),
257 errmsg(
"conflicting or redundant options")));
278 if (strcmp(def->
defname,
"filename") == 0 &&
281 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
282 errmsg(
"permission denied to set the \"%s\" option of a file_fdw foreign table",
284 errdetail(
"Only roles with privileges of the \"%s\" role may set this option.",
285 "pg_read_server_files")));
287 if (strcmp(def->
defname,
"program") == 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_execute_server_program")));
303 else if (strcmp(def->
defname,
"force_not_null") == 0)
307 (
errcode(ERRCODE_SYNTAX_ERROR),
308 errmsg(
"conflicting or redundant options"),
309 errhint(
"Option \"force_not_null\" supplied more than once for a column.")));
310 force_not_null = def;
315 else if (strcmp(def->
defname,
"force_null") == 0)
319 (
errcode(ERRCODE_SYNTAX_ERROR),
320 errmsg(
"conflicting or redundant options"),
321 errhint(
"Option \"force_null\" supplied more than once for a column.")));
326 other_options =
lappend(other_options, def);
338 if (catalog == ForeignTableRelationId &&
filename == NULL)
340 (
errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
341 errmsg(
"either filename or program is required for file_fdw foreign tables")));
371 char **
filename,
bool *is_program,
List **other_options)
407 if (strcmp(def->
defname,
"filename") == 0)
413 else if (strcmp(def->
defname,
"program") == 0)
427 elog(
ERROR,
"either filename or program is required for file_fdw foreign tables");
454 natts = tupleDesc->
natts;
460 List *column_options;
464 if (attr->attisdropped)
468 foreach(lc, column_options)
472 if (strcmp(def->
defname,
"force_not_null") == 0)
481 else if (strcmp(def->
defname,
"force_null") == 0)
500 if (fnncolumns !=
NIL)
503 if (fncolumns !=
NIL)
530 baserel->fdw_private = (
void *) fdw_private;
560 (
Node *) columns, -1));
564 &startup_cost, &total_cost);
652 struct stat stat_buf;
707 festate->is_program = is_program;
709 festate->cstate = cstate;
732 errcallback.
arg = (
void *) festate->
cstate;
814 struct stat stat_buf;
836 errmsg(
"could not stat file \"%s\": %m",
843 *totalpages = (stat_buf.
st_size + (BLCKSZ - 1)) / BLCKSZ;
884 bool has_wholerow =
false;
898 if (strcmp(def->
defname,
"format") == 0)
902 if (strcmp(
format,
"binary") == 0)
948 if (attr->attisdropped)
955 if (attr->attgenerated)
963 for (
i = 0;
i < tupleDesc->
natts;
i++)
967 if (attr->attisdropped)
1002 struct stat stat_buf;
1013 stat_buf.
st_size = 10 * BLCKSZ;
1018 pages = (stat_buf.
st_size + (BLCKSZ - 1)) / BLCKSZ;
1021 fdw_private->
pages = pages;
1035 density = baserel->
tuples / (double) baserel->
pages;
1053 (
double) tuple_width);
1055 fdw_private->
ntuples = ntuples;
1071 baserel->
rows = nrows;
1082 Cost *startup_cost,
Cost *total_cost)
1085 double ntuples = fdw_private->
ntuples;
1104 run_cost += cpu_per_tuple * ntuples;
1105 *total_cost = *startup_cost + run_cost;
1125 double *totalrows,
double *totaldeadrows)
1128 double rowstoskip = -1;
1147 nulls = (
bool *)
palloc(tupDesc->
natts *
sizeof(
bool));
1163 "file_fdw temporary context",
1171 errcallback.
arg = (
void *) cstate;
1199 if (numrows < targrows)
1213 if (rowstoskip <= 0)
1221 Assert(k >= 0 && k < targrows);
1247 (
errmsg(
"\"%s\": file contains %.0f rows; "
1248 "%d rows in sample",
1250 *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)
elog(ERROR, "%s: %s", p2, msg)
bool defGetBoolean(DefElem *def)
char * defGetString(DefElem *def)
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 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, Datum *values, bool *isnull)
void heap_freetuple(HeapTuple htup)
#define SizeofHeapTupleHeader
struct parser_state match_state[5]
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
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
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
ForeignPath * create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, 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, 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)
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)