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

Function TestDistinctOveruseRule

pkg/advisor/optimizer_test.go:259–288  ·  view source on GitHub ↗

--------------------------------------------------------------------------- OPT-004: SELECT DISTINCT Overuse ---------------------------------------------------------------------------

(t *testing.T)

Source from the content-addressed store, hash-verified

257// ---------------------------------------------------------------------------
258
259func TestDistinctOveruseRule(t *testing.T) {
260 opt := New()
261
262 tests := []struct {
263 name string
264 sql string
265 wantHit bool
266 }{
267 {
268 name: "DISTINCT without JOIN triggers info",
269 sql: "SELECT DISTINCT status FROM orders",
270 wantHit: true,
271 },
272 {
273 name: "No DISTINCT does not trigger",
274 sql: "SELECT status FROM orders",
275 wantHit: false,
276 },
277 }
278
279 for _, tt := range tests {
280 t.Run(tt.name, func(t *testing.T) {
281 result := mustAnalyze(t, opt, tt.sql)
282 got := hasSuggestion(result, "OPT-004")
283 if got != tt.wantHit {
284 t.Errorf("hasSuggestion(OPT-004) = %v, want %v for SQL %q", got, tt.wantHit, tt.sql)
285 }
286 })
287 }
288}
289
290func TestDistinctOveruseRuleDirect(t *testing.T) {
291 rule := &DistinctOveruseRule{}

Callers

nothing calls this directly

Calls 5

mustAnalyzeFunction · 0.85
hasSuggestionFunction · 0.85
RunMethod · 0.80
NewFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected