|
Posted by Schraalhans Keukenmeester on 05/14/07 06:52
At Sun, 13 May 2007 23:10:14 -0400, Roman let his monkeys type:
> Ciaran wrote:
>> Hi All,
>> Is it faster to have mySql look up as much data as possible in one
>> complex query or to have php do all the complex processing and submit
>> lots of simple queries to the mysql database?
>>
>> Cheers,
>> Ciarán
>>
>
> I would vote for single complex query over multiple queries with
> sub-results being processed by PHP.
>
> Do not forget that SQL is a procedural language and you can also write
> algorithms in it (I am not 100% sure about MySQL though). Any PHP to
> MySQL interraction will have an interprocess overhead (on same server)
> or network communication overhead (MySQL hosted on different server).
>
> Roman
MySQL supports stored procedures from v5 upwards I believe.
While this thread has offered several good points the most important
point in its summary would seem to be: it depends.
As someone said:"when in doubt, find it out." Very true, but I'd advise to
be pragmatic about it. If the total (execution) time of the SQL-related
stuff is only a fraction of a scripts total running time (a profiler could
help, but without it's quite doable to time things yourself), ask yourself
if it's really worth it putting in a lot of time and effort in optimizing
it. The famous 80/20 rule applies. Especially if a script isn't called a
gazillion times a day it's perhaps not important at all.
There seems to be quite an intrest with many/some in optimizing every
splinter of code, just for the heck of it. I'm not saying this is a bad
thing. Just that often using the time spent on this would be much better
spent on general program and data structure design.
That said, it is of course just one person's opinion, based on global
observations. So if you disagree, don't feel personally offended. Glad to
hear alternative views on this.
Best!,
Sh.
[Back to original message]
|