From 8d5ceb113e3f7ddb627bd40b26438a9d2fa05512 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Wed, 26 Mar 2025 13:52:21 -0400 Subject: pg_overexplain: Additional EXPLAIN options for debugging. There's a fair amount of information in the Plan and PlanState trees that isn't printed by any existing EXPLAIN option. This means that, when working on the planner, it's often necessary to rely on facilities such as debug_print_plan, which produce excessively voluminous output. Hence, use the new EXPLAIN extension facilities to implement EXPLAIN (DEBUG) and EXPLAIN (RANGE_TABLE) as extensions to the core EXPLAIN facility. A great deal more could be done here, and the specific choices about what to print and how are definitely arguable, but this is at least a starting point for discussion and a jumping-off point for possible future improvements. Reviewed-by: Sami Imseih Reviewed-by: Tom Lane Reviweed-by: Andrei Lepikhov (who didn't like it) Discussion: http://postgr.es/m/CA+TgmoZfvQUBWQ2P8iO30jywhfEAKyNzMZSR+uc2xr9PZBw6eQ@mail.gmail.com --- doc/src/sgml/contrib.sgml | 1 + doc/src/sgml/filelist.sgml | 1 + doc/src/sgml/pgoverexplain.sgml | 186 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+) create mode 100644 doc/src/sgml/pgoverexplain.sgml (limited to 'doc/src') diff --git a/doc/src/sgml/contrib.sgml b/doc/src/sgml/contrib.sgml index 7c381949a53..24b706b29ad 100644 --- a/doc/src/sgml/contrib.sgml +++ b/doc/src/sgml/contrib.sgml @@ -155,6 +155,7 @@ CREATE EXTENSION extension_name; &pgcrypto; &pgfreespacemap; &pglogicalinspect; + &pgoverexplain; &pgprewarm; &pgrowlocks; &pgstatstatements; diff --git a/doc/src/sgml/filelist.sgml b/doc/src/sgml/filelist.sgml index 25fb99cee69..fef9584f908 100644 --- a/doc/src/sgml/filelist.sgml +++ b/doc/src/sgml/filelist.sgml @@ -145,6 +145,7 @@ + diff --git a/doc/src/sgml/pgoverexplain.sgml b/doc/src/sgml/pgoverexplain.sgml new file mode 100644 index 00000000000..102bd275aed --- /dev/null +++ b/doc/src/sgml/pgoverexplain.sgml @@ -0,0 +1,186 @@ + + + + pg_overexplain — allow EXPLAIN to dump even more details + + + pg_overexplain + + + + The pg_overexplain extends EXPLAIN + with new options that provide additional output. It is mostly intended to + assist with debugging of and development of the planner, rather than for + general use. Since this module displays internal details of planner data + structures, it may be necessary to refer to the source code to make sense + of the output. Furthermore, the output is likely to change whenever (and as + often as) those data structures change. + + + + EXPLAIN (DEBUG) + + + The DEBUG option displays miscellaneous information from + the plan tree that is not normally shown because it is not expected to be + of general interest. For each individual plan node, it will display the + following fields. See Plan in + nodes/plannodes.h for additional documentation of these + fields. + + + + + + Disabled Nodes. Normal EXPLAIN + determines whether a node is disabled by checking whether the node's + count of disabled nodes is larger than the sum of the counts for the + underlying nodes. This option shows the raw counter value. + + + + + + Parallel Safe. Indicates whether it would be safe for + a plan tree node to appear beneath a Gather or + Gather Merge node, regardless of whether it is + actually below such a node. + + + + + + Plan Node ID. An internal ID number that should be + unique for every node in the plan tree. It is used to coordinate parallel + query activity. + + + + + + extParam and allParam. Information + about which numbered parameters affect this plan node or its children. In + text mode, these fields are only displayed if they are non-empty sets. + + + + + + Once per query, the DEBUG option will display the + following fields. See PlannedStmt in + nodes/plannodes.h for additional detail. + + + + + + Command Type. For example, select + or update. + + + + + + Flags. A comma-separated list of Boolean structure + member names from the PlannedStmt that are set to + true. It covers the following structure members: + hasReturning, hasModifyingCTE, + canSetTag, transientPlan, + dependsOnRole, parallelModeNeeded. + + + + + + Subplans Needing Rewind. Integer IDs of subplans that + may need to be rewound by the executor. + + + + + + Relation OIDs. OIDs of relations upon which this plan + depends. + + + + + + Executor Parameter Types. Type OID for each executor parameter + (e.g. when a nested loop is chosen and a parameter is used to pass a value down + to an inner index scan). Does not include parameters supplied to a prepared + statement by the user. + + + + + + Parse Location. Location within the query string + supplied to the planner where this query's text can be found. May be + Unknown in some contexts. Otherwise, may be + NNN to end for some integer NNN or + NNN for MMM bytes for some integers + NNN and MMM. + + + + + + + EXPLAIN (RANGE_TABLE) + + + The RANGE_TABLE option displays information from the + plan tree specifically concerning the query's range table. Range table + entries correspond roughly to items appearing in the query's + FROM clause, but with numerous exceptions. For example, + subqueries that are proved unnecessary may be deleted from the range table + entirely, while inheritance expansion adds range table entries for child + tables that are not named directly in the query. + + + + Range table entries are generally referenced within the query plan by a + range table index, or RTI. Plan nodes that reference one or more RTIs will + be labelled accordingly, using one of the following fields: Scan + RTI, Nominal RTI, Exclude Relation + RTI, Append RTIs. + + + + In addition, the query as a whole may maintain lists of range table indexes + that are needed for various purposes. These lists will be displayed once + per query, labelled as appropriate as Unprunable RTIs or + Result RTIs. In text mode, these fields are only + displayed if they are non-empty sets. + + + + Finally, but most importantly, the RANGE_TABLE option + will display a dump of the query's entire range table. Each range table + entry is labelled with the appropriate range table index, the kind of range + table entry (e.g. relation, + subquery, or join), followed by the + contents of various range table entry fields that are not normally part of + EXPLAIN output. Some of these fields are only displayed + for certain kinds of range table entries. For example, + Eref is displayed for all types of range table entries, + but CTE Name is displayed only for range table entries + of type cte. + + + + For more information about range table entries, see the definition of + RangeTblEntry in nodes/plannodes.h. + + + + + Author + + + Robert Haas rhaas@postgresql.org + + + + -- cgit v1.2.3