1/*-------------------------------------------------------------------------
2 *
3 * explain.h
4 * prototypes for explain.c
5 *
6 * Portions Copyright (c) 1996-2019, 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
20typedef enum ExplainFormat
21{
22 EXPLAIN_FORMAT_TEXT,
23 EXPLAIN_FORMAT_XML,
24 EXPLAIN_FORMAT_JSON,
25 EXPLAIN_FORMAT_YAML
26} ExplainFormat;
27
28typedef struct ExplainState
29{
30 StringInfo str; /* output buffer */
31 /* options */
32 bool verbose; /* be verbose */
33 bool analyze; /* print actual times */
34 bool costs; /* print estimated costs */
35 bool buffers; /* print buffer usage */
36 bool timing; /* print detailed node timing */
37 bool summary; /* print total planning and execution timing */
38 bool settings; /* print modified settings */
39 ExplainFormat format; /* output format */
40 /* state for output formatting --- not reset for each new plan tree */
41 int indent; /* current indentation level */
42 List *grouping_stack; /* format-specific grouping state */
43 /* state related to the current plan tree (filled by ExplainPrintPlan) */
44 PlannedStmt *pstmt; /* top of plan */
45 List *rtable; /* range table */
46 List *rtable_names; /* alias names for RTEs */
47 List *deparse_cxt; /* context list for deparsing expressions */
48 Bitmapset *printed_subplans; /* ids of SubPlans we've printed */
49} ExplainState;
50
51/* Hook for plugins to get control in ExplainOneQuery() */
52typedef void (*ExplainOneQuery_hook_type) (Query *query,
53 int cursorOptions,
54 IntoClause *into,
55 ExplainState *es,
56 const char *queryString,
57 ParamListInfo params,
58 QueryEnvironment *queryEnv);
59extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook;
60
61/* Hook for plugins to get control in explain_get_index_name() */
62typedef const char *(*explain_get_index_name_hook_type) (Oid indexId);
63extern PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook;
64
65
66extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString,
67 ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest);
68
69extern ExplainState *NewExplainState(void);
70
71extern TupleDesc ExplainResultDesc(ExplainStmt *stmt);
72
73extern void ExplainOneUtility(Node *utilityStmt, IntoClause *into,
74 ExplainState *es, const char *queryString,
75 ParamListInfo params, QueryEnvironment *queryEnv);
76
77extern void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into,
78 ExplainState *es, const char *queryString,
79 ParamListInfo params, QueryEnvironment *queryEnv,
80 const instr_time *planduration);
81
82extern void ExplainPrintPlan(ExplainState *es, QueryDesc *queryDesc);
83extern void ExplainPrintTriggers(ExplainState *es, QueryDesc *queryDesc);
84
85extern void ExplainPrintJITSummary(ExplainState *es, QueryDesc *queryDesc);
86extern void ExplainPrintJIT(ExplainState *es, int jit_flags,
87 struct JitInstrumentation *jit_instr, int worker_i);
88
89extern void ExplainQueryText(ExplainState *es, QueryDesc *queryDesc);
90
91extern void ExplainBeginOutput(ExplainState *es);
92extern void ExplainEndOutput(ExplainState *es);
93extern void ExplainSeparatePlans(ExplainState *es);
94
95extern void ExplainPropertyList(const char *qlabel, List *data,
96 ExplainState *es);
97extern void ExplainPropertyListNested(const char *qlabel, List *data,
98 ExplainState *es);
99extern void ExplainPropertyText(const char *qlabel, const char *value,
100 ExplainState *es);
101extern void ExplainPropertyInteger(const char *qlabel, const char *unit,
102 int64 value, ExplainState *es);
103extern void ExplainPropertyFloat(const char *qlabel, const char *unit,
104 double value, int ndigits, ExplainState *es);
105extern void ExplainPropertyBool(const char *qlabel, bool value,
106 ExplainState *es);
107
108extern void ExplainOpenGroup(const char *objtype, const char *labelname,
109 bool labeled, ExplainState *es);
110extern void ExplainCloseGroup(const char *objtype, const char *labelname,
111 bool labeled, ExplainState *es);
112
113#endif /* EXPLAIN_H */
114