How the weekly ranking works
One vote per prompt, a fresh count every Monday, and a simple tie-break. Everything about how prompts reach the top three, in plain words.
Have a slow SQL query checked for wrong results first and speed second. You get a rewrite, the indexes to add, and a way to prove it's faster.
Review this SQL query the way a database performance engineer would. Database and version: [e.g. PostgreSQL 16] Rough table sizes: [e.g. orders 40 million rows, customers 2 million] Indexes that exist: [LIST THEM, OR PASTE THE OUTPUT OF \d tablename] What it should return, in plain words: [DESCRIPTION] ```sql [PASTE THE QUERY] ``` EXPLAIN ANALYZE output, if you have it: ``` [PASTE] ``` In this order: 1. Correctness first. Can it ever return wrong or duplicated rows? Think about NULLs, joins that multiply rows, and time zones. 2. What makes it slow? Plain language, please. 3. Rewrite it, and tell me what you assumed. 4. Give me the exact CREATE INDEX statements. If an existing index isn't helping, say so. 5. How do I check that it really got faster?
Revenue is counted more than once. JOIN order_items produces one row per item, so SUM(o.total) adds the same order total once for every item in it. An order with three items is tripled.
"Today" is the server's today. created_at::date = CURRENT_DATE uses the server time zone. Your shop runs on Paris time, so orders placed between midnight and 2 am land on the wrong day.
lower(c.email) LIKE '%@acme.com' starts with a wildcard. No index can help, so Postgres reads all 2 million customers.created_at::date hides the column from its index. Compare against a time range instead.SELECT c.id, c.name, SUM(o.total) AS revenue
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE c.email_domain = 'acme.com'
AND o.created_at >= date_trunc('day', now() AT TIME ZONE 'Europe/Paris') AT TIME ZONE 'Europe/Paris'
AND o.created_at < date_trunc('day', now() AT TIME ZONE 'Europe/Paris') AT TIME ZONE 'Europe/Paris' + interval '1 day'
GROUP BY c.id, c.name;
Assumption: you add a generated column email_domain. The join to order_items is gone because nothing in the result needs it.
CREATE INDEX CONCURRENTLY orders_created_customer_idx
ON orders (created_at, customer_id) INCLUDE (total);
CREATE INDEX CONCURRENTLY customers_email_domain_idx
ON customers (email_domain);
orders_status_idx is not used by this query. Check pg_stat_user_indexes before you drop it, in case something else needs it.
Run EXPLAIN (ANALYZE, BUFFERS) before and after. You want to see an Index Only Scan on orders instead of a Seq Scan. Expect it to go from about 4 seconds to well under 100 milliseconds.
NoteThis is an example. Results change between runs and model versions. Claude Prompts is a fan project and is not affiliated with Anthropic.
A query that crawls in production, a report whose totals look slightly off, or a last look before merging something that touches a big table. It's written with PostgreSQL in mind. MySQL and SQL Server are fine too, as long as you name the engine and version.
Table sizes and existing indexes matter a lot, so don't skip them. An index that saves you on 40 million rows is dead weight on 4,000. If you can get the EXPLAIN ANALYZE output, paste it, because without it Claude is reasoning about a likely plan and not your real one. For reports, describe the result you expect in plain words. That's how double counting gets caught.
Correctness comes first in the prompt for a reason: a fast query with wrong numbers is worse than a slow one with right ones. Try new indexes on a copy of the data, and make sure an index really is unused before you drop it. On a live PostgreSQL database, build with CONCURRENTLY so you don't block writes.
Use the copy button above. The full text is included, nothing is cut off.
Everything highlighted in yellow is a placeholder. Swap it for your own topic, audience or data.
If the result helped, press the heart. Votes decide which prompts make the weekly top 10.

Paste raw CSV and get a clean SVG chart with sensible scales, labels on the data, and a title that says what the chart shows.

Give Claude one statistic and its context, and get a short animated visual in HTML that builds the number up step by step instead of just showing it.
One vote per prompt, a fresh count every Monday, and a simple tie-break. Everything about how prompts reach the top three, in plain words.
Wrapping parts of your prompt in simple tags is one of the easiest ways to get more reliable answers from Claude. A practical guide with examples.