|
Posted by Michael Fesser on 11/24/06 14:03
..oO(Sandman)
>> Clear.
>> Just to be sure, you should of course NOT running seperate queries for each
>> result you need.
>> eg BAD:
>> SELECT username FROM tbluser WHERE (userid=23);
>> SELECT username FROM tbluser WHERE (userid=36);
>> SELECT username FROM tbluser WHERE (userid=123);
>
>No, that's stupid.
>
>> eg GOOD:
>> SELECT userid, username FROM tbluser WHERE
>> (userid IN (23,36,123));
>
>But BAD:
>SELECT userid, username FROM tbluser WHERE
>(userid IN (<500 id numbers>));
I did a little test with a single table containing 100000(!) entries,
all with an ID and a random name. The task was to select 1000 randomly
chosen records. I did two tests:
1) a foreach loop, running 1000 queries
time: 0.90s
2) a single query with an IN operator and 1000 given IDs
time: 0.04s
Tested on a P3 550MHz/192MB RAM, MySQL 4.1.11
Micha
Navigation:
[Reply to this message]
|