A simple question really, would it be quicker, and more server friendly to either:
- Get 3 columns from a database via 1 query, or
- Get 3 rows from a database via 3 seperate queries.
I know which I think is quicker, but since I am no expert on databased, I wondered if someone could enlighten me.
Thanks.
Optimisation
Moderator: General Moderators
Optimisation
Last edited by Archy on Wed Feb 16, 2005 9:26 am, edited 1 time in total.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
In my experience Postgres is generally quicker when querying once, even with complex joins. Let the DB do the work rather than PHP as the numebr of things you return are generally smaller. This also makes maintenance of the PHP easier.
As always it depends on the php server and db server setup. Having a slow DBserver but a mega webserver may reverse things.
Also it should be worth pointing out that it is generally quicker to get only the columns required rather than using SELECT *, especially when joining tables.
As always it depends on the php server and db server setup. Having a slow DBserver but a mega webserver may reverse things.
Also it should be worth pointing out that it is generally quicker to get only the columns required rather than using SELECT *, especially when joining tables.
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Yea, using php w/ mysql I find that generally it is better to let the db handle as much as the data processing as I can give to it. It is generally much more efficient then pulling it over and then doing all sorts of traversing of arrays or whatnot.
Of course, this is not always true. Only testing can show the true path.
Of course, this is not always true. Only testing can show the true path.