extensible.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*-------------------------------------------------------------------------
  2. *
  3. * extensible.h
  4. * Definitions for extensible nodes and custom scans
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/nodes/extensible.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef EXTENSIBLE_H
  15. #define EXTENSIBLE_H
  16. #include "access/parallel.h"
  17. #include "commands/explain.h"
  18. #include "nodes/execnodes.h"
  19. #include "nodes/plannodes.h"
  20. #include "nodes/relation.h"
  21. /* maximum length of an extensible node identifier */
  22. #define EXTNODENAME_MAX_LEN 64
  23. /*
  24. * An extensible node is a new type of node defined by an extension. The
  25. * type is always T_ExtensibleNode, while the extnodename identifies the
  26. * specific type of node. extnodename can be looked up to find the
  27. * ExtensibleNodeMethods for this node type.
  28. */
  29. typedef struct ExtensibleNode
  30. {
  31. NodeTag type;
  32. const char *extnodename; /* identifier of ExtensibleNodeMethods */
  33. } ExtensibleNode;
  34. /*
  35. * node_size is the size of an extensible node of this type in bytes.
  36. *
  37. * nodeCopy is a function which performs a deep copy from oldnode to newnode.
  38. * It does not need to copy type or extnodename, which are copied by the
  39. * core system.
  40. *
  41. * nodeEqual is a function which performs a deep equality comparison between
  42. * a and b and returns true or false accordingly. It does not need to compare
  43. * type or extnodename, which are compared by the core system.
  44. *
  45. * nodeOut is a serialization function for the node type. It should use the
  46. * output conventions typical for outfuncs.c. It does not need to output
  47. * type or extnodename; the core system handles those.
  48. *
  49. * nodeRead is a deserialization function for the node type. It does not need
  50. * to read type or extnodename; the core system handles those. It should fetch
  51. * the next token using pg_strtok() from the current input stream, and then
  52. * reconstruct the private fields according to the manner in readfuncs.c.
  53. *
  54. * All callbacks are mandatory.
  55. */
  56. typedef struct ExtensibleNodeMethods
  57. {
  58. const char *extnodename;
  59. Size node_size;
  60. void (*nodeCopy) (struct ExtensibleNode *newnode,
  61. const struct ExtensibleNode *oldnode);
  62. bool (*nodeEqual) (const struct ExtensibleNode *a,
  63. const struct ExtensibleNode *b);
  64. void (*nodeOut) (struct StringInfoData *str,
  65. const struct ExtensibleNode *node);
  66. void (*nodeRead) (struct ExtensibleNode *node);
  67. } ExtensibleNodeMethods;
  68. extern void RegisterExtensibleNodeMethods(const ExtensibleNodeMethods *method);
  69. extern const ExtensibleNodeMethods *GetExtensibleNodeMethods(const char *name,
  70. bool missing_ok);
  71. /*
  72. * Flags for custom paths, indicating what capabilities the resulting scan
  73. * will have.
  74. */
  75. #define CUSTOMPATH_SUPPORT_BACKWARD_SCAN 0x0001
  76. #define CUSTOMPATH_SUPPORT_MARK_RESTORE 0x0002
  77. /*
  78. * Custom path methods. Mostly, we just need to know how to convert a
  79. * CustomPath to a plan.
  80. */
  81. typedef struct CustomPathMethods
  82. {
  83. const char *CustomName;
  84. /* Convert Path to a Plan */
  85. struct Plan *(*PlanCustomPath) (PlannerInfo *root,
  86. RelOptInfo *rel,
  87. struct CustomPath *best_path,
  88. List *tlist,
  89. List *clauses,
  90. List *custom_plans);
  91. } CustomPathMethods;
  92. /*
  93. * Custom scan. Here again, there's not much to do: we need to be able to
  94. * generate a ScanState corresponding to the scan.
  95. */
  96. typedef struct CustomScanMethods
  97. {
  98. const char *CustomName;
  99. /* Create execution state (CustomScanState) from a CustomScan plan node */
  100. Node *(*CreateCustomScanState) (CustomScan *cscan);
  101. } CustomScanMethods;
  102. /*
  103. * Execution-time methods for a CustomScanState. This is more complex than
  104. * what we need for a custom path or scan.
  105. */
  106. typedef struct CustomExecMethods
  107. {
  108. const char *CustomName;
  109. /* Required executor methods */
  110. void (*BeginCustomScan) (CustomScanState *node,
  111. EState *estate,
  112. int eflags);
  113. TupleTableSlot *(*ExecCustomScan) (CustomScanState *node);
  114. void (*EndCustomScan) (CustomScanState *node);
  115. void (*ReScanCustomScan) (CustomScanState *node);
  116. /* Optional methods: needed if mark/restore is supported */
  117. void (*MarkPosCustomScan) (CustomScanState *node);
  118. void (*RestrPosCustomScan) (CustomScanState *node);
  119. /* Optional methods: needed if parallel execution is supported */
  120. Size (*EstimateDSMCustomScan) (CustomScanState *node,
  121. ParallelContext *pcxt);
  122. void (*InitializeDSMCustomScan) (CustomScanState *node,
  123. ParallelContext *pcxt,
  124. void *coordinate);
  125. void (*InitializeWorkerCustomScan) (CustomScanState *node,
  126. shm_toc *toc,
  127. void *coordinate);
  128. /* Optional: print additional information in EXPLAIN */
  129. void (*ExplainCustomScan) (CustomScanState *node,
  130. List *ancestors,
  131. ExplainState *es);
  132. } CustomExecMethods;
  133. extern void RegisterCustomScanMethods(const CustomScanMethods *methods);
  134. extern const CustomScanMethods *GetCustomScanMethods(const char *CustomName,
  135. bool missing_ok);
  136. #endif /* EXTENSIBLE_H */