-
Notifications
You must be signed in to change notification settings - Fork 540
Expand file tree
/
Copy pathexplain_plan_output.go
More file actions
156 lines (133 loc) · 5.33 KB
/
explain_plan_output.go
File metadata and controls
156 lines (133 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package database_observability
type ExplainPlanOutputOperation string
const (
ExplainPlanOutputOperationTableScan ExplainPlanOutputOperation = "Table Scan"
ExplainPlanOutputOperationIndexScan ExplainPlanOutputOperation = "Index Scan"
ExplainPlanOutputOperationNestedLoopJoin ExplainPlanOutputOperation = "Nested Loop Join"
ExplainPlanOutputOperationHashJoin ExplainPlanOutputOperation = "Hash Join"
ExplainPlanOutputOperationMergeJoin ExplainPlanOutputOperation = "Merge Join"
ExplainPlanOutputOperationGroupingOperation ExplainPlanOutputOperation = "Grouping Operation"
ExplainPlanOutputOperationOrderingOperation ExplainPlanOutputOperation = "Ordering Operation"
ExplainPlanOutputOperationDuplicatesRemoval ExplainPlanOutputOperation = "Duplicates Removal"
ExplainPlanOutputOperationMaterializedSubquery ExplainPlanOutputOperation = "Materialized Subquery"
ExplainPlanOutputOperationAttachedSubquery ExplainPlanOutputOperation = "Attached Subquery"
ExplainPlanOutputOperationUnion ExplainPlanOutputOperation = "Union"
ExplainPlanOutputOperationUnknown ExplainPlanOutputOperation = "Unknown"
)
type ExplainPlanAccessType string
const (
ExplainPlanAccessTypeAll ExplainPlanAccessType = "all"
ExplainPlanAccessTypeIndex ExplainPlanAccessType = "index"
ExplainPlanAccessTypeRange ExplainPlanAccessType = "range"
ExplainPlanAccessTypeRef ExplainPlanAccessType = "ref"
ExplainPlanAccessTypeEqRef ExplainPlanAccessType = "eq_ref"
)
type ExplainPlanJoinAlgorithm string
const (
ExplainPlanJoinAlgorithmHash ExplainPlanJoinAlgorithm = "hash"
ExplainPlanJoinAlgorithmMerge ExplainPlanJoinAlgorithm = "merge"
ExplainPlanJoinAlgorithmNestedLoop ExplainPlanJoinAlgorithm = "nested_loop"
)
type ExplainProcessingResult string
const (
ExplainProcessingResultSuccess ExplainProcessingResult = "success"
ExplainProcessingResultError ExplainProcessingResult = "error"
ExplainProcessingResultSkipped ExplainProcessingResult = "skipped"
)
type ExplainReservedWordMetadata struct {
ExemptionPrefixes *[]string
}
// ExplainReservedWordDenyList contains SQL reserved words that indicate write operations
// to the database. These are primarily DML (Data Manipulation Language) and DDL
// (Data Definition Language) commands that modify database state.
// This was extracted from the MySQL and PostgreSQL documentation by Claude Sonnet 4 on Oct 28, 2025
// and audited by @rgeyer and others in the dbo11y team.
var ExplainReservedWordDenyList = map[string]ExplainReservedWordMetadata{
// Data Manipulation Language (DML) - Write operations
"INSERT": {},
"UPDATE": {
ExemptionPrefixes: &[]string{"FOR"},
},
"DELETE": {},
"REPLACE": {},
"MERGE": {},
"UPSERT": {},
// Data Definition Language (DDL) - Schema modifications
"CREATE": {},
"ALTER": {},
"DROP": {},
"RENAME": {},
"TRUNCATE": {},
// Transaction control that can commit writes
"BEGIN": {},
"COMMIT": {},
"ROLLBACK": {},
"SAVEPOINT": {},
"TRANSACTION": {},
// Database/Schema management
"USE": {},
"DATABASE": {},
"SCHEMA": {},
// Index operations
"REINDEX": {},
"ANALYZE": {},
"OPTIMIZE": {},
// User/Permission management
"GRANT": {},
"REVOKE": {},
// MySQL specific write operations
"LOAD": {},
"DELAYED": {},
"IGNORE": {},
"LOW_PRIORITY": {},
"HIGH_PRIORITY": {},
"QUICK": {},
// PostgreSQL specific write operations
"COPY": {},
"VACUUM": {},
"CLUSTER": {},
"LISTEN": {},
"NOTIFY": {},
"DISCARD": {},
"PREPARE": {},
"EXECUTE": {},
"DEALLOCATE": {},
"RESET": {},
"SET": {},
"UNLISTEN": {},
"DECLARE": {},
"CLOSE": {},
// dbo11 specific operations we'd like to exclude
"EXPLAIN": {},
}
type ExplainPlanOutput struct {
Metadata ExplainPlanMetadataInfo `json:"metadata"`
Plan ExplainPlanNode `json:"plan"`
}
type ExplainPlanMetadataInfo struct {
DatabaseEngine string `json:"databaseEngine"`
DatabaseVersion string `json:"databaseVersion"`
QueryIdentifier string `json:"queryIdentifier"`
GeneratedAt string `json:"generatedAt"`
ProcessingResult ExplainProcessingResult `json:"processingResult"`
ProcessingResultReason string `json:"processingResultReason"`
}
type ExplainPlanNode struct {
Operation ExplainPlanOutputOperation `json:"operation"`
Details ExplainPlanNodeDetails `json:"details"`
Children []ExplainPlanNode `json:"children,omitempty"`
}
type ExplainPlanNodeDetails struct {
EstimatedRows int64 `json:"estimatedRows"`
EstimatedCost *float64 `json:"estimatedCost,omitempty"`
TableName *string `json:"tableName,omitempty"`
Alias *string `json:"alias,omitempty"`
AccessType *ExplainPlanAccessType `json:"accessType,omitempty"`
KeyUsed *string `json:"keyUsed,omitempty"`
JoinType *string `json:"joinType,omitempty"`
JoinAlgorithm *ExplainPlanJoinAlgorithm `json:"joinAlgorithm,omitempty"`
Condition *string `json:"condition,omitempty"`
GroupByKeys []string `json:"groupByKeys,omitempty"`
SortKeys []string `json:"sortKeys,omitempty"`
Warning *string `json:"warning,omitempty"`
}