BenchmarkMariaDB_Mixed benchmarks parsing of queries that combine multiple MariaDB-specific features in a single statement.
(b *testing.B)
| 200 | // BenchmarkMariaDB_Mixed benchmarks parsing of queries that combine multiple |
| 201 | // MariaDB-specific features in a single statement. |
| 202 | func BenchmarkMariaDB_Mixed(b *testing.B) { |
| 203 | benchmarks := []struct { |
| 204 | name string |
| 205 | sql string |
| 206 | }{ |
| 207 | { |
| 208 | name: "temporal_with_cte", |
| 209 | sql: `WITH history AS ( |
| 210 | SELECT * FROM orders FOR SYSTEM_TIME ALL |
| 211 | ) |
| 212 | SELECT id, status FROM history WHERE status = 'cancelled'`, |
| 213 | }, |
| 214 | { |
| 215 | name: "hierarchical_with_cte", |
| 216 | sql: `WITH RECURSIVE org AS ( |
| 217 | SELECT id, name, parent_id FROM employees |
| 218 | START WITH parent_id IS NULL |
| 219 | CONNECT BY PRIOR id = parent_id |
| 220 | ) |
| 221 | SELECT * FROM org ORDER BY id`, |
| 222 | }, |
| 223 | { |
| 224 | name: "create_table_versioned", |
| 225 | sql: `CREATE TABLE orders ( |
| 226 | id INT PRIMARY KEY, |
| 227 | status VARCHAR(50), |
| 228 | row_start DATETIME(6) GENERATED ALWAYS AS ROW START, |
| 229 | row_end DATETIME(6) GENERATED ALWAYS AS ROW END, |
| 230 | PERIOD FOR SYSTEM_TIME(row_start, row_end) |
| 231 | ) WITH SYSTEM VERSIONING`, |
| 232 | }, |
| 233 | } |
| 234 | |
| 235 | for _, bm := range benchmarks { |
| 236 | bm := bm |
| 237 | b.Run(bm.name, func(b *testing.B) { |
| 238 | tkz := tokenizer.GetTokenizer() |
| 239 | defer tokenizer.PutTokenizer(tkz) |
| 240 | |
| 241 | tokens, err := tkz.Tokenize([]byte(bm.sql)) |
| 242 | if err != nil { |
| 243 | b.Fatalf("Tokenize error: %v", err) |
| 244 | } |
| 245 | |
| 246 | b.ResetTimer() |
| 247 | b.ReportAllocs() |
| 248 | |
| 249 | for i := 0; i < b.N; i++ { |
| 250 | p := parser.NewParser(parser.WithDialect(string(keywords.DialectMariaDB))) |
| 251 | result, err := p.ParseFromModelTokens(tokens) |
| 252 | if err != nil { |
| 253 | b.Fatalf("Parse error: %v", err) |
| 254 | } |
| 255 | ast.ReleaseAST(result) |
| 256 | p.Release() |
| 257 | } |
| 258 | }) |
| 259 | } |
nothing calls this directly
no test coverage detected