{
    "content": [
        {
            "type": "text",
            "text": "# EXPLAIN (man)\n\n## NAME\n\nEXPLAIN - show the execution plan of a statement\n\n## SYNOPSIS\n\nEXPLAIN [ ( option [, ...] ) ] statement\nEXPLAIN [ ANALYZE ] [ VERBOSE ] statement\nwhere option can be one of:\nANALYZE [ boolean ]\nVERBOSE [ boolean ]\nCOSTS [ boolean ]\nSETTINGS [ boolean ]\nBUFFERS [ boolean ]\nWAL [ boolean ]\nTIMING [ boolean ]\nSUMMARY [ boolean ]\nFORMAT { TEXT | XML | JSON | YAML }\n\n## DESCRIPTION\n\nThis command displays the execution plan that the PostgreSQL planner generates for the\nsupplied statement. The execution plan shows how the table(s) referenced by the statement\nwill be scanned — by plain sequential scan, index scan, etc. — and if multiple tables are\nreferenced, what join algorithms will be used to bring together the required rows from each\ninput table.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **OUTPUTS**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "EXPLAIN",
        "section": "",
        "mode": "man",
        "summary": "EXPLAIN - show the execution plan of a statement",
        "synopsis": "EXPLAIN [ ( option [, ...] ) ] statement\nEXPLAIN [ ANALYZE ] [ VERBOSE ] statement\nwhere option can be one of:\nANALYZE [ boolean ]\nVERBOSE [ boolean ]\nCOSTS [ boolean ]\nSETTINGS [ boolean ]\nBUFFERS [ boolean ]\nWAL [ boolean ]\nTIMING [ boolean ]\nSUMMARY [ boolean ]\nFORMAT { TEXT | XML | JSON | YAML }",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "To show the plan for a simple query on a table with a single integer column and 10000 rows:",
            "EXPLAIN SELECT * FROM foo;",
            "QUERY PLAN",
            "---------------------------------------------------------",
            "Seq Scan on foo  (cost=0.00..155.00 rows=10000 width=4)",
            "(1 row)",
            "Here is the same query, with JSON output formatting:",
            "EXPLAIN (FORMAT JSON) SELECT * FROM foo;",
            "QUERY PLAN",
            "--------------------------------",
            "[                             +",
            "{                           +",
            "\"Plan\": {                 +",
            "\"Node Type\": \"Seq Scan\",+",
            "\"Relation Name\": \"foo\", +",
            "\"Alias\": \"foo\",         +",
            "\"Startup Cost\": 0.00,   +",
            "\"Total Cost\": 155.00,   +",
            "\"Plan Rows\": 10000,     +",
            "\"Plan Width\": 4         +",
            "}                         +",
            "}                           +",
            "(1 row)",
            "If there is an index and we use a query with an indexable WHERE condition, EXPLAIN might show",
            "a different plan:",
            "EXPLAIN SELECT * FROM foo WHERE i = 4;",
            "QUERY PLAN",
            "--------------------------------------------------------------",
            "Index Scan using fi on foo  (cost=0.00..5.98 rows=1 width=4)",
            "Index Cond: (i = 4)",
            "(2 rows)",
            "Here is the same query, but in YAML format:",
            "EXPLAIN (FORMAT YAML) SELECT * FROM foo WHERE i='4';",
            "QUERY PLAN",
            "-------------------------------",
            "- Plan:                      +",
            "Node Type: \"Index Scan\"  +",
            "Scan Direction: \"Forward\"+",
            "Index Name: \"fi\"         +",
            "Relation Name: \"foo\"     +",
            "Alias: \"foo\"             +",
            "Startup Cost: 0.00       +",
            "Total Cost: 5.98         +",
            "Plan Rows: 1             +",
            "Plan Width: 4            +",
            "Index Cond: \"(i = 4)\"",
            "(1 row)",
            "XML format is left as an exercise for the reader.",
            "Here is the same plan with cost estimates suppressed:",
            "EXPLAIN (COSTS FALSE) SELECT * FROM foo WHERE i = 4;",
            "QUERY PLAN",
            "----------------------------",
            "Index Scan using fi on foo",
            "Index Cond: (i = 4)",
            "(2 rows)",
            "Here is an example of a query plan for a query using an aggregate function:",
            "EXPLAIN SELECT sum(i) FROM foo WHERE i < 10;",
            "QUERY PLAN",
            "---------------------------------------------------------------------",
            "Aggregate  (cost=23.93..23.93 rows=1 width=4)",
            "->  Index Scan using fi on foo  (cost=0.00..23.92 rows=6 width=4)",
            "Index Cond: (i < 10)",
            "(3 rows)",
            "Here is an example of using EXPLAIN EXECUTE to display the execution plan for a prepared",
            "query:",
            "PREPARE query(int, int) AS SELECT sum(bar) FROM test",
            "WHERE id > $1 AND id < $2",
            "GROUP BY foo;",
            "EXPLAIN ANALYZE EXECUTE query(100, 200);",
            "QUERY PLAN",
            "------------------------------------------------------------------------------------------------------------------------",
            "HashAggregate  (cost=9.54..9.54 rows=1 width=8) (actual time=0.156..0.161 rows=11 loops=1)",
            "Group Key: foo",
            "->  Index Scan using testpkey on test  (cost=0.29..9.29 rows=50 width=8) (actual time=0.039..0.091 rows=99 loops=1)",
            "Index Cond: ((id > $1) AND (id < $2))",
            "Planning time: 0.197 ms",
            "Execution time: 0.225 ms",
            "(6 rows)",
            "Of course, the specific numbers shown here depend on the actual contents of the tables",
            "involved. Also note that the numbers, and even the selected query strategy, might vary",
            "between PostgreSQL releases due to planner improvements. In addition, the ANALYZE command",
            "uses random sampling to estimate data statistics; therefore, it is possible for cost",
            "estimates to change after a fresh run of ANALYZE, even if the actual distribution of data in",
            "the table has not changed."
        ],
        "see_also": [
            {
                "name": "ANALYZE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ANALYZE/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 15,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 37,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 72,
                "subsections": []
            },
            {
                "name": "OUTPUTS",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 14,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 107,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "EXPLAIN - show the execution plan of a statement\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "EXPLAIN [ ( option [, ...] ) ] statement\nEXPLAIN [ ANALYZE ] [ VERBOSE ] statement\n\nwhere option can be one of:\n\nANALYZE [ boolean ]\nVERBOSE [ boolean ]\nCOSTS [ boolean ]\nSETTINGS [ boolean ]\nBUFFERS [ boolean ]\nWAL [ boolean ]\nTIMING [ boolean ]\nSUMMARY [ boolean ]\nFORMAT { TEXT | XML | JSON | YAML }\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This command displays the execution plan that the PostgreSQL planner generates for the\nsupplied statement. The execution plan shows how the table(s) referenced by the statement\nwill be scanned — by plain sequential scan, index scan, etc. — and if multiple tables are\nreferenced, what join algorithms will be used to bring together the required rows from each\ninput table.\n\nThe most critical part of the display is the estimated statement execution cost, which is the\nplanner's guess at how long it will take to run the statement (measured in cost units that\nare arbitrary, but conventionally mean disk page fetches). Actually two numbers are shown:\nthe start-up cost before the first row can be returned, and the total cost to return all the\nrows. For most queries the total cost is what matters, but in contexts such as a subquery in\nEXISTS, the planner will choose the smallest start-up cost instead of the smallest total cost\n(since the executor will stop after getting one row, anyway). Also, if you limit the number\nof rows to return with a LIMIT clause, the planner makes an appropriate interpolation between\nthe endpoint costs to estimate which plan is really the cheapest.\n\nThe ANALYZE option causes the statement to be actually executed, not only planned. Then\nactual run time statistics are added to the display, including the total elapsed time\nexpended within each plan node (in milliseconds) and the total number of rows it actually\nreturned. This is useful for seeing whether the planner's estimates are close to reality.\n\nImportant\nKeep in mind that the statement is actually executed when the ANALYZE option is used.\nAlthough EXPLAIN will discard any output that a SELECT would return, other side effects\nof the statement will happen as usual. If you wish to use EXPLAIN ANALYZE on an INSERT,\nUPDATE, DELETE, CREATE TABLE AS, or EXECUTE statement without letting the command affect\nyour data, use this approach:\n\nBEGIN;\nEXPLAIN ANALYZE ...;\nROLLBACK;\n\nOnly the ANALYZE and VERBOSE options can be specified, and only in that order, without\nsurrounding the option list in parentheses. Prior to PostgreSQL 9.0, the unparenthesized\nsyntax was the only one supported. It is expected that all new options will be supported only\nin the parenthesized syntax.\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "ANALYZE\nCarry out the command and show actual run times and other statistics. This parameter\ndefaults to FALSE.\n\nVERBOSE\nDisplay additional information regarding the plan. Specifically, include the output\ncolumn list for each node in the plan tree, schema-qualify table and function names,\nalways label variables in expressions with their range table alias, and always print the\nname of each trigger for which statistics are displayed. The query identifier will also\nbe displayed if one has been computed, see computequeryid for more details. This\nparameter defaults to FALSE.\n\nCOSTS\nInclude information on the estimated startup and total cost of each plan node, as well as\nthe estimated number of rows and the estimated width of each row. This parameter defaults\nto TRUE.\n\nSETTINGS\nInclude information on configuration parameters. Specifically, include options affecting\nquery planning with value different from the built-in default value. This parameter\ndefaults to FALSE.\n\nBUFFERS\nInclude information on buffer usage. Specifically, include the number of shared blocks\nhit, read, dirtied, and written, the number of local blocks hit, read, dirtied, and\nwritten, the number of temp blocks read and written, and the time spent reading and\nwriting data file blocks (in milliseconds) if trackiotiming is enabled. A hit means\nthat a read was avoided because the block was found already in cache when needed. Shared\nblocks contain data from regular tables and indexes; local blocks contain data from\ntemporary tables and indexes; while temp blocks contain short-term working data used in\nsorts, hashes, Materialize plan nodes, and similar cases. The number of blocks dirtied\nindicates the number of previously unmodified blocks that were changed by this query;\nwhile the number of blocks written indicates the number of previously-dirtied blocks\nevicted from cache by this backend during query processing. The number of blocks shown\nfor an upper-level node includes those used by all its child nodes. In text format, only\nnon-zero values are printed. It defaults to FALSE.\n\nWAL\nInclude information on WAL record generation. Specifically, include the number of\nrecords, number of full page images (fpi) and the amount of WAL generated in bytes. In\ntext format, only non-zero values are printed. This parameter may only be used when\nANALYZE is also enabled. It defaults to FALSE.\n\nTIMING\nInclude actual startup time and time spent in each node in the output. The overhead of\nrepeatedly reading the system clock can slow down the query significantly on some\nsystems, so it may be useful to set this parameter to FALSE when only actual row counts,\nand not exact times, are needed. Run time of the entire statement is always measured,\neven when node-level timing is turned off with this option. This parameter may only be\nused when ANALYZE is also enabled. It defaults to TRUE.\n\nSUMMARY\nInclude summary information (e.g., totaled timing information) after the query plan.\nSummary information is included by default when ANALYZE is used but otherwise is not\nincluded by default, but can be enabled using this option. Planning time in EXPLAIN\nEXECUTE includes the time required to fetch the plan from the cache and the time required\nfor re-planning, if necessary.\n\nFORMAT\nSpecify the output format, which can be TEXT, XML, JSON, or YAML. Non-text output\ncontains the same information as the text output format, but is easier for programs to\nparse. This parameter defaults to TEXT.\n\nboolean\nSpecifies whether the selected option should be turned on or off. You can write TRUE, ON,\nor 1 to enable the option, and FALSE, OFF, or 0 to disable it. The boolean value can also\nbe omitted, in which case TRUE is assumed.\n\nstatement\nAny SELECT, INSERT, UPDATE, DELETE, VALUES, EXECUTE, DECLARE, CREATE TABLE AS, or CREATE\nMATERIALIZED VIEW AS statement, whose execution plan you wish to see.\n",
                "subsections": []
            },
            "OUTPUTS": {
                "content": "The command's result is a textual description of the plan selected for the statement,\noptionally annotated with execution statistics.  Section 14.1 describes the information\nprovided.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "In order to allow the PostgreSQL query planner to make reasonably informed decisions when\noptimizing queries, the pgstatistic data should be up-to-date for all tables used in the\nquery. Normally the autovacuum daemon will take care of that automatically. But if a table\nhas recently had substantial changes in its contents, you might need to do a manual ANALYZE\nrather than wait for autovacuum to catch up with the changes.\n\nIn order to measure the run-time cost of each node in the execution plan, the current\nimplementation of EXPLAIN ANALYZE adds profiling overhead to query execution. As a result,\nrunning EXPLAIN ANALYZE on a query can sometimes take significantly longer than executing the\nquery normally. The amount of overhead depends on the nature of the query, as well as the\nplatform being used. The worst case occurs for plan nodes that in themselves require very\nlittle time per execution, and on machines that have relatively slow operating system calls\nfor obtaining the time of day.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "To show the plan for a simple query on a table with a single integer column and 10000 rows:\n\nEXPLAIN SELECT * FROM foo;\n\nQUERY PLAN\n---------------------------------------------------------\nSeq Scan on foo  (cost=0.00..155.00 rows=10000 width=4)\n(1 row)\n\nHere is the same query, with JSON output formatting:\n\nEXPLAIN (FORMAT JSON) SELECT * FROM foo;\nQUERY PLAN\n--------------------------------\n[                             +\n{                           +\n\"Plan\": {                 +\n\"Node Type\": \"Seq Scan\",+\n\"Relation Name\": \"foo\", +\n\"Alias\": \"foo\",         +\n\"Startup Cost\": 0.00,   +\n\"Total Cost\": 155.00,   +\n\"Plan Rows\": 10000,     +\n\"Plan Width\": 4         +\n}                         +\n}                           +\n]\n(1 row)\n\nIf there is an index and we use a query with an indexable WHERE condition, EXPLAIN might show\na different plan:\n\nEXPLAIN SELECT * FROM foo WHERE i = 4;\n\nQUERY PLAN\n--------------------------------------------------------------\nIndex Scan using fi on foo  (cost=0.00..5.98 rows=1 width=4)\nIndex Cond: (i = 4)\n(2 rows)\n\nHere is the same query, but in YAML format:\n\nEXPLAIN (FORMAT YAML) SELECT * FROM foo WHERE i='4';\nQUERY PLAN\n-------------------------------\n- Plan:                      +\nNode Type: \"Index Scan\"  +\nScan Direction: \"Forward\"+\nIndex Name: \"fi\"         +\nRelation Name: \"foo\"     +\nAlias: \"foo\"             +\nStartup Cost: 0.00       +\nTotal Cost: 5.98         +\nPlan Rows: 1             +\nPlan Width: 4            +\nIndex Cond: \"(i = 4)\"\n(1 row)\n\nXML format is left as an exercise for the reader.\n\nHere is the same plan with cost estimates suppressed:\n\nEXPLAIN (COSTS FALSE) SELECT * FROM foo WHERE i = 4;\n\nQUERY PLAN\n----------------------------\nIndex Scan using fi on foo\nIndex Cond: (i = 4)\n(2 rows)\n\nHere is an example of a query plan for a query using an aggregate function:\n\nEXPLAIN SELECT sum(i) FROM foo WHERE i < 10;\n\nQUERY PLAN\n---------------------------------------------------------------------\nAggregate  (cost=23.93..23.93 rows=1 width=4)\n->  Index Scan using fi on foo  (cost=0.00..23.92 rows=6 width=4)\nIndex Cond: (i < 10)\n(3 rows)\n\nHere is an example of using EXPLAIN EXECUTE to display the execution plan for a prepared\nquery:\n\nPREPARE query(int, int) AS SELECT sum(bar) FROM test\nWHERE id > $1 AND id < $2\nGROUP BY foo;\n\nEXPLAIN ANALYZE EXECUTE query(100, 200);\n\nQUERY PLAN\n------------------------------------------------------------------------------------------------------------------------\nHashAggregate  (cost=9.54..9.54 rows=1 width=8) (actual time=0.156..0.161 rows=11 loops=1)\nGroup Key: foo\n->  Index Scan using testpkey on test  (cost=0.29..9.29 rows=50 width=8) (actual time=0.039..0.091 rows=99 loops=1)\nIndex Cond: ((id > $1) AND (id < $2))\nPlanning time: 0.197 ms\nExecution time: 0.225 ms\n(6 rows)\n\nOf course, the specific numbers shown here depend on the actual contents of the tables\ninvolved. Also note that the numbers, and even the selected query strategy, might vary\nbetween PostgreSQL releases due to planner improvements. In addition, the ANALYZE command\nuses random sampling to estimate data statistics; therefore, it is possible for cost\nestimates to change after a fresh run of ANALYZE, even if the actual distribution of data in\nthe table has not changed.\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "There is no EXPLAIN statement defined in the SQL standard.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "ANALYZE(7)\n\n\n\nPostgreSQL 14.23                                2026                                      EXPLAIN(7)",
                "subsections": []
            }
        }
    }
}