Reputation: 3865
MyPHP Application sends a SELECT statement to MySQL with HTTPClient.
It takes about 20 seconds or more.
I thought MySQL can’t get result immediately because MySQL Administrator shows stat for sending data
or copying to tmp table
while I'd been waiting for result.
But when I send same SELECT statement from another application like phpMyAdmin or jmater it takes 2 seconds or less.10 times faster!!
Dose anyone know why MySQL perform so difference?
Upvotes: 1
Views: 109
Reputation: 308
Like @symcbean already said, php's mysql driver caches query results. This is also why you can do another mysql_query()
while in a while($row=mysql_fetch_array())
loop.
The reason MySql Administrator or phpMyAdmin shows result so fast is they append a LIMIT 10
to your query behind your back.
If you want to get your query results fast, i can offer some tips. They involve selecting only what you need and when you need:
select *
everywhere. This might bite you later when you want another column but forget to add it to select
statement, so do this when needed (like tables with 100 columns or a million rows).while()
loop. This might look like illogical 'cause you make more queries but when you deal with queries involving around ~10 tables, hundreds of concurrent users, locks and query caches; things don't always make sense at first :)These are some tips i learned from my boss and my own experince. As always, YMMV.
Upvotes: 1
Reputation: 48357
Dose anyone know why MySQL perform so difference?
Because MySQL caches query results, and the operating system caches disk I/O (see this link for a description of the process in Linux)
Upvotes: 0