Aan de slag
SQL Query Clinic — Find Slow and Risky SQL

SQL Query Clinic — Find Slow and Risky SQL

Send a .sql file and get back a list of slow, risky and broken queries with line numbers and cures, plus the SQLite query plan with every table scan marked. Suggested indexes are tried in memory first; long LIKE patterns and `= NULL` are rewritten for you. #Techniek

Beoordeling
Meer beoordelingen nodig
Verkocht
0
Gebruikswijze
Downloaden

Send SQL, get back what is wrong with it. Most SQL problems are not syntax errors: a LIKE pattern one byte too long for your managed database, an UPDATE with no WHERE, a NOT IN that quietly returns nothing, a filter that reads every row. SQL Query Clinic finds them in the text, then shows the query plan to prove which queries scan the whole table.

What it does:

  • 10 lint rules with line numbers, severity and a one-line cure: long LIKE/GLOB patterns, leading wildcards, UPDATE/DELETE without WHERE, SELECT *, values pasted into SQL, NOT IN with NULL, = NULL, functions around columns, LIMIT without ORDER BY
  • Reads the query plan from an in-memory SQLite built from your schema, and labels each step table-scan, index-scan, search or temp-sort
  • Builds each suggested index in memory, plans again, and reports scan gone or scan stays, so you do not get an index that does nothing
  • fix rewrites long LIKE patterns (substr, instr, =) and = NULL (IS NULL), keeps your comments, and lists every change
  • Text, Markdown or JSON output; exit codes for CI (0 clean, 1 findings, 2 unreadable, 3 invalid SQL)
  • The 50-byte LIMIT is a setting: --max-pattern-bytes

Honest limits, stated in the README: the rules read text and do not know your data; plans come from SQLite on an empty database, so another engine may differ; substr/instr rewrites are case-sensitive while LIKE is not.

What is inside

  • SKILL.md, README.md, LICENSE
  • scripts/sql_query_clinic.py
  • tests/test_clinic.py (62 tests)
  • examples/: schema, sample queries, saved outputs

Requirements and safety

Python 3.9+ (tested on macOS with Python 3.9 and 3.10), macOS or Linux. Standard library only. The tool makes no network calls, needs no credentials and never opens a database file; your schema runs only in memory.

License

Personal, non-transferable license for your own projects, including commercial work. No resale or redistribution.