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-2024, 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 
21 {
26 
27 typedef enum ExplainFormat
28 {
34 
35 typedef struct ExplainWorkersState
36 {
37  int num_workers; /* # of worker processes the plan used */
38  bool *worker_inited; /* per-worker state-initialized flags */
39  StringInfoData *worker_str; /* per-worker transient output buffers */
40  int *worker_state_save; /* per-worker grouping state save areas */
41  StringInfo prev_str; /* saved output buffer while redirecting */
43 
44 typedef struct ExplainState
45 {
46  StringInfo str; /* output buffer */
47  /* options */
48  bool verbose; /* be verbose */
49  bool analyze; /* print actual times */
50  bool costs; /* print estimated costs */
51  bool buffers; /* print buffer usage */
52  bool wal; /* print WAL usage */
53  bool timing; /* print detailed node timing */
54  bool summary; /* print total planning and execution timing */
55  bool memory; /* print planner's memory usage information */
56  bool settings; /* print modified settings */
57  bool generic; /* generate a generic plan */
58  ExplainSerializeOption serialize; /* serialize the query's output? */
59  ExplainFormat format; /* output format */
60  /* state for output formatting --- not reset for each new plan tree */
61  int indent; /* current indentation level */
62  List *grouping_stack; /* format-specific grouping state */
63  /* state related to the current plan tree (filled by ExplainPrintPlan) */
64  PlannedStmt *pstmt; /* top of plan */
65  List *rtable; /* range table */
66  List *rtable_names; /* alias names for RTEs */
67  List *deparse_cxt; /* context list for deparsing expressions */
68  Bitmapset *printed_subplans; /* ids of SubPlans we've printed */
69  bool hide_workers; /* set if we find an invisible Gather */
70  /* state related to the current plan node */
71  ExplainWorkersState *workers_state; /* needed if parallel plan */
73 
74 /* Hook for plugins to get control in ExplainOneQuery() */
75 typedef void (*ExplainOneQuery_hook_type) (Query *query,
76  int cursorOptions,
77  IntoClause *into,
78  ExplainState *es,
79  const char *queryString,
80  ParamListInfo params,
81  QueryEnvironment *queryEnv);
83 
84 /* Hook for plugins to get control in explain_get_index_name() */
85 typedef const char *(*explain_get_index_name_hook_type) (Oid indexId);
87 
88 
89 extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
91 extern void standard_ExplainOneQuery(Query *query, int cursorOptions,
92  IntoClause *into, ExplainState *es,
93  const char *queryString, ParamListInfo params,
94  QueryEnvironment *queryEnv);
95 
96 extern ExplainState *NewExplainState(void);
97 
99 
100 extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
101  ExplainState *es, const char *queryString,
102  ParamListInfo params, QueryEnvironment *queryEnv);
103 
104 extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
105  ExplainState *es, const char *queryString,
106  ParamListInfo params, QueryEnvironment *queryEnv,
107  const instr_time *planduration,
108  const BufferUsage *bufusage,
109  const MemoryContextCounters *mem_counters);
110 
111 extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
112 extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
113 
114 extern void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc);
115 
116 extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
117 extern void ExplainQueryParameters(ExplainState *es, ParamListInfo params, int maxlen);
118 
119 extern void ExplainBeginOutput(ExplainState *es);
120 extern void ExplainEndOutput(ExplainState *es);
121 extern void ExplainSeparatePlans(ExplainState *es);
122 
123 extern void ExplainPropertyList(const char *qlabel, List *data,
124  ExplainState *es);
125 extern void ExplainPropertyListNested(const char *qlabel, List *data,
126  ExplainState *es);
127 extern void ExplainPropertyText(const char *qlabel, const char *value,
128  ExplainState *es);
129 extern void ExplainPropertyInteger(const char *qlabel, const char *unit,
130  int64 value, ExplainState *es);
131 extern void ExplainPropertyUInteger(const char *qlabel, const char *unit,
132  uint64 value, ExplainState *es);
133 extern void ExplainPropertyFloat(const char *qlabel, const char *unit,
134  double value, int ndigits, ExplainState *es);
135 extern void ExplainPropertyBool(const char *qlabel, bool value,
136  ExplainState *es);
137 
138 extern void ExplainOpenGroup(const char *objtype, const char *labelname,
139  bool labeled, ExplainState *es);
140 extern void ExplainCloseGroup(const char *objtype, const char *labelname,
141  bool labeled, ExplainState *es);
142 
144 
145 #endif /* EXPLAIN_H */
#define PGDLLIMPORT
Definition: c.h:1316
void ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es)
Definition: explain.c:4801
ExplainSerializeOption
Definition: explain.h:21
@ EXPLAIN_SERIALIZE_TEXT
Definition: explain.h:23
@ EXPLAIN_SERIALIZE_NONE
Definition: explain.h:22
@ EXPLAIN_SERIALIZE_BINARY
Definition: explain.h:24
void ExplainOpenGroup(const char *objtype, const char *labelname, bool labeled, ExplainState *es)
Definition: explain.c:4866
void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, const instr_time *planduration, const BufferUsage *bufusage, const MemoryContextCounters *mem_counters)
Definition: explain.c:616
void ExplainPropertyUInteger(const char *qlabel, const char *unit, uint64 value, ExplainState *es)
Definition: explain.c:4823
PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook
Definition: explain.c:48
PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook
Definition: explain.c:45
void ExplainPropertyInteger(const char *qlabel, const char *unit, int64 value, ExplainState *es)
Definition: explain.c:4810
void ExplainPropertyListNested(const char *qlabel, List *data, ExplainState *es)
Definition: explain.c:4695
DestReceiver * CreateExplainSerializeDestReceiver(ExplainState *es)
Definition: explain.c:5555
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:182
void ExplainSeparatePlans(ExplainState *es)
Definition: explain.c:5182
void(* ExplainOneQuery_hook_type)(Query *query, int cursorOptions, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.h:75
void ExplainEndOutput(ExplainState *es)
Definition: explain.c:5153
void ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.c:526
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:388
void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:984
void ExplainPropertyFloat(const char *qlabel, const char *unit, double value, int ndigits, ExplainState *es)
Definition: explain.c:4837
void ExplainCloseGroup(const char *objtype, const char *labelname, bool labeled, ExplainState *es)
Definition: explain.c:4929
struct ExplainWorkersState ExplainWorkersState
void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:1168
void ExplainBeginOutput(ExplainState *es)
Definition: explain.c:5122
ExplainState * NewExplainState(void)
Definition: explain.c:371
ExplainFormat
Definition: explain.h:28
@ EXPLAIN_FORMAT_XML
Definition: explain.h:30
@ EXPLAIN_FORMAT_YAML
Definition: explain.h:32
@ EXPLAIN_FORMAT_TEXT
Definition: explain.h:29
@ EXPLAIN_FORMAT_JSON
Definition: explain.h:31
void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:876
void ExplainQueryParameters(ExplainState *es, ParamListInfo params, int maxlen)
Definition: explain.c:1183
struct ExplainState ExplainState
const char *(* explain_get_index_name_hook_type)(Oid indexId)
Definition: explain.h:85
void ExplainPropertyBool(const char *qlabel, bool value, ExplainState *es)
Definition: explain.c:4851
void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:941
void standard_ExplainOneQuery(Query *query, int cursorOptions, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.c:454
void ExplainPropertyList(const char *qlabel, List *data, ExplainState *es)
Definition: explain.c:4625
#define stmt
Definition: indent_codes.h:59
static struct @155 value
const void * data
unsigned int Oid
Definition: postgres_ext.h:31
bool verbose
Definition: explain.h:48
bool settings
Definition: explain.h:56
Bitmapset * printed_subplans
Definition: explain.h:68
bool hide_workers
Definition: explain.h:69
bool timing
Definition: explain.h:53
List * grouping_stack
Definition: explain.h:62
List * rtable_names
Definition: explain.h:66
ExplainWorkersState * workers_state
Definition: explain.h:71
bool analyze
Definition: explain.h:49
StringInfo str
Definition: explain.h:46
ExplainFormat format
Definition: explain.h:59
bool wal
Definition: explain.h:52
List * rtable
Definition: explain.h:65
PlannedStmt * pstmt
Definition: explain.h:64
bool memory
Definition: explain.h:55
bool summary
Definition: explain.h:54
ExplainSerializeOption serialize
Definition: explain.h:58
bool costs
Definition: explain.h:50
bool buffers
Definition: explain.h:51
int indent
Definition: explain.h:61
List * deparse_cxt
Definition: explain.h:67
StringInfoData * worker_str
Definition: explain.h:39
bool * worker_inited
Definition: explain.h:38
int * worker_state_save
Definition: explain.h:40
StringInfo prev_str
Definition: explain.h:41
Definition: pg_list.h:54
Definition: nodes.h:129