Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a specific problem: huge amounts of Web-related data in Postgres db. The queries running against the data are often very inefficient.

But in a more general sense, I need a book that explains well the "magic" behind execution of particular SQL queries and how to refactor or rewrite them.

I mean smth like this in a book form, covering a range of issues most frequently encountered in practice:

An ideal book would regard PG, but needs not to. Have you read such a book that would actually help you understand sql query execution plans and how to write efficient queries?

share|improve this question

closed as not constructive by dezso, Mark Storey-Smith, Martin Smith, Phil, ypercubeᵀᴹ Jan 23 '13 at 15:46

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

What about: (the content is also available as a book) – a_horse_with_no_name Jan 23 '13 at 11:09
@a_horse_with_no_name: woo hoo! This is VERY nice! Thanks!!! Although it is limited mostly to indexes, this is still a big chunk of what I'm looking for! Why did this thing not come up in my googling? – mrkafk Jan 23 '13 at 11:30
Well query tuning is mostly about finding the best index to support the query. You might be interested in the chapter about JOINs: – a_horse_with_no_name Jan 23 '13 at 11:33
Books about optimizations I liked are "The Art of SQL" by Stephane Faroult and Peter Robson (not specific for PostgreSQL, but it's exactly about what you want) and "PostgreSQL 9.0 High Performance" by Gregory Smith. – j.p. Jan 23 '13 at 13:01