params.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*-------------------------------------------------------------------------
  2. *
  3. * params.h
  4. * Support for finding the values associated with Param nodes.
  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/params.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef PARAMS_H
  15. #define PARAMS_H
  16. /* Forward declarations, to avoid including other headers */
  17. struct Bitmapset;
  18. struct ParseState;
  19. /* ----------------
  20. * ParamListInfo
  21. *
  22. * ParamListInfo arrays are used to pass parameters into the executor
  23. * for parameterized plans. Each entry in the array defines the value
  24. * to be substituted for a PARAM_EXTERN parameter. The "paramid"
  25. * of a PARAM_EXTERN Param can range from 1 to numParams.
  26. *
  27. * Although parameter numbers are normally consecutive, we allow
  28. * ptype == InvalidOid to signal an unused array entry.
  29. *
  30. * pflags is a flags field. Currently the only used bit is:
  31. * PARAM_FLAG_CONST signals the planner that it may treat this parameter
  32. * as a constant (i.e., generate a plan that works only for this value
  33. * of the parameter).
  34. *
  35. * There are two hook functions that can be associated with a ParamListInfo
  36. * array to support dynamic parameter handling. First, if paramFetch
  37. * isn't null and the executor requires a value for an invalid parameter
  38. * (one with ptype == InvalidOid), the paramFetch hook is called to give
  39. * it a chance to fill in the parameter value. Second, a parserSetup
  40. * hook can be supplied to re-instantiate the original parsing hooks if
  41. * a query needs to be re-parsed/planned (as a substitute for supposing
  42. * that the current ptype values represent a fixed set of parameter types).
  43. * Although the data structure is really an array, not a list, we keep
  44. * the old typedef name to avoid unnecessary code changes.
  45. * ----------------
  46. */
  47. #define PARAM_FLAG_CONST 0x0001 /* parameter is constant */
  48. typedef struct ParamExternData
  49. {
  50. Datum value; /* parameter value */
  51. bool isnull; /* is it NULL? */
  52. uint16 pflags; /* flag bits, see above */
  53. Oid ptype; /* parameter's datatype, or 0 */
  54. } ParamExternData;
  55. typedef struct ParamListInfoData *ParamListInfo;
  56. typedef void (*ParamFetchHook) (ParamListInfo params, int paramid);
  57. typedef void (*ParserSetupHook) (struct ParseState *pstate, void *arg);
  58. typedef struct ParamListInfoData
  59. {
  60. ParamFetchHook paramFetch; /* parameter fetch hook */
  61. void *paramFetchArg;
  62. ParserSetupHook parserSetup; /* parser setup hook */
  63. void *parserSetupArg;
  64. int numParams; /* number of ParamExternDatas following */
  65. struct Bitmapset *paramMask; /* if non-NULL, can ignore omitted params */
  66. ParamExternData params[FLEXIBLE_ARRAY_MEMBER];
  67. } ParamListInfoData;
  68. /* ----------------
  69. * ParamExecData
  70. *
  71. * ParamExecData entries are used for executor internal parameters
  72. * (that is, values being passed into or out of a sub-query). The
  73. * paramid of a PARAM_EXEC Param is a (zero-based) index into an
  74. * array of ParamExecData records, which is referenced through
  75. * es_param_exec_vals or ecxt_param_exec_vals.
  76. *
  77. * If execPlan is not NULL, it points to a SubPlanState node that needs
  78. * to be executed to produce the value. (This is done so that we can have
  79. * lazy evaluation of InitPlans: they aren't executed until/unless a
  80. * result value is needed.) Otherwise the value is assumed to be valid
  81. * when needed.
  82. * ----------------
  83. */
  84. typedef struct ParamExecData
  85. {
  86. void *execPlan; /* should be "SubPlanState *" */
  87. Datum value;
  88. bool isnull;
  89. } ParamExecData;
  90. /* Functions found in src/backend/nodes/params.c */
  91. extern ParamListInfo copyParamList(ParamListInfo from);
  92. extern Size EstimateParamListSpace(ParamListInfo paramLI);
  93. extern void SerializeParamList(ParamListInfo paramLI, char **start_address);
  94. extern ParamListInfo RestoreParamList(char **start_address);
  95. #endif /* PARAMS_H */