Menu

Post image 1
Post image 2
1 / 2
0

6 Eloquent Patterns That Silently Break MySQL Index Usage (And How to Fix Each One)

DEV Community: mysql·Hafiz·3 days ago
#X6ilFHtV
#dev#index#fullscreen#query#mysql#article
Reading 0:00
15s threshold

Originally published at hafiz.dev You added the index. You confirmed it's there with SHOW INDEX FROM orders . The query is still timing out in production, against the same created_at column you've had indexed for months. This happens more than it should. MySQL's B-tree index is sitting right next to your query, completely ignored, and Eloquent handed it a condition the optimizer can't act on. No error. No warning. No hint in the logs. Just a full table scan against 4 million rows while your dashboard waits. The reason almost always traces to one concept: sargability. A predicate is sargable (Search ARGument ABLE) when MySQL can use an index to resolve it directly. The moment a function wraps the indexed column, sargability breaks. MySQL has to compute that function for every single row, then filter the results. That means reading the entire table regardless of what indexes exist. View the interactive diagram on hafiz.dev Six Eloquent patterns trigger this silently.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More