In this recipe, we are going to see how to get the execution plan for a SQL statement.
Every query that is triggered in PostgreSQL has an execution plan. The EXPLAIN
command can be run in any of the three given modes:
Generic Mode: In this mode, we just need to specify the
EXPLAIN
command followed by the SQL statement. The PostgreSQL planner will display the execution plan that it generated for the specified SQL statement. The execution plan will show the scan method used to access the table referenced in the query. Other details included could be the estimated execution cost of the SQL statement, which is the planner's estimation of how long it will take to execute the SQL statement. TheEXPLAIN
command can be invoked as follows:dvdrental=# EXPLAIN select * from payment where amount > 4.99; QUERY PLAN --------------...