[geeklog-devel] Coding standards clarification
Peter Roozemaal
mathfox at xs4all.nl
Thu May 24 08:05:35 EDT 2007
Heather Engineering wrote:
>> Yes, because it is hard to maintain because it is ugly and it has so
>> many side effects. Make multiple trips to the database for code
>> clarity. Speed it up only if you do tests that show it is a bottleneck.
>
> That's a different question, but actually one I wanted to ask. Is it
> usually better to make one big query, or several smaller ones?
> Performance-wise, which is better? I was under the impression it was
> generally better to combine into as few queries as possible.
For performance it is generally better to reduce the number of round
trips to the database; if you know in advance that you are going to need
several records from the same table, get them all at once. If you need
unrelated records from different tables, just do two queries. (Standard
joins are fine; don't cruft one complex SQL statement where two simple
ones are the straight-forward implementation. (Parsing and optimising
complex SQL adds to the database load.))
My gripe: avoid "SELECT *"; instead specify the fields you need for your
query. You'll reduce the load on your network (and memory use in web-
and database server.) I've seen memory overflow on the admin story list
when it loaded more than 32Mb of body texts. It only needed titles and
dates!
Peter.
More information about the geeklog-devel
mailing list