* file_fdw.c
* foreign-data wrapper for server-side flat files.
*
- * Copyright (c) 2010-2015, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2016, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/file_fdw/file_fdw.c
Oid foreigntableid,
ForeignPath *best_path,
List *tlist,
- List *scan_clauses);
+ List *scan_clauses,
+ Plan *outer_plan);
static void fileExplainForeignScan(ForeignScanState *node, ExplainState *es);
static void fileBeginForeignScan(ForeignScanState *node, int eflags);
static TupleTableSlot *fileIterateForeignScan(ForeignScanState *node);
static bool fileAnalyzeForeignTable(Relation relation,
AcquireSampleRowsFunc *func,
BlockNumber *totalpages);
+static bool fileIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel,
+ RangeTblEntry *rte);
/*
* Helper functions
fdwroutine->ReScanForeignScan = fileReScanForeignScan;
fdwroutine->EndForeignScan = fileEndForeignScan;
fdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;
+ fdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;
PG_RETURN_POINTER(fdwroutine);
}
*/
add_path(baserel, (Path *)
create_foreignscan_path(root, baserel,
+ NULL, /* default pathtarget */
baserel->rows,
startup_cost,
total_cost,
NIL, /* no pathkeys */
NULL, /* no outer rel either */
+ NULL, /* no extra plan */
coptions));
/*
Oid foreigntableid,
ForeignPath *best_path,
List *tlist,
- List *scan_clauses)
+ List *scan_clauses,
+ Plan *outer_plan)
{
Index scan_relid = baserel->relid;
scan_relid,
NIL, /* no expressions to evaluate */
best_path->fdw_private,
- NIL /* no custom tlist */ );
+ NIL, /* no custom tlist */
+ NIL, /* no remote quals */
+ outer_plan);
}
/*
return true;
}
+/*
+ * fileIsForeignScanParallelSafe
+ * Reading a file in a parallel worker should work just the same as
+ * reading it in the leader, so mark scans safe.
+ */
+static bool
+fileIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel,
+ RangeTblEntry *rte)
+{
+ return true;
+}
+
/*
* check_selective_binary_conversion
*
}
/* Collect all the attributes needed for joins or final output. */
- pull_varattnos((Node *) baserel->reltargetlist, baserel->relid,
+ pull_varattnos((Node *) baserel->reltarget->exprs, baserel->relid,
&attrs_used);
/* Add all the attributes used by restriction clauses. */
*/
int tuple_width;
- tuple_width = MAXALIGN(baserel->width) +
+ tuple_width = MAXALIGN(baserel->reltarget->width) +
MAXALIGN(SizeofHeapTupleHeader);
ntuples = clamp_row_est((double) stat_buf.st_size /
(double) tuple_width);
*/
tupcontext = AllocSetContextCreate(CurrentMemoryContext,
"file_fdw temporary context",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
/* Prepare for sampling rows */
reservoir_init_selection_state(&rstate, targrows);
* Found a suitable tuple, so save it, replacing one old tuple
* at random
*/
- int k = (int) (targrows * sampler_random_fract());
+ int k = (int) (targrows * sampler_random_fract(rstate.randstate));
Assert(k >= 0 && k < targrows);
heap_freetuple(rows[k]);