Book Image

PostgreSQL Cookbook

By : Chitij Chauhan
Book Image

PostgreSQL Cookbook

By: Chitij Chauhan

Overview of this book

<p>PostgreSQL is an open source database management system. It is used for a wide variety of development practices such as software and web design, as well as for handling large datasets (big data).</p> <p>With the goal of teaching you the skills to master PostgreSQL, the book begins by giving you a glimpse of the unique features of PostgreSQL and how to utilize them to solve real-world problems. With the aid of practical examples, the book will then show you how to create and manage databases. You will learn how to secure PostgreSQL, perform administration and maintenance tasks, implement high availability features, and provide replication. The book will conclude by teaching you how to migrate information from other databases to PostgreSQL.</p>
Table of Contents (19 chapters)
PostgreSQL Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting the execution plan for a statement


In this recipe, we are going to see how to get the execution plan for a SQL statement.

Getting ready

The EXPLAIN command is used to get the execution plan for a SQL statement.

How to do it...

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. The EXPLAIN command can be invoked as follows:

    dvdrental=# EXPLAIN  select * from payment where amount > 4.99;
                             QUERY PLAN
    --------------...