Which is optimal query for check whether the username ans password present in MySql database.
1)SELECT * FROM login_details WHERE username='username' AND password='password'
2)SELECT count(*)FROM login_details WHERE username='username' AND password='password'
3)SELECT count(Username)FROM login_details WHERE username='username' AND password='password'
4)SELECT 1 FROM login_details WHERE username='username' AND password='password'
Thanks
Hopefully
'password'is actually a salted hash of the user’s password, and you’re passing both literals from your application as parameters to a prepared statement.Assuming that you have an index on
(username, password), the “optimum” would be:This way, MySQL stops searching once it encounters a single result.