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

Function BenchmarkFullPipeline

pkg/sql/parser/pipeline_bench_test.go:25–66  ·  view source on GitHub ↗

BenchmarkFullPipeline benchmarks the complete SQL processing pipeline: tokenize → convert → parse for various query complexities.

(b *testing.B)

Source from the content-addressed store, hash-verified

23// BenchmarkFullPipeline benchmarks the complete SQL processing pipeline:
24// tokenize → convert → parse for various query complexities.
25func BenchmarkFullPipeline(b *testing.B) {
26 queries := map[string]string{
27 "simple_select": "SELECT id, name FROM users WHERE active = true",
28 "join": "SELECT u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id WHERE o.status = 'completed'",
29 "aggregate": "SELECT department, COUNT(*) as cnt, AVG(salary) as avg_sal FROM employees GROUP BY department HAVING COUNT(*) > 5 ORDER BY avg_sal DESC",
30 "subquery": "SELECT * FROM users WHERE id IN (SELECT user_id FROM orders WHERE total > 100)",
31 "cte": "WITH active_users AS (SELECT id, name FROM users WHERE active = true) SELECT au.name, COUNT(o.id) FROM active_users au JOIN orders o ON au.id = o.user_id GROUP BY au.name",
32 "window_function": "SELECT name, salary, ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) as rank FROM employees",
33 "insert": "INSERT INTO users (name, email, active) VALUES ('John', 'john@example.com', true)",
34 "update": "UPDATE users SET name = 'Jane', updated_at = NOW() WHERE id = 42",
35 "delete": "DELETE FROM sessions WHERE expires_at < NOW()",
36 "complex": "SELECT u.id, u.name, o.total, ROW_NUMBER() OVER (PARTITION BY u.id ORDER BY o.created_at DESC) as rn FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.active = true AND o.total > 50 ORDER BY u.name, o.total DESC LIMIT 100",
37 }
38
39 for name, sql := range queries {
40 b.Run(name, func(b *testing.B) {
41 b.ReportAllocs()
42 sqlBytes := []byte(sql)
43
44 b.ResetTimer()
45 for i := 0; i < b.N; i++ {
46 // Step 1: Tokenize
47 tkz := tokenizer.GetTokenizer()
48 tokens, err := tkz.Tokenize(sqlBytes)
49 tokenizer.PutTokenizer(tkz)
50 if err != nil {
51 b.Fatal(err)
52 }
53
54 // Step 2: Convert
55
56 // Step 3: Parse
57 p := NewParser()
58 _, err = p.ParseFromModelTokensWithPositions(tokens)
59 p.Release()
60 if err != nil {
61 b.Fatal(err)
62 }
63 }
64 })
65 }
66}
67
68// BenchmarkParseError benchmarks error handling performance for invalid SQL.
69func BenchmarkParseError(b *testing.B) {

Callers

nothing calls this directly

Calls 7

ReleaseMethod · 0.95
GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
RunMethod · 0.80
TokenizeMethod · 0.80
NewParserFunction · 0.70

Tested by

no test coverage detected