Hi, I am running mysql select queries 3500 times in a for loop and perform operations on the values returned by the queries in PHP. that process takes 16 seconds to execute for loop. any suggestion to reduce the execution time and improve the performance. thanks!
views:
50answers:
2
+2
A:
Refactor your MySQL select so you only execute it once, not 3500 times. Tell us the queries in question, and we might be able to help you do it
Mark Baker
2010-10-21 08:01:40
Actually i run the queries based on the time period. for example I am getting user logins number daily since 2001. thanks for your suggestions and give some suggestions to Refactor MYSQL
KMK
2010-10-21 10:16:50
@KMK - Show us the SQL queries, and we might be able to refactor it for you - the most obvious solution for a time period query is with a group by - but without knowing the queries, there's not a great deal more that we can actually do to help.
Mark Baker
2010-10-21 10:23:53
+5
A:
Try to minimize the amount of queries, do you really need 3500 queries or can you select all rows in a single call?
If not, you can gain some performance by using prepared statements PDO gives you a easy to use interface for that.
http://dk2.php.net/manual/en/book.pdo.php
http://dk2.php.net/manual/en/pdo.prepare.php
Please paste some code if i need to be more specific :)
madsleejensen
2010-10-21 08:02:06