php - mysql select query very slow when using where clause
965
if ($result = mysqli_query($link, "SELECT * FROM `users`")) {
while ($row = mysqli_fetch_assoc($result)) {
}
}
When I use the above code query works fine..
But when I use the following code mysql is very slow.
if ($result = mysqli_query($link, "SELECT * FROM `users` WHERE name IS NULL")) {
while ($row = mysqli_fetch_assoc($result)) {
}
}
Can someone tell me why and how to make that query faster?
Answer
Solution:
There are many ways to make the query run faster.
Avoid
*
as it first look for all the column then it gives them out. Solution - Use the attribute name manually such as:Use on the query.
Use to find out which index could be used and which index is actually used. Create an appropriate index if necessary.
Answer
Solution:
You need to add an index on the
name
column to speed things up.