tsmapi.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*-------------------------------------------------------------------------
  2. *
  3. * tsmapi.h
  4. * API for tablesample methods
  5. *
  6. * Copyright (c) 2015-2016, PostgreSQL Global Development Group
  7. *
  8. * src/include/access/tsmapi.h
  9. *
  10. *-------------------------------------------------------------------------
  11. */
  12. #ifndef TSMAPI_H
  13. #define TSMAPI_H
  14. #include "nodes/execnodes.h"
  15. #include "nodes/relation.h"
  16. /*
  17. * Callback function signatures --- see tablesample-method.sgml for more info.
  18. */
  19. typedef void (*SampleScanGetSampleSize_function) (PlannerInfo *root,
  20. RelOptInfo *baserel,
  21. List *paramexprs,
  22. BlockNumber *pages,
  23. double *tuples);
  24. typedef void (*InitSampleScan_function) (SampleScanState *node,
  25. int eflags);
  26. typedef void (*BeginSampleScan_function) (SampleScanState *node,
  27. Datum *params,
  28. int nparams,
  29. uint32 seed);
  30. typedef BlockNumber (*NextSampleBlock_function) (SampleScanState *node);
  31. typedef OffsetNumber (*NextSampleTuple_function) (SampleScanState *node,
  32. BlockNumber blockno,
  33. OffsetNumber maxoffset);
  34. typedef void (*EndSampleScan_function) (SampleScanState *node);
  35. /*
  36. * TsmRoutine is the struct returned by a tablesample method's handler
  37. * function. It provides pointers to the callback functions needed by the
  38. * planner and executor, as well as additional information about the method.
  39. *
  40. * More function pointers are likely to be added in the future.
  41. * Therefore it's recommended that the handler initialize the struct with
  42. * makeNode(TsmRoutine) so that all fields are set to NULL. This will
  43. * ensure that no fields are accidentally left undefined.
  44. */
  45. typedef struct TsmRoutine
  46. {
  47. NodeTag type;
  48. /* List of datatype OIDs for the arguments of the TABLESAMPLE clause */
  49. List *parameterTypes;
  50. /* Can method produce repeatable samples across, or even within, queries? */
  51. bool repeatable_across_queries;
  52. bool repeatable_across_scans;
  53. /* Functions for planning a SampleScan on a physical table */
  54. SampleScanGetSampleSize_function SampleScanGetSampleSize;
  55. /* Functions for executing a SampleScan on a physical table */
  56. InitSampleScan_function InitSampleScan; /* can be NULL */
  57. BeginSampleScan_function BeginSampleScan;
  58. NextSampleBlock_function NextSampleBlock; /* can be NULL */
  59. NextSampleTuple_function NextSampleTuple;
  60. EndSampleScan_function EndSampleScan; /* can be NULL */
  61. } TsmRoutine;
  62. /* Functions in access/tablesample/tablesample.c */
  63. extern TsmRoutine *GetTsmRoutine(Oid tsmhandler);
  64. #endif /* TSMAPI_H */