8.8. Basic Optimizations Using EXPLAIN

After you have written the queries needed by your application, you will soon find out that some sort of tuning might be necessary. The more complex your queries are, the more likely it is that a lot of performance can be gained by changing some simple parameters.

8.8.1. Using EXPLAIN

To find out what the database does internally, PostgreSQL provides a command called EXPLAIN:

phpbook=# \h EXPLAIN
Command:     EXPLAIN
Description: show the execution plan of a statement
Syntax:
EXPLAIN [ ANALYZE ] [ VERBOSE ] query

As you can see, the syntax of the command is easy.

With the help of EXPLAIN it is possible to find out how PostgreSQL processes a query internally. EXPLAIN displays the so-called execution plan on ...

Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.