Appendix A. Five optimization tips
I wrote this book to walk you through the breadth and depth of Postgres’s capabilities. Each chapter is designed as a hands-on technical guide that lets you spin up a Postgres container, load a sample dataset, and experience a Postgres capability in action. My goal is for you to finish each chapter thinking, “Postgres can really do that too!”
To support this kind of learning, I intentionally avoid overloading you with too many details, best practices, or pitfalls: first, because too much too soon might discourage you from using any technology in the first place; and second, because your journey with Postgres shouldn’t end with this book. Once you're done here, keep building real-world apps with Postgres and pick up more tips, tricks, and gotchas from other resources—and, more importantly, from your own experience.
That said, I can’t resist sharing my top five query optimization tips. These should help you write more efficient code and design better solutions with Postgres. Let’s run through them briefly.
A.1 Master using EXPLAIN
Throughout the book, we use the EXPLAIN command to analyze and compare execution plans generated by Postgres. Most of the time, a statement with EXPLAIN looks as follows:
EXPLAIN (analyze, costs off) SELECT...