Examples of query tuning
In the previous section, you learned how EXPLAIN
can show the plan PostgreSQL will use to access the underlying data; it is now time to use EXPLAIN
to tune some slow queries and improve performance.
This section will show you some basic concepts of the day-to-day usage of EXPLAIN
as a powerful tool to determine where and how to instrument PostgreSQL in accessing data faster. Of course, query tuning is a very complex subject and often requires repeated trial-based optimization, so the aim of this section is not to provide you with in-depth knowledge about query tuning but rather a basic understanding of how to improve your own database and queries.
Sometimes, tuning a query involves simply rewriting it in a way that is more comfortable for – or better, more comprehensible to – PostgreSQL, but most often, query tuning means using an appropriate index to speed up access to the underlying data.
One important thing to take into account...