mediumPerformancePostgreSQL
The unindexed query
A developer asked an AI assistant to add a 'find orders by customer email' lookup to an admin dashboard. The suggested query returns correct results and runs fine in development with a handful of rows, but takes over 8 seconds once the orders table has grown to a few million rows in production.
findOrdersByEmail.sql
SELECT id, total, created_at
FROM orders
WHERE customer_email = 'alex@example.com'
ORDER BY created_at DESC;Why does this exact same query go from instant to 8+ seconds as the orders table grows to millions of rows?
Without an index on customer_email, the database has to scan every row to find matches — query time grows linearly with table size instead of staying near-constant.
ORDER BY created_at DESC always forces a full table scan regardless of indexing.
Selecting three columns is inherently slower than SELECT * in Postgres.
String comparisons in WHERE clauses are always quadratic in relational databases.