Indexes improve lookup performance by allowing MySQL to locate rows more efficiently.
Example:
$table->index('email');
$table->index(['user_id', 'status']);
A composite index:
INDEX(user_id, status)
can be useful for:
WHERE user_id = ?
AND status = ?
Important interview point
Indexes aren't free.
They:
consume storage
increase write/update cost
require maintenance
can be useless if poorly designed
I verify indexing decisions using:
EXPLAIN SELECT ...
For example:
EXPLAIN
SELECT *
FROM orders
WHERE user_id = 10
AND status = 'paid';
I would inspect the execution plan rather than adding indexes blindly.
0 comments:
Post a Comment
Thanks