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

Function classifyComplexity

pkg/advisor/optimizer.go:190–209  ·  view source on GitHub ↗

classifyComplexity determines query complexity based on AST characteristics.

(tree *ast.AST)

Source from the content-addressed store, hash-verified

188
189// classifyComplexity determines query complexity based on AST characteristics.
190func classifyComplexity(tree *ast.AST) string {
191 if tree == nil || len(tree.Statements) == 0 {
192 return ComplexitySimple
193 }
194
195 complexityScore := 0
196
197 for _, stmt := range tree.Statements {
198 complexityScore += statementComplexity(stmt)
199 }
200
201 switch {
202 case complexityScore >= 5:
203 return ComplexityComplex
204 case complexityScore >= 2:
205 return ComplexityModerate
206 default:
207 return ComplexitySimple
208 }
209}
210
211// statementComplexity scores the complexity of a single statement.
212func statementComplexity(stmt ast.Statement) int {

Callers 2

AnalyzeMethod · 0.85

Calls 1

statementComplexityFunction · 0.85

Tested by 1