PostgreSQL Source Code  git master
file_fdw.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * file_fdw.c
4  * foreign-data wrapper for server-side flat files (or programs).
5  *
6  * Copyright (c) 2010-2022, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  * contrib/file_fdw/file_fdw.c
10  *
11  *-------------------------------------------------------------------------
12  */
13 #include "postgres.h"
14 
15 #include <sys/stat.h>
16 #include <unistd.h>
17 
18 #include "access/htup_details.h"
19 #include "access/reloptions.h"
20 #include "access/sysattr.h"
21 #include "access/table.h"
22 #include "catalog/pg_authid.h"
24 #include "commands/copy.h"
25 #include "commands/defrem.h"
26 #include "commands/explain.h"
27 #include "commands/vacuum.h"
28 #include "foreign/fdwapi.h"
29 #include "foreign/foreign.h"
30 #include "miscadmin.h"
31 #include "nodes/makefuncs.h"
32 #include "optimizer/optimizer.h"
33 #include "optimizer/pathnode.h"
34 #include "optimizer/planmain.h"
35 #include "optimizer/restrictinfo.h"
36 #include "utils/acl.h"
37 #include "utils/memutils.h"
38 #include "utils/rel.h"
39 #include "utils/sampling.h"
40 #include "utils/varlena.h"
41 
43 
44 /*
45  * Describes the valid options for objects that use this wrapper.
46  */
48 {
49  const char *optname;
50  Oid optcontext; /* Oid of catalog in which option may appear */
51 };
52 
53 /*
54  * Valid options for file_fdw.
55  * These options are based on the options for the COPY FROM command.
56  * But note that force_not_null and force_null are handled as boolean options
57  * attached to a column, not as table options.
58  *
59  * Note: If you are adding new option for user mapping, you need to modify
60  * fileGetOptions(), which currently doesn't bother to look at user mappings.
61  */
62 static const struct FileFdwOption valid_options[] = {
63  /* Data source options */
64  {"filename", ForeignTableRelationId},
65  {"program", ForeignTableRelationId},
66 
67  /* Format options */
68  /* oids option is not supported */
69  {"format", ForeignTableRelationId},
70  {"header", ForeignTableRelationId},
71  {"delimiter", ForeignTableRelationId},
72  {"quote", ForeignTableRelationId},
73  {"escape", ForeignTableRelationId},
74  {"null", ForeignTableRelationId},
75  {"encoding", ForeignTableRelationId},
76  {"force_not_null", AttributeRelationId},
77  {"force_null", AttributeRelationId},
78 
79  /*
80  * force_quote is not supported by file_fdw because it's for COPY TO.
81  */
82 
83  /* Sentinel */
84  {NULL, InvalidOid}
85 };
86 
87 /*
88  * FDW-specific information for RelOptInfo.fdw_private.
89  */
90 typedef struct FileFdwPlanState
91 {
92  char *filename; /* file or program to read from */
93  bool is_program; /* true if filename represents an OS command */
94  List *options; /* merged COPY options, excluding filename and
95  * is_program */
96  BlockNumber pages; /* estimate of file's physical size */
97  double ntuples; /* estimate of number of data rows */
99 
100 /*
101  * FDW-specific information for ForeignScanState.fdw_state.
102  */
103 typedef struct FileFdwExecutionState
104 {
105  char *filename; /* file or program to read from */
106  bool is_program; /* true if filename represents an OS command */
107  List *options; /* merged COPY options, excluding filename and
108  * is_program */
109  CopyFromState cstate; /* COPY execution state */
111 
112 /*
113  * SQL functions
114  */
117 
118 /*
119  * FDW callback routines
120  */
121 static void fileGetForeignRelSize(PlannerInfo *root,
122  RelOptInfo *baserel,
123  Oid foreigntableid);
124 static void fileGetForeignPaths(PlannerInfo *root,
125  RelOptInfo *baserel,
126  Oid foreigntableid);
128  RelOptInfo *baserel,
129  Oid foreigntableid,
130  ForeignPath *best_path,
131  List *tlist,
132  List *scan_clauses,
133  Plan *outer_plan);
135 static void fileBeginForeignScan(ForeignScanState *node, int eflags);
137 static void fileReScanForeignScan(ForeignScanState *node);
138 static void fileEndForeignScan(ForeignScanState *node);
139 static bool fileAnalyzeForeignTable(Relation relation,
140  AcquireSampleRowsFunc *func,
141  BlockNumber *totalpages);
143  RangeTblEntry *rte);
144 
145 /*
146  * Helper functions
147  */
148 static bool is_valid_option(const char *option, Oid context);
149 static void fileGetOptions(Oid foreigntableid,
150  char **filename,
151  bool *is_program,
152  List **other_options);
154 static bool check_selective_binary_conversion(RelOptInfo *baserel,
155  Oid foreigntableid,
156  List **columns);
157 static void estimate_size(PlannerInfo *root, RelOptInfo *baserel,
158  FileFdwPlanState *fdw_private);
159 static void estimate_costs(PlannerInfo *root, RelOptInfo *baserel,
160  FileFdwPlanState *fdw_private,
161  Cost *startup_cost, Cost *total_cost);
162 static int file_acquire_sample_rows(Relation onerel, int elevel,
163  HeapTuple *rows, int targrows,
164  double *totalrows, double *totaldeadrows);
165 
166 
167 /*
168  * Foreign-data wrapper handler function: return a struct with pointers
169  * to my callback routines.
170  */
171 Datum
173 {
174  FdwRoutine *fdwroutine = makeNode(FdwRoutine);
175 
177  fdwroutine->GetForeignPaths = fileGetForeignPaths;
178  fdwroutine->GetForeignPlan = fileGetForeignPlan;
183  fdwroutine->EndForeignScan = fileEndForeignScan;
186 
187  PG_RETURN_POINTER(fdwroutine);
188 }
189 
190 /*
191  * Validate the generic options given to a FOREIGN DATA WRAPPER, SERVER,
192  * USER MAPPING or FOREIGN TABLE that uses file_fdw.
193  *
194  * Raise an ERROR if the option or its value is considered invalid.
195  */
196 Datum
198 {
199  List *options_list = untransformRelOptions(PG_GETARG_DATUM(0));
200  Oid catalog = PG_GETARG_OID(1);
201  char *filename = NULL;
202  DefElem *force_not_null = NULL;
203  DefElem *force_null = NULL;
204  List *other_options = NIL;
205  ListCell *cell;
206 
207  /*
208  * Check that only options supported by file_fdw, and allowed for the
209  * current object type, are given.
210  */
211  foreach(cell, options_list)
212  {
213  DefElem *def = (DefElem *) lfirst(cell);
214 
215  if (!is_valid_option(def->defname, catalog))
216  {
217  const struct FileFdwOption *opt;
218  const char *closest_match;
219  ClosestMatchState match_state;
220  bool has_valid_options = false;
221 
222  /*
223  * Unknown option specified, complain about it. Provide a hint
224  * with a valid option that looks similar, if there is one.
225  */
226  initClosestMatch(&match_state, def->defname, 4);
227  for (opt = valid_options; opt->optname; opt++)
228  {
229  if (catalog == opt->optcontext)
230  {
231  has_valid_options = true;
232  updateClosestMatch(&match_state, opt->optname);
233  }
234  }
235 
236  closest_match = getClosestMatch(&match_state);
237  ereport(ERROR,
238  (errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
239  errmsg("invalid option \"%s\"", def->defname),
240  has_valid_options ? closest_match ?
241  errhint("Perhaps you meant the option \"%s\".",
242  closest_match) : 0 :
243  errhint("There are no valid options in this context.")));
244  }
245 
246  /*
247  * Separate out filename, program, and column-specific options, since
248  * ProcessCopyOptions won't accept them.
249  */
250  if (strcmp(def->defname, "filename") == 0 ||
251  strcmp(def->defname, "program") == 0)
252  {
253  if (filename)
254  ereport(ERROR,
255  (errcode(ERRCODE_SYNTAX_ERROR),
256  errmsg("conflicting or redundant options")));
257 
258  /*
259  * Check permissions for changing which file or program is used by
260  * the file_fdw.
261  *
262  * Only members of the role 'pg_read_server_files' are allowed to
263  * set the 'filename' option of a file_fdw foreign table, while
264  * only members of the role 'pg_execute_server_program' are
265  * allowed to set the 'program' option. This is because we don't
266  * want regular users to be able to control which file gets read
267  * or which program gets executed.
268  *
269  * Putting this sort of permissions check in a validator is a bit
270  * of a crock, but there doesn't seem to be any other place that
271  * can enforce the check more cleanly.
272  *
273  * Note that the valid_options[] array disallows setting filename
274  * and program at any options level other than foreign table ---
275  * otherwise there'd still be a security hole.
276  */
277  if (strcmp(def->defname, "filename") == 0 &&
278  !has_privs_of_role(GetUserId(), ROLE_PG_READ_SERVER_FILES))
279  ereport(ERROR,
280  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
281  errmsg("only superuser or a role with privileges of the pg_read_server_files role may specify the filename option of a file_fdw foreign table")));
282 
283  if (strcmp(def->defname, "program") == 0 &&
284  !has_privs_of_role(GetUserId(), ROLE_PG_EXECUTE_SERVER_PROGRAM))
285  ereport(ERROR,
286  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
287  errmsg("only superuser or a role with privileges of the pg_execute_server_program role may specify the program option of a file_fdw foreign table")));
288 
289  filename = defGetString(def);
290  }
291 
292  /*
293  * force_not_null is a boolean option; after validation we can discard
294  * it - it will be retrieved later in get_file_fdw_attribute_options()
295  */
296  else if (strcmp(def->defname, "force_not_null") == 0)
297  {
298  if (force_not_null)
299  ereport(ERROR,
300  (errcode(ERRCODE_SYNTAX_ERROR),
301  errmsg("conflicting or redundant options"),
302  errhint("Option \"force_not_null\" supplied more than once for a column.")));
303  force_not_null = def;
304  /* Don't care what the value is, as long as it's a legal boolean */
305  (void) defGetBoolean(def);
306  }
307  /* See comments for force_not_null above */
308  else if (strcmp(def->defname, "force_null") == 0)
309  {
310  if (force_null)
311  ereport(ERROR,
312  (errcode(ERRCODE_SYNTAX_ERROR),
313  errmsg("conflicting or redundant options"),
314  errhint("Option \"force_null\" supplied more than once for a column.")));
315  force_null = def;
316  (void) defGetBoolean(def);
317  }
318  else
319  other_options = lappend(other_options, def);
320  }
321 
322  /*
323  * Now apply the core COPY code's validation logic for more checks.
324  */
325  ProcessCopyOptions(NULL, NULL, true, other_options);
326 
327  /*
328  * Either filename or program option is required for file_fdw foreign
329  * tables.
330  */
331  if (catalog == ForeignTableRelationId && filename == NULL)
332  ereport(ERROR,
333  (errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
334  errmsg("either filename or program is required for file_fdw foreign tables")));
335 
336  PG_RETURN_VOID();
337 }
338 
339 /*
340  * Check if the provided option is one of the valid options.
341  * context is the Oid of the catalog holding the object the option is for.
342  */
343 static bool
344 is_valid_option(const char *option, Oid context)
345 {
346  const struct FileFdwOption *opt;
347 
348  for (opt = valid_options; opt->optname; opt++)
349  {
350  if (context == opt->optcontext && strcmp(opt->optname, option) == 0)
351  return true;
352  }
353  return false;
354 }
355 
356 /*
357  * Fetch the options for a file_fdw foreign table.
358  *
359  * We have to separate out filename/program from the other options because
360  * those must not appear in the options list passed to the core COPY code.
361  */
362 static void
363 fileGetOptions(Oid foreigntableid,
364  char **filename, bool *is_program, List **other_options)
365 {
366  ForeignTable *table;
367  ForeignServer *server;
368  ForeignDataWrapper *wrapper;
369  List *options;
370  ListCell *lc;
371 
372  /*
373  * Extract options from FDW objects. We ignore user mappings because
374  * file_fdw doesn't have any options that can be specified there.
375  *
376  * (XXX Actually, given the current contents of valid_options[], there's
377  * no point in examining anything except the foreign table's own options.
378  * Simplify?)
379  */
380  table = GetForeignTable(foreigntableid);
381  server = GetForeignServer(table->serverid);
382  wrapper = GetForeignDataWrapper(server->fdwid);
383 
384  options = NIL;
385  options = list_concat(options, wrapper->options);
386  options = list_concat(options, server->options);
387  options = list_concat(options, table->options);
389 
390  /*
391  * Separate out the filename or program option (we assume there is only
392  * one).
393  */
394  *filename = NULL;
395  *is_program = false;
396  foreach(lc, options)
397  {
398  DefElem *def = (DefElem *) lfirst(lc);
399 
400  if (strcmp(def->defname, "filename") == 0)
401  {
402  *filename = defGetString(def);
404  break;
405  }
406  else if (strcmp(def->defname, "program") == 0)
407  {
408  *filename = defGetString(def);
409  *is_program = true;
411  break;
412  }
413  }
414 
415  /*
416  * The validator should have checked that filename or program was included
417  * in the options, but check again, just in case.
418  */
419  if (*filename == NULL)
420  elog(ERROR, "either filename or program is required for file_fdw foreign tables");
421 
422  *other_options = options;
423 }
424 
425 /*
426  * Retrieve per-column generic options from pg_attribute and construct a list
427  * of DefElems representing them.
428  *
429  * At the moment we only have "force_not_null", and "force_null",
430  * which should each be combined into a single DefElem listing all such
431  * columns, since that's what COPY expects.
432  */
433 static List *
435 {
436  Relation rel;
437  TupleDesc tupleDesc;
438  AttrNumber natts;
440  List *fnncolumns = NIL;
441  List *fncolumns = NIL;
442 
443  List *options = NIL;
444 
445  rel = table_open(relid, AccessShareLock);
446  tupleDesc = RelationGetDescr(rel);
447  natts = tupleDesc->natts;
448 
449  /* Retrieve FDW options for all user-defined attributes. */
450  for (attnum = 1; attnum <= natts; attnum++)
451  {
452  Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum - 1);
453  List *column_options;
454  ListCell *lc;
455 
456  /* Skip dropped attributes. */
457  if (attr->attisdropped)
458  continue;
459 
460  column_options = GetForeignColumnOptions(relid, attnum);
461  foreach(lc, column_options)
462  {
463  DefElem *def = (DefElem *) lfirst(lc);
464 
465  if (strcmp(def->defname, "force_not_null") == 0)
466  {
467  if (defGetBoolean(def))
468  {
469  char *attname = pstrdup(NameStr(attr->attname));
470 
471  fnncolumns = lappend(fnncolumns, makeString(attname));
472  }
473  }
474  else if (strcmp(def->defname, "force_null") == 0)
475  {
476  if (defGetBoolean(def))
477  {
478  char *attname = pstrdup(NameStr(attr->attname));
479 
480  fncolumns = lappend(fncolumns, makeString(attname));
481  }
482  }
483  /* maybe in future handle other column options here */
484  }
485  }
486 
488 
489  /*
490  * Return DefElem only when some column(s) have force_not_null /
491  * force_null options set
492  */
493  if (fnncolumns != NIL)
494  options = lappend(options, makeDefElem("force_not_null", (Node *) fnncolumns, -1));
495 
496  if (fncolumns != NIL)
497  options = lappend(options, makeDefElem("force_null", (Node *) fncolumns, -1));
498 
499  return options;
500 }
501 
502 /*
503  * fileGetForeignRelSize
504  * Obtain relation size estimates for a foreign table
505  */
506 static void
508  RelOptInfo *baserel,
509  Oid foreigntableid)
510 {
511  FileFdwPlanState *fdw_private;
512 
513  /*
514  * Fetch options. We only need filename (or program) at this point, but
515  * we might as well get everything and not need to re-fetch it later in
516  * planning.
517  */
518  fdw_private = (FileFdwPlanState *) palloc(sizeof(FileFdwPlanState));
519  fileGetOptions(foreigntableid,
520  &fdw_private->filename,
521  &fdw_private->is_program,
522  &fdw_private->options);
523  baserel->fdw_private = (void *) fdw_private;
524 
525  /* Estimate relation size */
526  estimate_size(root, baserel, fdw_private);
527 }
528 
529 /*
530  * fileGetForeignPaths
531  * Create possible access paths for a scan on the foreign table
532  *
533  * Currently we don't support any push-down feature, so there is only one
534  * possible access path, which simply returns all records in the order in
535  * the data file.
536  */
537 static void
539  RelOptInfo *baserel,
540  Oid foreigntableid)
541 {
542  FileFdwPlanState *fdw_private = (FileFdwPlanState *) baserel->fdw_private;
543  Cost startup_cost;
544  Cost total_cost;
545  List *columns;
546  List *coptions = NIL;
547 
548  /* Decide whether to selectively perform binary conversion */
550  foreigntableid,
551  &columns))
552  coptions = list_make1(makeDefElem("convert_selectively",
553  (Node *) columns, -1));
554 
555  /* Estimate costs */
556  estimate_costs(root, baserel, fdw_private,
557  &startup_cost, &total_cost);
558 
559  /*
560  * Create a ForeignPath node and add it as only possible path. We use the
561  * fdw_private list of the path to carry the convert_selectively option;
562  * it will be propagated into the fdw_private list of the Plan node.
563  *
564  * We don't support pushing join clauses into the quals of this path, but
565  * it could still have required parameterization due to LATERAL refs in
566  * its tlist.
567  */
568  add_path(baserel, (Path *)
569  create_foreignscan_path(root, baserel,
570  NULL, /* default pathtarget */
571  baserel->rows,
572  startup_cost,
573  total_cost,
574  NIL, /* no pathkeys */
575  baserel->lateral_relids,
576  NULL, /* no extra plan */
577  coptions));
578 
579  /*
580  * If data file was sorted, and we knew it somehow, we could insert
581  * appropriate pathkeys into the ForeignPath node to tell the planner
582  * that.
583  */
584 }
585 
586 /*
587  * fileGetForeignPlan
588  * Create a ForeignScan plan node for scanning the foreign table
589  */
590 static ForeignScan *
592  RelOptInfo *baserel,
593  Oid foreigntableid,
594  ForeignPath *best_path,
595  List *tlist,
596  List *scan_clauses,
597  Plan *outer_plan)
598 {
599  Index scan_relid = baserel->relid;
600 
601  /*
602  * We have no native ability to evaluate restriction clauses, so we just
603  * put all the scan_clauses into the plan node's qual list for the
604  * executor to check. So all we have to do here is strip RestrictInfo
605  * nodes from the clauses and ignore pseudoconstants (which will be
606  * handled elsewhere).
607  */
608  scan_clauses = extract_actual_clauses(scan_clauses, false);
609 
610  /* Create the ForeignScan node */
611  return make_foreignscan(tlist,
612  scan_clauses,
613  scan_relid,
614  NIL, /* no expressions to evaluate */
615  best_path->fdw_private,
616  NIL, /* no custom tlist */
617  NIL, /* no remote quals */
618  outer_plan);
619 }
620 
621 /*
622  * fileExplainForeignScan
623  * Produce extra output for EXPLAIN
624  */
625 static void
627 {
628  char *filename;
629  bool is_program;
630  List *options;
631 
632  /* Fetch options --- we only need filename and is_program at this point */
634  &filename, &is_program, &options);
635 
636  if (is_program)
637  ExplainPropertyText("Foreign Program", filename, es);
638  else
639  ExplainPropertyText("Foreign File", filename, es);
640 
641  /* Suppress file size if we're not showing cost details */
642  if (es->costs)
643  {
644  struct stat stat_buf;
645 
646  if (!is_program &&
647  stat(filename, &stat_buf) == 0)
648  ExplainPropertyInteger("Foreign File Size", "b",
649  (int64) stat_buf.st_size, es);
650  }
651 }
652 
653 /*
654  * fileBeginForeignScan
655  * Initiate access to the file by creating CopyState
656  */
657 static void
659 {
660  ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
661  char *filename;
662  bool is_program;
663  List *options;
664  CopyFromState cstate;
665  FileFdwExecutionState *festate;
666 
667  /*
668  * Do nothing in EXPLAIN (no ANALYZE) case. node->fdw_state stays NULL.
669  */
670  if (eflags & EXEC_FLAG_EXPLAIN_ONLY)
671  return;
672 
673  /* Fetch options of foreign table */
675  &filename, &is_program, &options);
676 
677  /* Add any options from the plan (currently only convert_selectively) */
679 
680  /*
681  * Create CopyState from FDW options. We always acquire all columns, so
682  * as to match the expected ScanTupleSlot signature.
683  */
684  cstate = BeginCopyFrom(NULL,
685  node->ss.ss_currentRelation,
686  NULL,
687  filename,
688  is_program,
689  NULL,
690  NIL,
691  options);
692 
693  /*
694  * Save state in node->fdw_state. We must save enough information to call
695  * BeginCopyFrom() again.
696  */
697  festate = (FileFdwExecutionState *) palloc(sizeof(FileFdwExecutionState));
698  festate->filename = filename;
699  festate->is_program = is_program;
700  festate->options = options;
701  festate->cstate = cstate;
702 
703  node->fdw_state = (void *) festate;
704 }
705 
706 /*
707  * fileIterateForeignScan
708  * Read next record from the data file and store it into the
709  * ScanTupleSlot as a virtual tuple
710  */
711 static TupleTableSlot *
713 {
715  TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
716  bool found;
717  ErrorContextCallback errcallback;
718 
719  /* Set up callback to identify error line number. */
720  errcallback.callback = CopyFromErrorCallback;
721  errcallback.arg = (void *) festate->cstate;
722  errcallback.previous = error_context_stack;
723  error_context_stack = &errcallback;
724 
725  /*
726  * The protocol for loading a virtual tuple into a slot is first
727  * ExecClearTuple, then fill the values/isnull arrays, then
728  * ExecStoreVirtualTuple. If we don't find another row in the file, we
729  * just skip the last step, leaving the slot empty as required.
730  *
731  * We can pass ExprContext = NULL because we read all columns from the
732  * file, so no need to evaluate default expressions.
733  */
734  ExecClearTuple(slot);
735  found = NextCopyFrom(festate->cstate, NULL,
736  slot->tts_values, slot->tts_isnull);
737  if (found)
738  ExecStoreVirtualTuple(slot);
739 
740  /* Remove error callback. */
741  error_context_stack = errcallback.previous;
742 
743  return slot;
744 }
745 
746 /*
747  * fileReScanForeignScan
748  * Rescan table, possibly with new parameters
749  */
750 static void
752 {
754 
755  EndCopyFrom(festate->cstate);
756 
757  festate->cstate = BeginCopyFrom(NULL,
758  node->ss.ss_currentRelation,
759  NULL,
760  festate->filename,
761  festate->is_program,
762  NULL,
763  NIL,
764  festate->options);
765 }
766 
767 /*
768  * fileEndForeignScan
769  * Finish scanning foreign table and dispose objects used for this scan
770  */
771 static void
773 {
775 
776  /* if festate is NULL, we are in EXPLAIN; nothing to do */
777  if (festate)
778  EndCopyFrom(festate->cstate);
779 }
780 
781 /*
782  * fileAnalyzeForeignTable
783  * Test whether analyzing this foreign table is supported
784  */
785 static bool
787  AcquireSampleRowsFunc *func,
788  BlockNumber *totalpages)
789 {
790  char *filename;
791  bool is_program;
792  List *options;
793  struct stat stat_buf;
794 
795  /* Fetch options of foreign table */
796  fileGetOptions(RelationGetRelid(relation), &filename, &is_program, &options);
797 
798  /*
799  * If this is a program instead of a file, just return false to skip
800  * analyzing the table. We could run the program and collect stats on
801  * whatever it currently returns, but it seems likely that in such cases
802  * the output would be too volatile for the stats to be useful. Maybe
803  * there should be an option to enable doing this?
804  */
805  if (is_program)
806  return false;
807 
808  /*
809  * Get size of the file. (XXX if we fail here, would it be better to just
810  * return false to skip analyzing the table?)
811  */
812  if (stat(filename, &stat_buf) < 0)
813  ereport(ERROR,
815  errmsg("could not stat file \"%s\": %m",
816  filename)));
817 
818  /*
819  * Convert size to pages. Must return at least 1 so that we can tell
820  * later on that pg_class.relpages is not default.
821  */
822  *totalpages = (stat_buf.st_size + (BLCKSZ - 1)) / BLCKSZ;
823  if (*totalpages < 1)
824  *totalpages = 1;
825 
826  *func = file_acquire_sample_rows;
827 
828  return true;
829 }
830 
831 /*
832  * fileIsForeignScanParallelSafe
833  * Reading a file, or external program, in a parallel worker should work
834  * just the same as reading it in the leader, so mark scans safe.
835  */
836 static bool
838  RangeTblEntry *rte)
839 {
840  return true;
841 }
842 
843 /*
844  * check_selective_binary_conversion
845  *
846  * Check to see if it's useful to convert only a subset of the file's columns
847  * to binary. If so, construct a list of the column names to be converted,
848  * return that at *columns, and return true. (Note that it's possible to
849  * determine that no columns need be converted, for instance with a COUNT(*)
850  * query. So we can't use returning a NIL list to indicate failure.)
851  */
852 static bool
854  Oid foreigntableid,
855  List **columns)
856 {
857  ForeignTable *table;
858  ListCell *lc;
859  Relation rel;
860  TupleDesc tupleDesc;
862  Bitmapset *attrs_used = NULL;
863  bool has_wholerow = false;
864  int numattrs;
865  int i;
866 
867  *columns = NIL; /* default result */
868 
869  /*
870  * Check format of the file. If binary format, this is irrelevant.
871  */
872  table = GetForeignTable(foreigntableid);
873  foreach(lc, table->options)
874  {
875  DefElem *def = (DefElem *) lfirst(lc);
876 
877  if (strcmp(def->defname, "format") == 0)
878  {
879  char *format = defGetString(def);
880 
881  if (strcmp(format, "binary") == 0)
882  return false;
883  break;
884  }
885  }
886 
887  /* Collect all the attributes needed for joins or final output. */
888  pull_varattnos((Node *) baserel->reltarget->exprs, baserel->relid,
889  &attrs_used);
890 
891  /* Add all the attributes used by restriction clauses. */
892  foreach(lc, baserel->baserestrictinfo)
893  {
894  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
895 
896  pull_varattnos((Node *) rinfo->clause, baserel->relid,
897  &attrs_used);
898  }
899 
900  /* Convert attribute numbers to column names. */
901  rel = table_open(foreigntableid, AccessShareLock);
902  tupleDesc = RelationGetDescr(rel);
903 
904  while ((attnum = bms_first_member(attrs_used)) >= 0)
905  {
906  /* Adjust for system attributes. */
908 
909  if (attnum == 0)
910  {
911  has_wholerow = true;
912  break;
913  }
914 
915  /* Ignore system attributes. */
916  if (attnum < 0)
917  continue;
918 
919  /* Get user attributes. */
920  if (attnum > 0)
921  {
922  Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum - 1);
923  char *attname = NameStr(attr->attname);
924 
925  /* Skip dropped attributes (probably shouldn't see any here). */
926  if (attr->attisdropped)
927  continue;
928 
929  /*
930  * Skip generated columns (COPY won't accept them in the column
931  * list)
932  */
933  if (attr->attgenerated)
934  continue;
935  *columns = lappend(*columns, makeString(pstrdup(attname)));
936  }
937  }
938 
939  /* Count non-dropped user attributes while we have the tupdesc. */
940  numattrs = 0;
941  for (i = 0; i < tupleDesc->natts; i++)
942  {
943  Form_pg_attribute attr = TupleDescAttr(tupleDesc, i);
944 
945  if (attr->attisdropped)
946  continue;
947  numattrs++;
948  }
949 
951 
952  /* If there's a whole-row reference, fail: we need all the columns. */
953  if (has_wholerow)
954  {
955  *columns = NIL;
956  return false;
957  }
958 
959  /* If all the user attributes are needed, fail. */
960  if (numattrs == list_length(*columns))
961  {
962  *columns = NIL;
963  return false;
964  }
965 
966  return true;
967 }
968 
969 /*
970  * Estimate size of a foreign table.
971  *
972  * The main result is returned in baserel->rows. We also set
973  * fdw_private->pages and fdw_private->ntuples for later use in the cost
974  * calculation.
975  */
976 static void
978  FileFdwPlanState *fdw_private)
979 {
980  struct stat stat_buf;
981  BlockNumber pages;
982  double ntuples;
983  double nrows;
984 
985  /*
986  * Get size of the file. It might not be there at plan time, though, in
987  * which case we have to use a default estimate. We also have to fall
988  * back to the default if using a program as the input.
989  */
990  if (fdw_private->is_program || stat(fdw_private->filename, &stat_buf) < 0)
991  stat_buf.st_size = 10 * BLCKSZ;
992 
993  /*
994  * Convert size to pages for use in I/O cost estimate later.
995  */
996  pages = (stat_buf.st_size + (BLCKSZ - 1)) / BLCKSZ;
997  if (pages < 1)
998  pages = 1;
999  fdw_private->pages = pages;
1000 
1001  /*
1002  * Estimate the number of tuples in the file.
1003  */
1004  if (baserel->tuples >= 0 && baserel->pages > 0)
1005  {
1006  /*
1007  * We have # of pages and # of tuples from pg_class (that is, from a
1008  * previous ANALYZE), so compute a tuples-per-page estimate and scale
1009  * that by the current file size.
1010  */
1011  double density;
1012 
1013  density = baserel->tuples / (double) baserel->pages;
1014  ntuples = clamp_row_est(density * (double) pages);
1015  }
1016  else
1017  {
1018  /*
1019  * Otherwise we have to fake it. We back into this estimate using the
1020  * planner's idea of the relation width; which is bogus if not all
1021  * columns are being read, not to mention that the text representation
1022  * of a row probably isn't the same size as its internal
1023  * representation. Possibly we could do something better, but the
1024  * real answer to anyone who complains is "ANALYZE" ...
1025  */
1026  int tuple_width;
1027 
1028  tuple_width = MAXALIGN(baserel->reltarget->width) +
1030  ntuples = clamp_row_est((double) stat_buf.st_size /
1031  (double) tuple_width);
1032  }
1033  fdw_private->ntuples = ntuples;
1034 
1035  /*
1036  * Now estimate the number of rows returned by the scan after applying the
1037  * baserestrictinfo quals.
1038  */
1039  nrows = ntuples *
1041  baserel->baserestrictinfo,
1042  0,
1043  JOIN_INNER,
1044  NULL);
1045 
1046  nrows = clamp_row_est(nrows);
1047 
1048  /* Save the output-rows estimate for the planner */
1049  baserel->rows = nrows;
1050 }
1051 
1052 /*
1053  * Estimate costs of scanning a foreign table.
1054  *
1055  * Results are returned in *startup_cost and *total_cost.
1056  */
1057 static void
1059  FileFdwPlanState *fdw_private,
1060  Cost *startup_cost, Cost *total_cost)
1061 {
1062  BlockNumber pages = fdw_private->pages;
1063  double ntuples = fdw_private->ntuples;
1064  Cost run_cost = 0;
1065  Cost cpu_per_tuple;
1066 
1067  /*
1068  * We estimate costs almost the same way as cost_seqscan(), thus assuming
1069  * that I/O costs are equivalent to a regular table file of the same size.
1070  * However, we take per-tuple CPU costs as 10x of a seqscan, to account
1071  * for the cost of parsing records.
1072  *
1073  * In the case of a program source, this calculation is even more divorced
1074  * from reality, but we have no good alternative; and it's not clear that
1075  * the numbers we produce here matter much anyway, since there's only one
1076  * access path for the rel.
1077  */
1078  run_cost += seq_page_cost * pages;
1079 
1080  *startup_cost = baserel->baserestrictcost.startup;
1081  cpu_per_tuple = cpu_tuple_cost * 10 + baserel->baserestrictcost.per_tuple;
1082  run_cost += cpu_per_tuple * ntuples;
1083  *total_cost = *startup_cost + run_cost;
1084 }
1085 
1086 /*
1087  * file_acquire_sample_rows -- acquire a random sample of rows from the table
1088  *
1089  * Selected rows are returned in the caller-allocated array rows[],
1090  * which must have at least targrows entries.
1091  * The actual number of rows selected is returned as the function result.
1092  * We also count the total number of rows in the file and return it into
1093  * *totalrows. Note that *totaldeadrows is always set to 0.
1094  *
1095  * Note that the returned list of rows is not always in order by physical
1096  * position in the file. Therefore, correlation estimates derived later
1097  * may be meaningless, but it's OK because we don't use the estimates
1098  * currently (the planner only pays attention to correlation for indexscans).
1099  */
1100 static int
1102  HeapTuple *rows, int targrows,
1103  double *totalrows, double *totaldeadrows)
1104 {
1105  int numrows = 0;
1106  double rowstoskip = -1; /* -1 means not set yet */
1107  ReservoirStateData rstate;
1108  TupleDesc tupDesc;
1109  Datum *values;
1110  bool *nulls;
1111  bool found;
1112  char *filename;
1113  bool is_program;
1114  List *options;
1115  CopyFromState cstate;
1116  ErrorContextCallback errcallback;
1117  MemoryContext oldcontext = CurrentMemoryContext;
1118  MemoryContext tupcontext;
1119 
1120  Assert(onerel);
1121  Assert(targrows > 0);
1122 
1123  tupDesc = RelationGetDescr(onerel);
1124  values = (Datum *) palloc(tupDesc->natts * sizeof(Datum));
1125  nulls = (bool *) palloc(tupDesc->natts * sizeof(bool));
1126 
1127  /* Fetch options of foreign table */
1128  fileGetOptions(RelationGetRelid(onerel), &filename, &is_program, &options);
1129 
1130  /*
1131  * Create CopyState from FDW options.
1132  */
1133  cstate = BeginCopyFrom(NULL, onerel, NULL, filename, is_program, NULL, NIL,
1134  options);
1135 
1136  /*
1137  * Use per-tuple memory context to prevent leak of memory used to read
1138  * rows from the file with Copy routines.
1139  */
1141  "file_fdw temporary context",
1143 
1144  /* Prepare for sampling rows */
1145  reservoir_init_selection_state(&rstate, targrows);
1146 
1147  /* Set up callback to identify error line number. */
1148  errcallback.callback = CopyFromErrorCallback;
1149  errcallback.arg = (void *) cstate;
1150  errcallback.previous = error_context_stack;
1151  error_context_stack = &errcallback;
1152 
1153  *totalrows = 0;
1154  *totaldeadrows = 0;
1155  for (;;)
1156  {
1157  /* Check for user-requested abort or sleep */
1159 
1160  /* Fetch next row */
1161  MemoryContextReset(tupcontext);
1162  MemoryContextSwitchTo(tupcontext);
1163 
1164  found = NextCopyFrom(cstate, NULL, values, nulls);
1165 
1166  MemoryContextSwitchTo(oldcontext);
1167 
1168  if (!found)
1169  break;
1170 
1171  /*
1172  * The first targrows sample rows are simply copied into the
1173  * reservoir. Then we start replacing tuples in the sample until we
1174  * reach the end of the relation. This algorithm is from Jeff Vitter's
1175  * paper (see more info in commands/analyze.c).
1176  */
1177  if (numrows < targrows)
1178  {
1179  rows[numrows++] = heap_form_tuple(tupDesc, values, nulls);
1180  }
1181  else
1182  {
1183  /*
1184  * t in Vitter's paper is the number of records already processed.
1185  * If we need to compute a new S value, we must use the
1186  * not-yet-incremented value of totalrows as t.
1187  */
1188  if (rowstoskip < 0)
1189  rowstoskip = reservoir_get_next_S(&rstate, *totalrows, targrows);
1190 
1191  if (rowstoskip <= 0)
1192  {
1193  /*
1194  * Found a suitable tuple, so save it, replacing one old tuple
1195  * at random
1196  */
1197  int k = (int) (targrows * sampler_random_fract(&rstate.randstate));
1198 
1199  Assert(k >= 0 && k < targrows);
1200  heap_freetuple(rows[k]);
1201  rows[k] = heap_form_tuple(tupDesc, values, nulls);
1202  }
1203 
1204  rowstoskip -= 1;
1205  }
1206 
1207  *totalrows += 1;
1208  }
1209 
1210  /* Remove error callback. */
1211  error_context_stack = errcallback.previous;
1212 
1213  /* Clean up. */
1214  MemoryContextDelete(tupcontext);
1215 
1216  EndCopyFrom(cstate);
1217 
1218  pfree(values);
1219  pfree(nulls);
1220 
1221  /*
1222  * Emit some interesting relation info
1223  */
1224  ereport(elevel,
1225  (errmsg("\"%s\": file contains %.0f rows; "
1226  "%d rows in sample",
1227  RelationGetRelationName(onerel),
1228  *totalrows, numrows)));
1229 
1230  return numrows;
1231 }
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4949
int16 AttrNumber
Definition: attnum.h:21
void ProcessCopyOptions(ParseState *pstate, CopyFormatOptions *opts_out, bool is_from, List *options)
Definition: copy.c:404
int bms_first_member(Bitmapset *a)
Definition: bitmapset.c:1000
uint32 BlockNumber
Definition: block.h:31
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define NameStr(name)
Definition: c.h:682
#define MAXALIGN(LEN)
Definition: c.h:747
unsigned int Index
Definition: c.h:550
Selectivity clauselist_selectivity(PlannerInfo *root, List *clauses, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: clausesel.c:102
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)
Definition: copyfrom.c:1333
void EndCopyFrom(CopyFromState cstate)
Definition: copyfrom.c:1707
void CopyFromErrorCallback(void *arg)
Definition: copyfrom.c:116
bool NextCopyFrom(CopyFromState cstate, ExprContext *econtext, Datum *values, bool *nulls)
double cpu_tuple_cost
Definition: costsize.c:122
double seq_page_cost
Definition: costsize.c:120
double clamp_row_est(double nrows)
Definition: costsize.c:201
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)
Definition: createplan.c:5779
bool defGetBoolean(DefElem *def)
Definition: define.c:108
char * defGetString(DefElem *def)
Definition: define.c:49
int errcode_for_file_access(void)
Definition: elog.c:718
ErrorContextCallback * error_context_stack
Definition: elog.c:94
int errhint(const char *fmt,...)
Definition: elog.c:1153
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1552
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:56
void ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es)
Definition: explain.c:4543
void ExplainPropertyInteger(const char *qlabel, const char *unit, int64 value, ExplainState *es)
Definition: explain.c:4552
int(* AcquireSampleRowsFunc)(Relation relation, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
Definition: fdwapi.h:151
static ForeignScan * fileGetForeignPlan(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid, ForeignPath *best_path, List *tlist, List *scan_clauses, Plan *outer_plan)
Definition: file_fdw.c:591
static void fileEndForeignScan(ForeignScanState *node)
Definition: file_fdw.c:772
Datum file_fdw_handler(PG_FUNCTION_ARGS)
Definition: file_fdw.c:172
static bool check_selective_binary_conversion(RelOptInfo *baserel, Oid foreigntableid, List **columns)
Definition: file_fdw.c:853
static void fileGetForeignRelSize(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
Definition: file_fdw.c:507
static void fileExplainForeignScan(ForeignScanState *node, ExplainState *es)
Definition: file_fdw.c:626
static List * get_file_fdw_attribute_options(Oid relid)
Definition: file_fdw.c:434
PG_MODULE_MAGIC
Definition: file_fdw.c:42
Datum file_fdw_validator(PG_FUNCTION_ARGS)
Definition: file_fdw.c:197
static void estimate_costs(PlannerInfo *root, RelOptInfo *baserel, FileFdwPlanState *fdw_private, Cost *startup_cost, Cost *total_cost)
Definition: file_fdw.c:1058
static int file_acquire_sample_rows(Relation onerel, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows)
Definition: file_fdw.c:1101
PG_FUNCTION_INFO_V1(file_fdw_handler)
static const struct FileFdwOption valid_options[]
Definition: file_fdw.c:62
static bool fileAnalyzeForeignTable(Relation relation, AcquireSampleRowsFunc *func, BlockNumber *totalpages)
Definition: file_fdw.c:786
static void fileReScanForeignScan(ForeignScanState *node)
Definition: file_fdw.c:751
struct FileFdwExecutionState FileFdwExecutionState
static bool is_valid_option(const char *option, Oid context)
Definition: file_fdw.c:344
static bool fileIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: file_fdw.c:837
static void fileGetForeignPaths(PlannerInfo *root, RelOptInfo *baserel, Oid foreigntableid)
Definition: file_fdw.c:538
static void fileGetOptions(Oid foreigntableid, char **filename, bool *is_program, List **other_options)
Definition: file_fdw.c:363
static void estimate_size(PlannerInfo *root, RelOptInfo *baserel, FileFdwPlanState *fdw_private)
Definition: file_fdw.c:977
static void fileBeginForeignScan(ForeignScanState *node, int eflags)
Definition: file_fdw.c:658
static TupleTableSlot * fileIterateForeignScan(ForeignScanState *node)
Definition: file_fdw.c:712
struct FileFdwPlanState FileFdwPlanState
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:37
ForeignTable * GetForeignTable(Oid relid)
Definition: foreign.c:250
List * GetForeignColumnOptions(Oid relid, AttrNumber attnum)
Definition: foreign.c:288
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:111
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
#define SizeofHeapTupleHeader
Definition: htup_details.h:184
int i
Definition: isn.c:73
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
Definition: list.c:338
List * list_concat(List *list1, const List *list2)
Definition: list.c:560
#define AccessShareLock
Definition: lockdefs.h:36
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:546
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:303
char * pstrdup(const char *in)
Definition: mcxt.c:1483
void pfree(void *pointer)
Definition: mcxt.c:1306
MemoryContext CurrentMemoryContext
Definition: mcxt.c:124
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:376
void * palloc(Size size)
Definition: mcxt.c:1199
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
Oid GetUserId(void)
Definition: miscinit.c:497
double Cost
Definition: nodes.h:251
#define makeNode(_type_)
Definition: nodes.h:165
@ JOIN_INNER
Definition: nodes.h:293
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
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_private)
Definition: pathnode.c:2226
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:83
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:207
static char format
static char * filename
Definition: pg_dumpall.c:119
#define lfirst(lc)
Definition: pg_list.h:170
static int list_length(const List *l)
Definition: pg_list.h:150
#define NIL
Definition: pg_list.h:66
#define list_make1(x1)
Definition: pg_list.h:210
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:388
static char ** options
uintptr_t Datum
Definition: postgres.h:412
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:501
#define RelationGetDescr(relation)
Definition: rel.h:527
#define RelationGetRelationName(relation)
Definition: rel.h:535
List * untransformRelOptions(Datum options)
Definition: reloptions.c:1333
List * extract_actual_clauses(List *restrictinfo_list, bool pseudoconstant)
Definition: restrictinfo.c:445
void reservoir_init_selection_state(ReservoirState rs, int n)
Definition: sampling.c:133
double sampler_random_fract(pg_prng_state *randstate)
Definition: sampling.c:241
double reservoir_get_next_S(ReservoirState rs, double t, int n)
Definition: sampling.c:147
char * defname
Definition: parsenodes.h:777
struct ErrorContextCallback * previous
Definition: elog.h:234
void(* callback)(void *arg)
Definition: elog.h:235
bool costs
Definition: explain.h:43
ReScanForeignScan_function ReScanForeignScan
Definition: fdwapi.h:214
BeginForeignScan_function BeginForeignScan
Definition: fdwapi.h:212
IsForeignScanParallelSafe_function IsForeignScanParallelSafe
Definition: fdwapi.h:266
GetForeignPaths_function GetForeignPaths
Definition: fdwapi.h:210
GetForeignRelSize_function GetForeignRelSize
Definition: fdwapi.h:209
ExplainForeignScan_function ExplainForeignScan
Definition: fdwapi.h:252
EndForeignScan_function EndForeignScan
Definition: fdwapi.h:215
AnalyzeForeignTable_function AnalyzeForeignTable
Definition: fdwapi.h:257
IterateForeignScan_function IterateForeignScan
Definition: fdwapi.h:213
GetForeignPlan_function GetForeignPlan
Definition: fdwapi.h:211
CopyFromState cstate
Definition: file_fdw.c:109
Oid optcontext
Definition: file_fdw.c:50
const char * optname
Definition: file_fdw.c:49
char * filename
Definition: file_fdw.c:92
double ntuples
Definition: file_fdw.c:97
BlockNumber pages
Definition: file_fdw.c:96
List * options
Definition: file_fdw.c:94
List * options
Definition: foreign.h:31
List * fdw_private
Definition: pathnodes.h:1754
ScanState ss
Definition: execnodes.h:1934
List * fdw_private
Definition: plannodes.h:713
List * options
Definition: foreign.h:42
List * options
Definition: foreign.h:57
Oid serverid
Definition: foreign.h:56
Definition: pg_list.h:52
Definition: nodes.h:118
List * exprs
Definition: pathnodes.h:1424
Plan * plan
Definition: execnodes.h:1029
Cost per_tuple
Definition: pathnodes.h:48
Cost startup
Definition: pathnodes.h:47
List * baserestrictinfo
Definition: pathnodes.h:930
struct PathTarget * reltarget
Definition: pathnodes.h:843
Index relid
Definition: pathnodes.h:868
Cardinality tuples
Definition: pathnodes.h:891
BlockNumber pages
Definition: pathnodes.h:890
Relids lateral_relids
Definition: pathnodes.h:863
QualCost baserestrictcost
Definition: pathnodes.h:932
Cardinality rows
Definition: pathnodes.h:827
pg_prng_state randstate
Definition: sampling.h:49
Expr * clause
Definition: pathnodes.h:2432
Relation ss_currentRelation
Definition: execnodes.h:1455
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1457
PlanState ps
Definition: execnodes.h:1454
__int64 st_size
Definition: win32_port.h:275
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433
void vacuum_delay_point(void)
Definition: vacuum.c:2166
String * makeString(char *str)
Definition: value.c:63
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:281
const char * getClosestMatch(ClosestMatchState *state)
Definition: varlena.c:6274
void initClosestMatch(ClosestMatchState *state, const char *source, int max_d)
Definition: varlena.c:6219
void updateClosestMatch(ClosestMatchState *state, const char *candidate)
Definition: varlena.c:6239
#define stat
Definition: win32_port.h:286