PostgreSQL Tips and Tricks
blog.gtuhl.com
blog.gtuhl.com
Yes, it's no secret that large joins on huge amounts of data can often be very intensive. From that does not follow, however, the exhortation to simply avoid them categorically. That's a little too much blanket statement for me.
For instance, joins are often used in situations where there is a numeric type column that refers to a very small table of enumerated values that have a textual or other translation, and there is a need to produce the latter in a single query. There's nothing wrong with that join from a performance standpoint, even for very large values of n.
Having a single awkward example does not detract from that.
I'll add to this by noting the post does say "For smaller tables it doesn’t matter but as tables get bigger avoid joining when you can" which is sound advice.
I'd say joining scales up to perhaps a million or two rows unless you have a lot of RAM (you can see join spills to disk in the EXPLAIN ANALYZE output). I often am working with tables in the 10-30 million row range so my perspective is probably a little slanted towards the negative.
Most of the serious commercial databases I've worked with/near/on have been de-normalised to some extent.
e.g. SalesForce run massive amounts of data. Their implementation really boils down to one de-normalised table; with a dozen or so supporting tables.
When I hear about some (not all) NoSQL implementations I occasionally wonder why they just didn't adopt a de-normalised SQL solution.
SQL Server + NHibernate does handle the CRUD stuff, custom fields and DDD-based domain logic very well.
NoSQL (CouchDB in our case) doesn't handle transactions, locking and business rules effectively. However it excels at providing extremely fast views on schemaless data such as our core domain model plus custom fields.
There is definitely a place for NoSQL. However, many projects simply don't need to bite this off. They could start with SQL, from there you can decide how rigid/structured you want to be... I definitely agree that this comes with baggage; but if you're prepared to be pragmatic it's often got a lot of upside.
* Throw away the normal forms you learned in school
* Denormalize [...] whenever it makes a query faster.
I think that's bad advice as stated. As you imply, you have to know why the rules are there to know when to break them intelligently. I didn't get that message from the item as posted, rather that the author thought that NF had little value, which probably doesn't belong in a list of database tips and tricks.
[edit: format]
One approach is to make all your denormalizations populated by triggers -- that way to you can still think about the DB in "clean" terms in your code when modifying data, but get your denormalized tables for queries, too.
If you have 30 million rows in a table you absolutely cannot do joins so you bring everything in that you commonly need.
All of those deficiencies may have since been eliminated.
We peak at 1000s of transactions a second on an OLTP database that is over 100GB in size and PostgreSQL handles it like a champ.
Any nice reference about pgsql and query optimization? Any book recommendation?
As an old mysql guy, as far as I do db:s, the advice re subqueries (#4) was unusual... :-)
(I looked at trying pgsql for a hobby a few years back and found lacking support for different char sets for different tables, etc. Is that [still] so?)
(No book recommendations for something like e.g. "High Performance MySQL"? Well, nice with no fanatical fanboys in this area, at least. :-)
The current 8.3 documentation is here: http://www.postgresql.org/docs/8.3/static/
I especially enjoy the sections on indexes: http://www.postgresql.org/docs/8.3/static/indexes.html