Use cases / Debug and optimize database queries

Debug and optimize database queries

Paste your slow SQL query and EXPLAIN output. Torki identifies performance bottlenecks, suggests indexes, rewrites joins, and explains exactly why each change improves execution time.

Try in Torki
Author
Torki AI
Category
Developers
Feature
Chat
Model
Cosmos
Share
Copy link
1

Share your query

Paste your SQL query along with the EXPLAIN or EXPLAIN ANALYZE output. Include the database engine (PostgreSQL, MySQL, SQLite) and any relevant context — table sizes, expected row counts, and what the query is supposed to accomplish. The more context, the more precise the optimization.

My PostgreSQL query is taking 12 seconds to run. Here's the query and EXPLAIN ANALYZE output. The orders table has ~2.3M rows, users table has ~150K rows. I need this under 500ms for our API endpoint. SELECT u.name, COUNT(o.id) as order_count, SUM(o.total) as revenue FROM users u JOIN orders o ON u.id = o.user_id WHERE o.created_at > '2024-01-01' GROUP BY u.id ORDER BY revenue DESC LIMIT 50;

2

Get a diagnosis

Torki reads your EXPLAIN output line by line, identifying the exact operations causing slowdowns — sequential scans on large tables, inefficient join strategies, missing indexes, or poor cardinality estimates. It doesn't just tell you what's slow, it explains why.

3

Apply optimizations

Torki provides specific fixes: CREATE INDEX statements ready to copy-paste, rewritten queries using CTEs or subqueries, configuration adjustments, and materialized view suggestions for repeated queries. Each recommendation includes the expected performance impact.

4

Verify improvements

Run the optimized query with EXPLAIN ANALYZE and share the new results. Torki compares before-and-after execution plans, confirms the improvements are working as expected, and suggests additional fine-tuning if needed.

Torki Chat
My PostgreSQL query is taking 12 seconds...

I see three bottlenecks:

1. Sequential scan on orders — add composite index on (user_id, created_at)...

Ready to try for yourself?

Paste your slow query and EXPLAIN output. Torki diagnoses the problem and provides optimized solutions.

Try in Torki