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: http://explainextended.com/2009/09/17/not-in-vs-not-exists-vs-left-join-is-null-oracle/
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?