1 /*-------------------------------------------------------------------------
4 * prototypes for explain.c
6 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994-5, Regents of the University of California
9 * src/include/commands/explain.h
11 *-------------------------------------------------------------------------
16 #include "executor/executor.h"
17 #include "lib/stringinfo.h"
18 #include "parser/parse_node.h"
20 typedef enum ExplainFormat
28 typedef struct ExplainWorkersState
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 */
35 } ExplainWorkersState
;
37 typedef struct ExplainState
39 StringInfo str
; /* output buffer */
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 */
64 /* Hook for plugins to get control in ExplainOneQuery() */
65 typedef void (*ExplainOneQuery_hook_type
) (Query
*query
,
69 const char *queryString
,
71 QueryEnvironment
*queryEnv
);
72 extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook
;
74 /* Hook for plugins to get control in explain_get_index_name() */
75 typedef const char *(*explain_get_index_name_hook_type
) (Oid indexId
);
76 extern PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook
;
79 extern void ExplainQuery(ParseState
*pstate
, ExplainStmt
*stmt
,
80 ParamListInfo params
, DestReceiver
*dest
);
82 extern ExplainState
*NewExplainState(void);
84 extern TupleDesc
ExplainResultDesc(ExplainStmt
*stmt
);
86 extern void ExplainOneUtility(Node
*utilityStmt
, IntoClause
*into
,
87 ExplainState
*es
, const char *queryString
,
88 ParamListInfo params
, QueryEnvironment
*queryEnv
);
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
);
96 extern void ExplainPrintPlan(ExplainState
*es
, QueryDesc
*queryDesc
);
97 extern void ExplainPrintTriggers(ExplainState
*es
, QueryDesc
*queryDesc
);
99 extern void ExplainPrintJITSummary(ExplainState
*es
, QueryDesc
*queryDesc
);
101 extern void ExplainQueryText(ExplainState
*es
, QueryDesc
*queryDesc
);
103 extern void ExplainBeginOutput(ExplainState
*es
);
104 extern void ExplainEndOutput(ExplainState
*es
);
105 extern void ExplainSeparatePlans(ExplainState
*es
);
107 extern void ExplainPropertyList(const char *qlabel
, List
*data
,
109 extern void ExplainPropertyListNested(const char *qlabel
, List
*data
,
111 extern void ExplainPropertyText(const char *qlabel
, const char *value
,
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
,
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
);
127 #endif /* EXPLAIN_H */