PostgreSQL Source Code  git master
explain.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * explain.h
4  * prototypes for explain.c
5  *
6  * Portions Copyright (c) 1996-2020, 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 
16 #include "executor/executor.h"
17 #include "lib/stringinfo.h"
18 #include "parser/parse_node.h"
19 
20 typedef enum ExplainFormat
21 {
27 
28 typedef struct ExplainWorkersState
29 {
30  int num_workers; /* # of worker processes the plan used */
31  bool *worker_inited; /* per-worker state-initialized flags */
32  StringInfoData *worker_str; /* per-worker transient output buffers */
33  int *worker_state_save; /* per-worker grouping state save areas */
34  StringInfo prev_str; /* saved output buffer while redirecting */
36 
37 typedef struct ExplainState
38 {
39  StringInfo str; /* output buffer */
40  /* options */
41  bool verbose; /* be verbose */
42  bool analyze; /* print actual times */
43  bool costs; /* print estimated costs */
44  bool buffers; /* print buffer usage */
45  bool wal; /* print WAL usage */
46  bool timing; /* print detailed node timing */
47  bool summary; /* print total planning and execution timing */
48  bool settings; /* print modified settings */
49  ExplainFormat format; /* output format */
50  /* state for output formatting --- not reset for each new plan tree */
51  int indent; /* current indentation level */
52  List *grouping_stack; /* format-specific grouping state */
53  /* state related to the current plan tree (filled by ExplainPrintPlan) */
54  PlannedStmt *pstmt; /* top of plan */
55  List *rtable; /* range table */
56  List *rtable_names; /* alias names for RTEs */
57  List *deparse_cxt; /* context list for deparsing expressions */
58  Bitmapset *printed_subplans; /* ids of SubPlans we've printed */
59  bool hide_workers; /* set if we find an invisible Gather */
60  /* state related to the current plan node */
61  ExplainWorkersState *workers_state; /* needed if parallel plan */
62 } ExplainState;
63 
64 /* Hook for plugins to get control in ExplainOneQuery() */
65 typedef void (*ExplainOneQuery_hook_type) (Query *query,
66  int cursorOptions,
67  IntoClause *into,
68  ExplainState *es,
69  const char *queryString,
70  ParamListInfo params,
71  QueryEnvironment *queryEnv);
73 
74 /* Hook for plugins to get control in explain_get_index_name() */
75 typedef const char *(*explain_get_index_name_hook_type) (Oid indexId);
77 
78 
79 extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
81 
82 extern ExplainState *NewExplainState(void);
83 
85 
86 extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
87  ExplainState *es, const char *queryString,
88  ParamListInfo params, QueryEnvironment *queryEnv);
89 
90 extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
91  ExplainState *es, const char *queryString,
92  ParamListInfo params, QueryEnvironment *queryEnv,
93  const instr_time *planduration,
94  const BufferUsage *bufusage);
95 
96 extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
97 extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
98 
99 extern void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc);
100 
101 extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
102 
103 extern void ExplainBeginOutput(ExplainState *es);
104 extern void ExplainEndOutput(ExplainState *es);
105 extern void ExplainSeparatePlans(ExplainState *es);
106 
107 extern void ExplainPropertyList(const char *qlabel, List *data,
108  ExplainState *es);
109 extern void ExplainPropertyListNested(const char *qlabel, List *data,
110  ExplainState *es);
111 extern void ExplainPropertyText(const char *qlabel, const char *value,
112  ExplainState *es);
113 extern void ExplainPropertyInteger(const char *qlabel, const char *unit,
114  int64 value, ExplainState *es);
115 extern void ExplainPropertyUInteger(const char *qlabel, const char *unit,
116  uint64 value, ExplainState *es);
117 extern void ExplainPropertyFloat(const char *qlabel, const char *unit,
118  double value, int ndigits, ExplainState *es);
119 extern void ExplainPropertyBool(const char *qlabel, bool value,
120  ExplainState *es);
121 
122 extern void ExplainOpenGroup(const char *objtype, const char *labelname,
123  bool labeled, ExplainState *es);
124 extern void ExplainCloseGroup(const char *objtype, const char *labelname,
125  bool labeled, ExplainState *es);
126 
127 #endif /* EXPLAIN_H */
PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook
Definition: explain.c:47
int * worker_state_save
Definition: explain.h:33
bool summary
Definition: explain.h:47
ExplainFormat
Definition: explain.h:20
bool hide_workers
Definition: explain.h:59
void ExplainCloseGroup(const char *objtype, const char *labelname, bool labeled, ExplainState *es)
Definition: explain.c:4356
Bitmapset * printed_subplans
Definition: explain.h:58
struct timeval instr_time
Definition: instr_time.h:150
Definition: nodes.h:529
List * deparse_cxt
Definition: explain.h:57
struct ExplainWorkersState ExplainWorkersState
unsigned int Oid
Definition: postgres_ext.h:31
bool costs
Definition: explain.h:43
bool analyze
Definition: explain.h:42
void ExplainPropertyInteger(const char *qlabel, const char *unit, int64 value, ExplainState *es)
Definition: explain.c:4237
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:322
void ExplainPropertyBool(const char *qlabel, bool value, ExplainState *es)
Definition: explain.c:4278
PlannedStmt * pstmt
Definition: explain.h:54
void ExplainPropertyListNested(const char *qlabel, List *data, ExplainState *es)
Definition: explain.c:4122
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:161
List * rtable_names
Definition: explain.h:56
#define PGDLLIMPORT
Definition: c.h:1257
struct ExplainState ExplainState
void ExplainEndOutput(ExplainState *es)
Definition: explain.c:4580
StringInfoData * worker_str
Definition: explain.h:32
List * grouping_stack
Definition: explain.h:52
int indent
Definition: explain.h:51
PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook
Definition: explain.c:44
void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, const instr_time *planduration, const BufferUsage *bufusage)
Definition: explain.c:496
void ExplainPropertyList(const char *qlabel, List *data, ExplainState *es)
Definition: explain.c:4052
bool timing
Definition: explain.h:46
void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:768
void ExplainBeginOutput(ExplainState *es)
Definition: explain.c:4549
void ExplainPropertyUInteger(const char *qlabel, const char *unit, uint64 value, ExplainState *es)
Definition: explain.c:4250
bool verbose
Definition: explain.h:41
static struct @143 value
void ExplainOpenGroup(const char *objtype, const char *labelname, bool labeled, ExplainState *es)
Definition: explain.c:4293
bool * worker_inited
Definition: explain.h:31
void ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.c:421
bool wal
Definition: explain.h:45
ExplainWorkersState * workers_state
Definition: explain.h:61
ExplainFormat format
Definition: explain.h:49
void ExplainSeparatePlans(ExplainState *es)
Definition: explain.c:4609
const char *(* explain_get_index_name_hook_type)(Oid indexId)
Definition: explain.h:75
StringInfo prev_str
Definition: explain.h:34
void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:934
void(* ExplainOneQuery_hook_type)(Query *query, int cursorOptions, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.h:65
ExplainState * NewExplainState(void)
Definition: explain.c:305
void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:814
bool buffers
Definition: explain.h:44
void ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es)
Definition: explain.c:4228
Definition: pg_list.h:50
StringInfo str
Definition: explain.h:39
bool settings
Definition: explain.h:48
void ExplainPropertyFloat(const char *qlabel, const char *unit, double value, int ndigits, ExplainState *es)
Definition: explain.c:4264
List * rtable
Definition: explain.h:55
void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:719