2
0

utility.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*-------------------------------------------------------------------------
  2. *
  3. * utility.h
  4. * prototypes for utility.c.
  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/tcop/utility.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef UTILITY_H
  15. #define UTILITY_H
  16. #include "tcop/cmdtag.h"
  17. #include "tcop/tcopprot.h"
  18. typedef enum
  19. {
  20. PROCESS_UTILITY_TOPLEVEL, /* toplevel interactive command */
  21. PROCESS_UTILITY_QUERY, /* a complete query, but not toplevel */
  22. PROCESS_UTILITY_QUERY_NONATOMIC, /* a complete query, nonatomic
  23. * execution context */
  24. PROCESS_UTILITY_SUBCOMMAND /* a portion of a query */
  25. } ProcessUtilityContext;
  26. /* Info needed when recursing from ALTER TABLE */
  27. typedef struct AlterTableUtilityContext
  28. {
  29. PlannedStmt *pstmt; /* PlannedStmt for outer ALTER TABLE command */
  30. const char *queryString; /* its query string */
  31. Oid relid; /* OID of ALTER's target table */
  32. ParamListInfo params; /* any parameters available to ALTER TABLE */
  33. QueryEnvironment *queryEnv; /* execution environment for ALTER TABLE */
  34. } AlterTableUtilityContext;
  35. /*
  36. * These constants are used to describe the extent to which a particular
  37. * command is read-only.
  38. *
  39. * COMMAND_OK_IN_READ_ONLY_TXN means that the command is permissible even when
  40. * XactReadOnly is set. This bit should be set for commands that don't change
  41. * the state of the database (data or schema) in a way that would affect the
  42. * output of pg_dump.
  43. *
  44. * COMMAND_OK_IN_PARALLEL_MODE means that the command is permissible even
  45. * when in parallel mode. Writing tuples is forbidden, as is anything that
  46. * might confuse cooperating processes.
  47. *
  48. * COMMAND_OK_IN_RECOVERY means that the command is permissible even when in
  49. * recovery. It can't write WAL, nor can it do things that would imperil
  50. * replay of future WAL received from the primary.
  51. */
  52. #define COMMAND_OK_IN_READ_ONLY_TXN 0x0001
  53. #define COMMAND_OK_IN_PARALLEL_MODE 0x0002
  54. #define COMMAND_OK_IN_RECOVERY 0x0004
  55. /*
  56. * We say that a command is strictly read-only if it is sufficiently read-only
  57. * for all purposes. For clarity, we also have a constant for commands that are
  58. * in no way read-only.
  59. */
  60. #define COMMAND_IS_STRICTLY_READ_ONLY \
  61. (COMMAND_OK_IN_READ_ONLY_TXN | COMMAND_OK_IN_RECOVERY | \
  62. COMMAND_OK_IN_PARALLEL_MODE)
  63. #define COMMAND_IS_NOT_READ_ONLY 0
  64. /* Hook for plugins to get control in ProcessUtility() */
  65. typedef void (*ProcessUtility_hook_type) (PlannedStmt *pstmt,
  66. const char *queryString,
  67. bool readOnlyTree,
  68. ProcessUtilityContext context,
  69. ParamListInfo params,
  70. QueryEnvironment *queryEnv,
  71. DestReceiver *dest, QueryCompletion *qc);
  72. extern PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook;
  73. extern void ProcessUtility(PlannedStmt *pstmt, const char *queryString,
  74. bool readOnlyTree,
  75. ProcessUtilityContext context, ParamListInfo params,
  76. QueryEnvironment *queryEnv,
  77. DestReceiver *dest, QueryCompletion *qc);
  78. extern void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
  79. bool readOnlyTree,
  80. ProcessUtilityContext context, ParamListInfo params,
  81. QueryEnvironment *queryEnv,
  82. DestReceiver *dest, QueryCompletion *qc);
  83. extern void ProcessUtilityForAlterTable(Node *stmt,
  84. AlterTableUtilityContext *context);
  85. extern bool UtilityReturnsTuples(Node *parsetree);
  86. extern TupleDesc UtilityTupleDescriptor(Node *parsetree);
  87. extern Query *UtilityContainsQuery(Node *parsetree);
  88. extern CommandTag CreateCommandTag(Node *parsetree);
  89. static inline const char *
  90. CreateCommandName(Node *parsetree)
  91. {
  92. return GetCommandTagName(CreateCommandTag(parsetree));
  93. }
  94. extern LogStmtLevel GetCommandLogLevel(Node *parsetree);
  95. extern bool CommandIsReadOnly(PlannedStmt *pstmt);
  96. #endif /* UTILITY_H */