@@ -33,6 +33,9 @@ type DatabaseQuery interface {
33
33
// When the query is valid, nil returned, otherwise an error is returned.
34
34
// The query is not executed.
35
35
ValidateQuery (ctx context.Context , query string ) error
36
+
37
+ // ExplainQuery explains an AQL query and return information about it.
38
+ ExplainQuery (ctx context.Context , query string , bindVars map [string ]interface {}, opts * ExplainQueryOptions ) (ExplainQueryResult , error )
36
39
}
37
40
38
41
type QuerySubOptions struct {
@@ -99,3 +102,73 @@ type QueryOptions struct {
99
102
type QueryRequest struct {
100
103
Query string `json:"query"`
101
104
}
105
+
106
+ type ExplainQueryOptimizerOptions struct {
107
+ // A list of to-be-included or to-be-excluded optimizer rules can be put into this attribute,
108
+ // telling the optimizer to include or exclude specific rules.
109
+ // To disable a rule, prefix its name with a "-", to enable a rule, prefix it with a "+".
110
+ // There is also a pseudo-rule "all", which matches all optimizer rules. "-all" disables all rules.
111
+ Rules []string `json:"rules,omitempty"`
112
+ }
113
+
114
+ type ExplainQueryOptions struct {
115
+ // If set to true, all possible execution plans will be returned.
116
+ // The default is false, meaning only the optimal plan will be returned.
117
+ AllPlans bool `json:"allPlans,omitempty"`
118
+
119
+ // An optional maximum number of plans that the optimizer is allowed to generate.
120
+ // Setting this attribute to a low value allows to put a cap on the amount of work the optimizer does.
121
+ MaxNumberOfPlans * int `json:"maxNumberOfPlans,omitempty"`
122
+
123
+ // Options related to the query optimizer.
124
+ Optimizer ExplainQueryOptimizerOptions `json:"optimizer,omitempty"`
125
+ }
126
+
127
+ type ExplainQueryResultExecutionNodeRaw map [string ]interface {}
128
+
129
+ type ExplainQueryResultExecutionCollection struct {
130
+ Name string `json:"name"`
131
+ Type string `json:"type"`
132
+ }
133
+
134
+ type ExplainQueryResultExecutionVariable struct {
135
+ ID int `json:"id"`
136
+ Name string `json:"name"`
137
+ IsDataFromCollection bool `json:"isDataFromCollection"`
138
+ IsFullDocumentFromCollection bool `json:"isFullDocumentFromCollection"`
139
+ }
140
+
141
+ type ExplainQueryResultPlan struct {
142
+ // Execution nodes of the plan.
143
+ NodesRaw []ExplainQueryResultExecutionNodeRaw `json:"nodes,omitempty"`
144
+ // List of rules the optimizer applied
145
+ Rules []string `json:"rules,omitempty"`
146
+ // List of collections used in the query
147
+ Collections []ExplainQueryResultExecutionCollection `json:"collections,omitempty"`
148
+ // List of variables used in the query (note: this may contain internal variables created by the optimizer)
149
+ Variables []ExplainQueryResultExecutionVariable `json:"variables,omitempty"`
150
+ // The total estimated cost for the plan. If there are multiple plans, the optimizer will choose the plan with the lowest total cost
151
+ EstimatedCost float64 `json:"estimatedCost,omitempty"`
152
+ // The estimated number of results.
153
+ EstimatedNrItems int `json:"estimatedNrItems,omitempty"`
154
+ }
155
+
156
+ type ExplainQueryResultExecutionStats struct {
157
+ RulesExecuted int `json:"rulesExecuted,omitempty"`
158
+ RulesSkipped int `json:"rulesSkipped,omitempty"`
159
+ PlansCreated int `json:"plansCreated,omitempty"`
160
+ PeakMemoryUsage uint64 `json:"peakMemoryUsage,omitempty"`
161
+ ExecutionTime float64 `json:"executionTime,omitempty"`
162
+ }
163
+
164
+ type ExplainQueryResult struct {
165
+ Plan ExplainQueryResultPlan `json:"plan,omitempty"`
166
+ Plans []ExplainQueryResultPlan `json:"plans,omitempty"`
167
+ // List of warnings that occurred during optimization or execution plan creation
168
+ Warnings []string `json:"warnings,omitempty"`
169
+ // Info about optimizer statistics
170
+ Stats ExplainQueryResultExecutionStats `json:"stats,omitempty"`
171
+ // Cacheable states whether the query results can be cached on the server if the query result cache were used.
172
+ // This attribute is not present when allPlans is set to true.
173
+ Cacheable * bool `json:"cacheable,omitempty"`
174
+ }
0 commit comments