2
0

explain.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*-------------------------------------------------------------------------
  2. *
  3. * explain.h
  4. * prototypes for explain.c
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994-5, Regents of the University of California
  8. *
  9. * src/include/commands/explain.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef EXPLAIN_H
  14. #define EXPLAIN_H
  15. #include "executor/executor.h"
  16. #include "lib/stringinfo.h"
  17. #include "parser/parse_node.h"
  18. typedef enum ExplainFormat
  19. {
  20. EXPLAIN_FORMAT_TEXT,
  21. EXPLAIN_FORMAT_XML,
  22. EXPLAIN_FORMAT_JSON,
  23. EXPLAIN_FORMAT_YAML
  24. } ExplainFormat;
  25. typedef struct ExplainWorkersState
  26. {
  27. int num_workers; /* # of worker processes the plan used */
  28. bool *worker_inited; /* per-worker state-initialized flags */
  29. StringInfoData *worker_str; /* per-worker transient output buffers */
  30. int *worker_state_save; /* per-worker grouping state save areas */
  31. StringInfo prev_str; /* saved output buffer while redirecting */
  32. } ExplainWorkersState;
  33. typedef struct ExplainState
  34. {
  35. StringInfo str; /* output buffer */
  36. /* options */
  37. bool verbose; /* be verbose */
  38. bool analyze; /* print actual times */
  39. bool costs; /* print estimated costs */
  40. bool buffers; /* print buffer usage */
  41. bool wal; /* print WAL usage */
  42. bool timing; /* print detailed node timing */
  43. bool summary; /* print total planning and execution timing */
  44. bool settings; /* print modified settings */
  45. ExplainFormat format; /* output format */
  46. /* state for output formatting --- not reset for each new plan tree */
  47. int indent; /* current indentation level */
  48. List *grouping_stack; /* format-specific grouping state */
  49. /* state related to the current plan tree (filled by ExplainPrintPlan) */
  50. PlannedStmt *pstmt; /* top of plan */
  51. List *rtable; /* range table */
  52. List *rtable_names; /* alias names for RTEs */
  53. List *deparse_cxt; /* context list for deparsing expressions */
  54. Bitmapset *printed_subplans; /* ids of SubPlans we've printed */
  55. bool hide_workers; /* set if we find an invisible Gather */
  56. /* state related to the current plan node */
  57. ExplainWorkersState *workers_state; /* needed if parallel plan */
  58. } ExplainState;
  59. /* Hook for plugins to get control in ExplainOneQuery() */
  60. typedef void (*ExplainOneQuery_hook_type) (Query *query,
  61. int cursorOptions,
  62. IntoClause *into,
  63. ExplainState *es,
  64. const char *queryString,
  65. ParamListInfo params,
  66. QueryEnvironment *queryEnv);
  67. extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook;
  68. /* Hook for plugins to get control in explain_get_index_name() */
  69. typedef const char *(*explain_get_index_name_hook_type) (Oid indexId);
  70. extern PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook;
  71. extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
  72. ParamListInfo params, DestReceiver *dest);
  73. extern ExplainState *NewExplainState(void);
  74. extern TupleDesc ExplainResultDesc(ExplainStmt *stmt);
  75. extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
  76. ExplainState *es, const char *queryString,
  77. ParamListInfo params, QueryEnvironment *queryEnv);
  78. extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
  79. ExplainState *es, const char *queryString,
  80. ParamListInfo params, QueryEnvironment *queryEnv,
  81. const instr_time *planduration,
  82. const BufferUsage *bufusage);
  83. extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
  84. extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
  85. extern void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc);
  86. extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
  87. extern void ExplainBeginOutput(ExplainState *es);
  88. extern void ExplainEndOutput(ExplainState *es);
  89. extern void ExplainSeparatePlans(ExplainState *es);
  90. extern void ExplainPropertyList(const char *qlabel, List *data,
  91. ExplainState *es);
  92. extern void ExplainPropertyListNested(const char *qlabel, List *data,
  93. ExplainState *es);
  94. extern void ExplainPropertyText(const char *qlabel, const char *value,
  95. ExplainState *es);
  96. extern void ExplainPropertyInteger(const char *qlabel, const char *unit,
  97. int64 value, ExplainState *es);
  98. extern void ExplainPropertyUInteger(const char *qlabel, const char *unit,
  99. uint64 value, ExplainState *es);
  100. extern void ExplainPropertyFloat(const char *qlabel, const char *unit,
  101. double value, int ndigits, ExplainState *es);
  102. extern void ExplainPropertyBool(const char *qlabel, bool value,
  103. ExplainState *es);
  104. extern void ExplainOpenGroup(const char *objtype, const char *labelname,
  105. bool labeled, ExplainState *es);
  106. extern void ExplainCloseGroup(const char *objtype, const char *labelname,
  107. bool labeled, ExplainState *es);
  108. #endif /* EXPLAIN_H */