analyzeSelectStatement analyzes SELECT statements for issues
(stmt *ast.SelectStatement)
| 154 | |
| 155 | // analyzeSelectStatement analyzes SELECT statements for issues |
| 156 | func (a *SQLAnalyzer) analyzeSelectStatement(stmt *ast.SelectStatement) { |
| 157 | // Check for SELECT * |
| 158 | for _, col := range stmt.Columns { |
| 159 | if id, ok := col.(*ast.Identifier); ok && id.Name == "*" { |
| 160 | a.hasSelectStar = true |
| 161 | a.addPerformanceIssue("SELECT_STAR", "MEDIUM", |
| 162 | "SELECT * can be inefficient and may break if table schema changes", |
| 163 | "performance", "Specify explicit column names instead of SELECT *") |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Analyze FROM clause |
| 168 | if len(stmt.From) > 1 { |
| 169 | // Multiple tables in FROM without explicit JOIN |
| 170 | a.hasCartesian = true |
| 171 | a.addPerformanceIssue("CARTESIAN_PRODUCT", "HIGH", |
| 172 | "Multiple tables in FROM clause may cause cartesian product", |
| 173 | "performance", "Use explicit JOIN syntax instead of comma-separated tables") |
| 174 | } |
| 175 | |
| 176 | // Check for missing WHERE clause on large table operations |
| 177 | if stmt.Where == nil && len(stmt.From) > 0 { |
| 178 | a.addPerformanceIssue("MISSING_WHERE", "MEDIUM", |
| 179 | "SELECT without WHERE clause may scan entire table", |
| 180 | "performance", "Add WHERE clause to limit result set") |
| 181 | } |
| 182 | |
| 183 | // Analyze subqueries |
| 184 | if len(stmt.From) > 0 { |
| 185 | a.subqueryCount++ |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // analyzeInsertStatement analyzes INSERT statements |
| 190 | func (a *SQLAnalyzer) analyzeInsertStatement(stmt *ast.InsertStatement) { |
no test coverage detected