MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / Analyze

Method Analyze

pkg/advisor/optimizer.go:148–174  ·  view source on GitHub ↗

Analyze inspects all statements in the given AST and returns an OptimizationResult. Each configured rule is applied to every statement in the AST. The result includes all suggestions, a complexity classification, and an optimization score.

(tree *ast.AST)

Source from the content-addressed store, hash-verified

146// Each configured rule is applied to every statement in the AST. The result
147// includes all suggestions, a complexity classification, and an optimization score.
148func (o *Optimizer) Analyze(tree *ast.AST) *OptimizationResult {
149 if tree == nil {
150 return &OptimizationResult{
151 Suggestions: []Suggestion{},
152 QueryComplexity: ComplexitySimple,
153 Score: 100,
154 }
155 }
156
157 var suggestions []Suggestion
158
159 for _, stmt := range tree.Statements {
160 for _, rule := range o.rules {
161 ruleSuggestions := rule.Analyze(stmt)
162 suggestions = append(suggestions, ruleSuggestions...)
163 }
164 }
165
166 complexity := classifyComplexity(tree)
167 score := calculateScore(suggestions)
168
169 return &OptimizationResult{
170 Suggestions: suggestions,
171 QueryComplexity: complexity,
172 Score: score,
173 }
174}
175
176// AnalyzeSQL is a convenience method that parses the SQL string and analyzes it.
177//

Callers 1

AnalyzeSQLMethod · 0.95

Calls 3

classifyComplexityFunction · 0.85
calculateScoreFunction · 0.85
AnalyzeMethod · 0.65

Tested by

no test coverage detected