Three query patterns that quietly kill performance in Eloquent, and the EXPLAIN output that gives them away.
Read the generated query
A dashboard often lists the latest orders for one customer. Inspect the SQL generated by Eloquent, including its predicates, sorting and limit. Run EXPLAIN with representative values and compare the chosen key and estimated rows with the size of that customer’s order history.
Match the index to the work
For a query that filters by customer and sorts by creation time, test a composite index beginning with customer_id and created_at. An index on each column separately may still leave sorting work. For date filters, compare a range on the timestamp with applying a function to every row.
Measure the trade-off
A new index costs disk space and work on every write. Compare read latency and insert performance using realistic data distributions. If the page still sends one query per order to fetch its customer, solve that relationship-loading problem separately. An index cannot remove unnecessary round trips.
