Page 1 of 1

Optimisation

Posted: Wed Feb 16, 2005 8:53 am
by Archy
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.

Posted: Wed Feb 16, 2005 9:11 am
by feyd
3 rows should be quicker, as it should require less checking/matching for what to return.

Posted: Wed Feb 16, 2005 9:27 am
by Archy
Sorry, I made a mistake in my other post, I meant (And is corrected in my previous post):

- Get 3 columns from a database via 1 query, or
- Get 3 rows from a database via 3 seperate queries.

Thanks.

Posted: Wed Feb 16, 2005 9:36 am
by feyd
1 query scenarios are generally the faster.. but that depends on the query.

Posted: Wed Feb 16, 2005 10:10 am
by Archy
That's what I thought. The queries are only very basic.

Thanks.

Posted: Wed Feb 16, 2005 1:28 pm
by timvw
experiment and share the results with us..... :)

i can imagine mysql is better in performing 3 simple queries faster than 1 complex query....

Posted: Thu Feb 17, 2005 6:28 am
by CoderGoblin
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.

Posted: Thu Feb 17, 2005 8:34 am
by magicrobotmonkey
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.