(ctx context.Context, db *sql.DB, table string, batch []QueryLogEntry)
| 307 | return nil |
| 308 | } |
| 309 | truncated := truncateQuery(*q) |
| 310 | return &truncated |
| 311 | } |
| 312 | |
| 313 | // classifyQuery maps a command type string to a query_kind value. |
| 314 | func classifyQuery(cmdType string) string { |
| 315 | switch cmdType { |
| 316 | case "SELECT", "SHOW", "TABLE", "VALUES", "EXPLAIN": |
| 317 | return "Select" |
| 318 | case "INSERT": |
| 319 | return "Insert" |
| 320 | case "UPDATE": |
| 321 | return "Update" |
| 322 | case "DELETE": |
| 323 | return "Delete" |
| 324 | case "CREATE", "ALTER", "DROP", "TRUNCATE": |
| 325 | return "DDL" |
| 326 | case "COPY": |
| 327 | return "Copy" |
| 328 | case "BEGIN", "COMMIT", "ROLLBACK", "SET", "RESET", "DISCARD", "DEALLOCATE", "LISTEN", "NOTIFY", "UNLISTEN": |
| 329 | return "Utility" |
| 330 | default: |
| 331 | return "Utility" |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | // literalRegexp matches string literals and numeric literals for normalization. |
| 336 | var literalRegexp = regexp.MustCompile(`'[^']*'|"[^"]*"|\b\d+\.?\d*\b`) |
| 337 | |
| 338 | // comparisonBoolNullRegexp matches boolean/null values in comparison expressions. |
| 339 | var comparisonBoolNullRegexp = regexp.MustCompile(`(=|<>|!=|<=|>=|<|>)\s*(TRUE|FALSE|NULL)\b`) |
| 340 | |
| 341 | // normalizeQueryHash computes a FNV-1a hash of a query after collapsing |
| 342 | // whitespace and replacing literals with placeholders. This groups queries |
| 343 | // that differ only in parameter values. |
| 344 | func normalizeQueryHash(query string) int64 { |
| 345 | // Collapse whitespace |
| 346 | var sb strings.Builder |
no test coverage detected