MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / MakeExplain

Function MakeExplain

pkg/sql/sem/tree/explain.go:173–230  ·  view source on GitHub ↗

MakeExplain parses the EXPLAIN option strings and generates an explain statement.

(options []string, stmt Statement)

Source from the content-addressed store, hash-verified

171// MakeExplain parses the EXPLAIN option strings and generates an explain
172// statement.
173func MakeExplain(options []string, stmt Statement) (Statement, error) {
174 for i := range options {
175 options[i] = strings.ToUpper(options[i])
176 }
177 find := func(o string) bool {
178 for i := range options {
179 if options[i] == o {
180 return true
181 }
182 }
183 return false
184 }
185
186 if find("DEBUG") {
187 if !find("ANALYZE") {
188 return nil, pgerror.Newf(pgcode.Syntax, "DEBUG flag can only be used with EXPLAIN ANALYZE")
189 }
190 if len(options) != 2 {
191 return nil, pgerror.Newf(
192 pgcode.Syntax, "EXPLAIN ANALYZE (DEBUG) cannot be used in conjunction with other flags")
193 }
194 return &ExplainAnalyzeDebug{Statement: stmt}, nil
195 }
196
197 var opts ExplainOptions
198 for _, opt := range options {
199 opt = strings.ToUpper(opt)
200 if m, ok := explainModeStringMap[opt]; ok {
201 if opts.Mode != 0 {
202 return nil, pgerror.Newf(pgcode.Syntax, "cannot set EXPLAIN mode more than once: %s", opt)
203 }
204 opts.Mode = m
205 continue
206 }
207 flag, ok := explainFlagStringMap[opt]
208 if !ok {
209 return nil, pgerror.Newf(pgcode.Syntax, "unsupported EXPLAIN option: %s", opt)
210 }
211 opts.Flags[flag] = true
212 }
213 analyze := opts.Flags[ExplainFlagAnalyze]
214 if opts.Mode == 0 {
215 if analyze {
216 // ANALYZE implies DISTSQL.
217 opts.Mode = ExplainDistSQL
218 } else {
219 // Default mode is ExplainPlan.
220 opts.Mode = ExplainPlan
221 }
222 } else if analyze && opts.Mode != ExplainDistSQL {
223 return nil, pgerror.Newf(pgcode.Syntax, "EXPLAIN ANALYZE cannot be used with %s", opts.Mode)
224 }
225
226 return &Explain{
227 ExplainOptions: opts,
228 Statement: stmt,
229 }, nil
230}

Callers 1

ParseMethod · 0.92

Calls 1

NewfFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…