2
0

extensible.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*-------------------------------------------------------------------------
  2. *
  3. * extensible.h
  4. * Definitions for extensible nodes and custom scans
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, 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/pathnodes.h"
  20. #include "nodes/plannodes.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. The flags fields of CustomPath and CustomScan nodes are
  74. * bitmasks of these flags.
  75. */
  76. #define CUSTOMPATH_SUPPORT_BACKWARD_SCAN 0x0001
  77. #define CUSTOMPATH_SUPPORT_MARK_RESTORE 0x0002
  78. #define CUSTOMPATH_SUPPORT_PROJECTION 0x0004
  79. /*
  80. * Custom path methods. Mostly, we just need to know how to convert a
  81. * CustomPath to a plan.
  82. */
  83. typedef struct CustomPathMethods
  84. {
  85. const char *CustomName;
  86. /* Convert Path to a Plan */
  87. struct Plan *(*PlanCustomPath) (PlannerInfo *root,
  88. RelOptInfo *rel,
  89. struct CustomPath *best_path,
  90. List *tlist,
  91. List *clauses,
  92. List *custom_plans);
  93. struct List *(*ReparameterizeCustomPathByChild) (PlannerInfo *root,
  94. List *custom_private,
  95. RelOptInfo *child_rel);
  96. } CustomPathMethods;
  97. /*
  98. * Custom scan. Here again, there's not much to do: we need to be able to
  99. * generate a ScanState corresponding to the scan.
  100. */
  101. typedef struct CustomScanMethods
  102. {
  103. const char *CustomName;
  104. /* Create execution state (CustomScanState) from a CustomScan plan node */
  105. Node *(*CreateCustomScanState) (CustomScan *cscan);
  106. } CustomScanMethods;
  107. /*
  108. * Execution-time methods for a CustomScanState. This is more complex than
  109. * what we need for a custom path or scan.
  110. */
  111. typedef struct CustomExecMethods
  112. {
  113. const char *CustomName;
  114. /* Required executor methods */
  115. void (*BeginCustomScan) (CustomScanState *node,
  116. EState *estate,
  117. int eflags);
  118. TupleTableSlot *(*ExecCustomScan) (CustomScanState *node);
  119. void (*EndCustomScan) (CustomScanState *node);
  120. void (*ReScanCustomScan) (CustomScanState *node);
  121. /* Optional methods: needed if mark/restore is supported */
  122. void (*MarkPosCustomScan) (CustomScanState *node);
  123. void (*RestrPosCustomScan) (CustomScanState *node);
  124. /* Optional methods: needed if parallel execution is supported */
  125. Size (*EstimateDSMCustomScan) (CustomScanState *node,
  126. ParallelContext *pcxt);
  127. void (*InitializeDSMCustomScan) (CustomScanState *node,
  128. ParallelContext *pcxt,
  129. void *coordinate);
  130. void (*ReInitializeDSMCustomScan) (CustomScanState *node,
  131. ParallelContext *pcxt,
  132. void *coordinate);
  133. void (*InitializeWorkerCustomScan) (CustomScanState *node,
  134. shm_toc *toc,
  135. void *coordinate);
  136. void (*ShutdownCustomScan) (CustomScanState *node);
  137. /* Optional: print additional information in EXPLAIN */
  138. void (*ExplainCustomScan) (CustomScanState *node,
  139. List *ancestors,
  140. ExplainState *es);
  141. } CustomExecMethods;
  142. extern void RegisterCustomScanMethods(const CustomScanMethods *methods);
  143. extern const CustomScanMethods *GetCustomScanMethods(const char *CustomName,
  144. bool missing_ok);
  145. #endif /* EXTENSIBLE_H */