I'm using a table to do login, the table has a record of 2500. when i try to login it takes nearly 30-40 seconds to load. I'm using PHP and MySQL.I need to make the sql query faster to check the data. Solutions are welcomed thanks in advance pls help me out
10
-
Use indexes, and instead of retrieving all fields using *, try retrieving only the fields you require.Prabhuram– Prabhuram2012-04-30 06:42:25 +00:00Commented Apr 30, 2012 at 6:42
-
If the table has only 2500 records it should even with no indexes be way faster.juergen d– juergen d2012-04-30 06:43:01 +00:00Commented Apr 30, 2012 at 6:43
-
Without any code, we can only guess what you did wrong. Show us.kba– kba2012-04-30 06:43:27 +00:00Commented Apr 30, 2012 at 6:43
-
I have index on the login id's even its slowBoopaathy– Boopaathy2012-04-30 06:44:57 +00:00Commented Apr 30, 2012 at 6:44
-
3@Boopaathy Edit your question and include it there. By the way, your scheme is terribly wrong. You should ever never never store passwords plaintext! Especially not so when your code is vulnerable to SQL injections!kba– kba2012-04-30 06:55:24 +00:00Commented Apr 30, 2012 at 6:55
|
Show 5 more comments
2 Answers
When locating the causes of problems of performance issues, there are many things to consider in the your application stack:
- Database: Indexes, Joins, Query Formation
- Network in between: Routing issues, Bandwith, connectivity speed
- Code: Check if your code structure is not creating unecessary delays, forexample some people have their validations span over client and server both in a single method which increases method lifetime longer. Try to put validation's core logic on database side like in stored procedures. Try to use methods with lesser overheads.
Comments
You should have included your query so we can examine it. Don't pull all your records (e.g. don't use Select * from users) and then loop through to find a match. Instead, use WHERE clause to limit your records to (i.e. one row). That is
SELECT col1,col2,.. FROM Users WHERE username='username' AND password='password'
You can try that and see the performance...