美文网首页
PostgreSQL Explain Basics

PostgreSQL Explain Basics

作者: PythonDeveloper | 来源:发表于2016-07-20 09:24 被阅读19次

    source
    The structure of a query plan is a tree of plan nodes. Nodes at the bottom level of the tree are scan nodes: they return raw nodes from a table.

    Different types of scan nodes

    • sequential scans
    • index scans
    • bitmap index scans

    If the query requires joining, aggregation, sorting or other operation on the raw rows, there will be additional nodes above the scan nodes to perform these operations.

    The output of EXPLAIN has one line for each node in the plan tree, showing the basic node type plus the cost estimates that the planner made for the execution of that plan node.

    An example of a simple EXPLAIN output:

    EXPLAIN SELECT * FROM tenk1;
    Seq Scan on tenk1  (cost=0.00..458.00 rows=10000 width=244)
    

    Content of the output:

    • sequential scan node
    • the first cost before '..' is estimated start-up cost.
    • estimated total cost
    • estimated number of rows returned
    • estimated average row width returned in bytes

    Get number of pages and rows in a table

    SELECT relpages, reltuples from pg_class where relanme = 'collection';
    estimated_cost = disk_pages_read * seq_page_cost + rows_scanned * cpu_tuple_cost
    

    相关文章

      网友评论

          本文标题:PostgreSQL Explain Basics

          本文链接:https://www.haomeiwen.com/subject/jkrvjttx.html