Finding the execution plan
Now, we know that the planner has quite a few decisions to make and that these decisions will ultimately decide the execution time as well as consumption of resources (CPU, memory, and disk I/O). How do we know what decision the planner will take? We can use the EXPLAIN
command to find out the possible (note that it's possible) execution plan. To use EXPLAIN
, we have to just prefix the EXPLAIN
word to the SQL statement we want to execute, as shown here:
EXPLAIN SELECT first_name FROM customer_master WHERE first_name = 'Carolee'; QUERY PLAN ----------------------------------------------------------------- Seq Scan on customer_master (cost=0.00..271.62 rows=3 width=6) Filter: ((first_name)::text = 'Carolee'::text) (2 rows)
The query plan should be read from most indented to least intended: from bottom to top. Each line with cost/rows/width is a node. The inner (child) nodes feed the outer (parent) nodes. In...