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 timing; /* print detailed node timing */
46  bool summary; /* print total planning and execution timing */
47  bool settings; /* print modified settings */
48  ExplainFormat format; /* output format */
49  /* state for output formatting --- not reset for each new plan tree */
50  int indent; /* current indentation level */
51  List *grouping_stack; /* format-specific grouping state */
52  /* state related to the current plan tree (filled by ExplainPrintPlan) */
53  PlannedStmt *pstmt; /* top of plan */
54  List *rtable; /* range table */
55  List *rtable_names; /* alias names for RTEs */
56  List *deparse_cxt; /* context list for deparsing expressions */
57  Bitmapset *printed_subplans; /* ids of SubPlans we've printed */
58  bool hide_workers; /* set if we find an invisible Gather */
59  /* state related to the current plan node */
60  ExplainWorkersState *workers_state; /* needed if parallel plan */
61 } ExplainState;
62 
63 /* Hook for plugins to get control in ExplainOneQuery() */
64 typedef void (*ExplainOneQuery_hook_type) (Query *query,
65  int cursorOptions,
66  IntoClause *into,
67  ExplainState *es,
68  const char *queryString,
69  ParamListInfo params,
70  QueryEnvironment *queryEnv);
72 
73 /* Hook for plugins to get control in explain_get_index_name() */
74 typedef const char *(*explain_get_index_name_hook_type) (Oid indexId);
76 
77 
78 extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
80 
81 extern ExplainState *NewExplainState(void);
82 
84 
85 extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
86  ExplainState *es, const char *queryString,
87  ParamListInfo params, QueryEnvironment *queryEnv);
88 
89 extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
90  ExplainState *es, const char *queryString,
91  ParamListInfo params, QueryEnvironment *queryEnv,
92  const instr_time *planduration);
93 
94 extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
95 extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
96 
97 extern void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc);
98 
99 extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
100 
101 extern void ExplainBeginOutput(ExplainState *es);
102 extern void ExplainEndOutput(ExplainState *es);
103 extern void ExplainSeparatePlans(ExplainState *es);
104 
105 extern void ExplainPropertyList(const char *qlabel, List *data,
106  ExplainState *es);
107 extern void ExplainPropertyListNested(const char *qlabel, List *data,
108  ExplainState *es);
109 extern void ExplainPropertyText(const char *qlabel, const char *value,
110  ExplainState *es);
111 extern void ExplainPropertyInteger(const char *qlabel, const char *unit,
112  int64 value, ExplainState *es);
113 extern void ExplainPropertyFloat(const char *qlabel, const char *unit,
114  double value, int ndigits, ExplainState *es);
115 extern void ExplainPropertyBool(const char *qlabel, bool value,
116  ExplainState *es);
117 
118 extern void ExplainOpenGroup(const char *objtype, const char *labelname,
119  bool labeled, ExplainState *es);
120 extern void ExplainCloseGroup(const char *objtype, const char *labelname,
121  bool labeled, ExplainState *es);
122 
123 #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:46
ExplainFormat
Definition: explain.h:20
bool hide_workers
Definition: explain.h:58
void ExplainCloseGroup(const char *objtype, const char *labelname, bool labeled, ExplainState *es)
Definition: explain.c:3906
Bitmapset * printed_subplans
Definition: explain.h:57
struct timeval instr_time
Definition: instr_time.h:150
static struct @145 value
Definition: nodes.h:525
List * deparse_cxt
Definition: explain.h:56
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:3800
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:313
void ExplainPropertyBool(const char *qlabel, bool value, ExplainState *es)
Definition: explain.c:3828
PlannedStmt * pstmt
Definition: explain.h:53
void ExplainPropertyListNested(const char *qlabel, List *data, ExplainState *es)
Definition: explain.c:3685
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:154
List * rtable_names
Definition: explain.h:55
#define PGDLLIMPORT
Definition: c.h:1276
struct ExplainState ExplainState
void ExplainEndOutput(ExplainState *es)
Definition: explain.c:4130
StringInfoData * worker_str
Definition: explain.h:32
List * grouping_stack
Definition: explain.h:51
int indent
Definition: explain.h:50
PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook
Definition: explain.c:44
void ExplainPropertyList(const char *qlabel, List *data, ExplainState *es)
Definition: explain.c:3615
bool timing
Definition: explain.h:45
void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:737
void ExplainBeginOutput(ExplainState *es)
Definition: explain.c:4099
bool verbose
Definition: explain.h:41
void ExplainOpenGroup(const char *objtype, const char *labelname, bool labeled, ExplainState *es)
Definition: explain.c:3843
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:401
ExplainWorkersState * workers_state
Definition: explain.h:60
ExplainFormat format
Definition: explain.h:48
void ExplainSeparatePlans(ExplainState *es)
Definition: explain.c:4159
const char *(* explain_get_index_name_hook_type)(Oid indexId)
Definition: explain.h:74
StringInfo prev_str
Definition: explain.h:34
void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:903
void(* ExplainOneQuery_hook_type)(Query *query, int cursorOptions, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.h:64
ExplainState * NewExplainState(void)
Definition: explain.c:296
void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:783
bool buffers
Definition: explain.h:44
void ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es)
Definition: explain.c:3791
void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, const instr_time *planduration)
Definition: explain.c:476
Definition: pg_list.h:50
StringInfo str
Definition: explain.h:39
bool settings
Definition: explain.h:47
void ExplainPropertyFloat(const char *qlabel, const char *unit, double value, int ndigits, ExplainState *es)
Definition: explain.c:3814
List * rtable
Definition: explain.h:54
void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:688