Understanding the concept of execution plans

It is impossible to understand the use of indexes without understanding the concept of execution plans. Whenever you execute a query in PostgreSQL, it generally goes through four central steps, described as follows:

  • Parser: PostgreSQL will check the syntax of the statement.
  • Rewrite system: PostgreSQL will rewrite the query (for example, rules and views are handled by the rewrite system).
  • Optimizer or planner: PostgreSQL will come up with a smart plan to execute the query as efficiently as possible. At this step, the system will decide whether or not to use indexes.
  • Executor: Finally, the execution plan is taken by the executor and the result is generated.

Being able to understand and read execution plans ...

Get PostgreSQL Administration Essentials 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.