tsmapi.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*-------------------------------------------------------------------------
  2. *
  3. * tsmapi.h
  4. * API for tablesample methods
  5. *
  6. * Copyright (c) 2015-2022, 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/pathnodes.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. BlockNumber nblocks);
  32. typedef OffsetNumber (*NextSampleTuple_function) (SampleScanState *node,
  33. BlockNumber blockno,
  34. OffsetNumber maxoffset);
  35. typedef void (*EndSampleScan_function) (SampleScanState *node);
  36. /*
  37. * TsmRoutine is the struct returned by a tablesample method's handler
  38. * function. It provides pointers to the callback functions needed by the
  39. * planner and executor, as well as additional information about the method.
  40. *
  41. * More function pointers are likely to be added in the future.
  42. * Therefore it's recommended that the handler initialize the struct with
  43. * makeNode(TsmRoutine) so that all fields are set to NULL. This will
  44. * ensure that no fields are accidentally left undefined.
  45. */
  46. typedef struct TsmRoutine
  47. {
  48. NodeTag type;
  49. /* List of datatype OIDs for the arguments of the TABLESAMPLE clause */
  50. List *parameterTypes;
  51. /* Can method produce repeatable samples across, or even within, queries? */
  52. bool repeatable_across_queries;
  53. bool repeatable_across_scans;
  54. /* Functions for planning a SampleScan on a physical table */
  55. SampleScanGetSampleSize_function SampleScanGetSampleSize;
  56. /* Functions for executing a SampleScan on a physical table */
  57. InitSampleScan_function InitSampleScan; /* can be NULL */
  58. BeginSampleScan_function BeginSampleScan;
  59. NextSampleBlock_function NextSampleBlock; /* can be NULL */
  60. NextSampleTuple_function NextSampleTuple;
  61. EndSampleScan_function EndSampleScan; /* can be NULL */
  62. } TsmRoutine;
  63. /* Functions in access/tablesample/tablesample.c */
  64. extern TsmRoutine *GetTsmRoutine(Oid tsmhandler);
  65. #endif /* TSMAPI_H */