SQL Query Optimizer

Analyze SQL queries for performance issues and get optimization suggestions — detect full scans, bad patterns, and missing indexes.

About SQL Query Optimization

SQL query optimization is the process of improving query performance by rewriting queries, adding appropriate indexes, reducing data scanned, and avoiding common anti-patterns. Even small queries can have dramatic performance differences depending on how they're written — the difference between a well-optimized and poorly-written query can be several orders of magnitude in execution time on large tables.

This analyzer checks your queries against a library of known performance anti-patterns: SELECT * (transfers unnecessary data), LIKE with leading wildcards (disables index usage), implicit type conversions in WHERE clauses (disables indexes), functions on indexed columns (prevents index usage), missing LIMIT clauses, N+1 query patterns, and many more.

FAQ

Why is LIKE '%value%' slow?
A leading wildcard in LIKE prevents the database from using a B-tree index — it can't know where to start looking without knowing the beginning of the string. The database must scan every row. Alternatives: use full-text search (MATCH/AGAINST in MySQL, tsvector in PostgreSQL), or restructure data to avoid leading wildcard searches.
Why should I avoid functions on WHERE columns?
When you write WHERE YEAR(created_at) = 2024, the database computes YEAR() for every row, preventing index use. Instead, use range conditions: WHERE created_at >= '2024-01-01' AND created_at < '2025-01-01'. This lets the database use an index on created_at efficiently.