O'Reilly logo

PostgreSQL High Performance Cookbook by Dinesh Kumar, Chitij Chauhan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required