|
Posted by NC on 05/13/07 20:42
On May 10, 9:43 am, Ciaran <cronok...@hotmail.com> wrote:
>
> What about at the most basic level. For example would it be
> quicker to run:
> SELECT * FROM users WHERE userID IN
> (1,2,4,7,8,9,10,11,13,14,15,17,18,35,etc,etc,etc);
>
> or select each userID seperately in a PHP foreach loop with
> something like this statement:
> SELECT * FROM users WHERE userID=2 LIMIT 1;
The first approach would be much faster.
> I'm basically asking: Is it contacting the database that slows
> down PHP or is it the actual speed at which mySQL runs.
It depends on the query. For simple queries, the per-query overhead
is important, so one query is faster than several. For complex
queries, especially those that involve joins and sorting, splitting
one complex query into two simpler ones may be a viable option.
> I'm just looking for a rule of thumb here
There is only one rule of thumb here: when in doubut, test it out...
Cheers,
NC
Navigation:
[Reply to this message]
|