Computing basic cost

In this recipe, we will be discussing how the optimizer chooses the optimal plan from the set of plans that it generates.

Getting ready

PostgreSQL generates a set of plans based on the optimizer attributes such as enable_seqscan, enable_indexscan, and so on. Among these generated sets of plans, PostgreSQL will only choose the plan that has the minimum cost value when compared with the other plans.

How to do it…

  1. Let's generate a simple plan, as shown in the following snippet, and evaluate it:
    benchmarksql=# SHOW seq_page_cost;
     seq_page_cost
    ---------------
     1
    (1 row) benchmarksql=# EXPLAIN SELECT * FROM bmsql_customer;
                                   QUERY PLAN                                
    -------------------------------------------------------------------------
     Seq Scan on bmsql_customer ...

Get PostgreSQL High Performance Cookbook 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.