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  int rtable_size; /* length of rtable excluding the RTE_GROUP
71  * entry */
72  /* state related to the current plan node */
73  ExplainWorkersState *workers_state; /* needed if parallel plan */
75 
76 /* Hook for plugins to get control in ExplainOneQuery() */
77 typedef void (*ExplainOneQuery_hook_type) (Query *query,
78  int cursorOptions,
79  IntoClause *into,
80  ExplainState *es,
81  const char *queryString,
82  ParamListInfo params,
83  QueryEnvironment *queryEnv);
85 
86 /* Hook for plugins to get control in explain_get_index_name() */
87 typedef const char *(*explain_get_index_name_hook_type) (Oid indexId);
89 
90 
91 extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
93 extern void standard_ExplainOneQuery(Query *query, int cursorOptions,
94  IntoClause *into, ExplainState *es,
95  const char *queryString, ParamListInfo params,
96  QueryEnvironment *queryEnv);
97 
98 extern ExplainState *NewExplainState(void);
99 
101 
102 extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
103  ExplainState *es, const char *queryString,
104  ParamListInfo params, QueryEnvironment *queryEnv);
105 
106 extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
107  ExplainState *es, const char *queryString,
108  ParamListInfo params, QueryEnvironment *queryEnv,
109  const instr_time *planduration,
110  const BufferUsage *bufusage,
111  const MemoryContextCounters *mem_counters);
112 
113 extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
114 extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
115 
116 extern void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc);
117 
118 extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
119 extern void ExplainQueryParameters(ExplainState *es, ParamListInfo params, int maxlen);
120 
121 extern void ExplainBeginOutput(ExplainState *es);
122 extern void ExplainEndOutput(ExplainState *es);
123 extern void ExplainSeparatePlans(ExplainState *es);
124 
125 extern void ExplainPropertyList(const char *qlabel, List *data,
126  ExplainState *es);
127 extern void ExplainPropertyListNested(const char *qlabel, List *data,
128  ExplainState *es);
129 extern void ExplainPropertyText(const char *qlabel, const char *value,
130  ExplainState *es);
131 extern void ExplainPropertyInteger(const char *qlabel, const char *unit,
132  int64 value, ExplainState *es);
133 extern void ExplainPropertyUInteger(const char *qlabel, const char *unit,
134  uint64 value, ExplainState *es);
135 extern void ExplainPropertyFloat(const char *qlabel, const char *unit,
136  double value, int ndigits, ExplainState *es);
137 extern void ExplainPropertyBool(const char *qlabel, bool value,
138  ExplainState *es);
139 
140 extern void ExplainOpenGroup(const char *objtype, const char *labelname,
141  bool labeled, ExplainState *es);
142 extern void ExplainCloseGroup(const char *objtype, const char *labelname,
143  bool labeled, ExplainState *es);
144 
146 
147 #endif /* EXPLAIN_H */
#define PGDLLIMPORT
Definition: c.h:1316
void ExplainPropertyText(const char *qlabel, const char *value, ExplainState *es)
Definition: explain.c:4899
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:4964
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:618
void ExplainPropertyUInteger(const char *qlabel, const char *unit, uint64 value, ExplainState *es)
Definition: explain.c:4921
PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook
Definition: explain.c:49
PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook
Definition: explain.c:46
void ExplainPropertyInteger(const char *qlabel, const char *unit, int64 value, ExplainState *es)
Definition: explain.c:4908
void ExplainPropertyListNested(const char *qlabel, List *data, ExplainState *es)
Definition: explain.c:4793
DestReceiver * CreateExplainSerializeDestReceiver(ExplainState *es)
Definition: explain.c:5653
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:184
void ExplainSeparatePlans(ExplainState *es)
Definition: explain.c:5280
void(* ExplainOneQuery_hook_type)(Query *query, int cursorOptions, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.h:77
void ExplainEndOutput(ExplainState *es)
Definition: explain.c:5251
void ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.c:528
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:390
void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:998
void ExplainPropertyFloat(const char *qlabel, const char *unit, double value, int ndigits, ExplainState *es)
Definition: explain.c:4935
void ExplainCloseGroup(const char *objtype, const char *labelname, bool labeled, ExplainState *es)
Definition: explain.c:5027
struct ExplainWorkersState ExplainWorkersState
void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:1182
void ExplainBeginOutput(ExplainState *es)
Definition: explain.c:5220
ExplainState * NewExplainState(void)
Definition: explain.c:373
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:878
void ExplainQueryParameters(ExplainState *es, ParamListInfo params, int maxlen)
Definition: explain.c:1197
struct ExplainState ExplainState
const char *(* explain_get_index_name_hook_type)(Oid indexId)
Definition: explain.h:87
void ExplainPropertyBool(const char *qlabel, bool value, ExplainState *es)
Definition: explain.c:4949
void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc)
Definition: explain.c:955
void standard_ExplainOneQuery(Query *query, int cursorOptions, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
Definition: explain.c:456
void ExplainPropertyList(const char *qlabel, List *data, ExplainState *es)
Definition: explain.c:4723
#define stmt
Definition: indent_codes.h:59
static struct @157 value
const void * data
unsigned int Oid
Definition: postgres_ext.h:31
bool verbose
Definition: explain.h:48
bool settings
Definition: explain.h:56
int rtable_size
Definition: explain.h:70
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:73
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