]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix pg_overexplain to emit valid output with RANGE_TABLE option.
authorAmit Langote <amitlan@postgresql.org>
Thu, 16 Apr 2026 04:47:07 +0000 (13:47 +0900)
committerAmit Langote <amitlan@postgresql.org>
Thu, 16 Apr 2026 04:47:07 +0000 (13:47 +0900)
commit059cf7f58d23fc53423e4e58feaaa717faef53c5
treed247ed1f0cf298747593ccabb1a10c03404b9c2c
parentb5062a4e57fcdd51949a046314ec90731bdbf92c
Fix pg_overexplain to emit valid output with RANGE_TABLE option.

overexplain_range_table() emitted the "Unprunable RTIs" and "Result
RTIs" properties before closing the "Range Table" group.  In the JSON
and YAML formats the Range Table group is rendered as an array of RTE
objects, so emitting key/value pairs inside it produced structurally
invalid output.  The XML format had a related oddity, with these
elements nested inside <Range-Table> rather than appearing as its
siblings.

These fields are properties of the PlannedStmt as a whole, not of any
individual RTE, so close the Range Table group before emitting them.
They now appear as siblings of "Range Table" in the parent Query
object, which is what was intended.

Also add a test exercising FORMAT JSON with RANGE_TABLE so that any
future regression in the output structure is caught.

Reported-by: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Author: Satyanarayana Narlapuram <satyanarlapuram@gmail.com>
Reviewed-by: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAHg+QDdDrdqMr98a_OBYDYmK3RaT7XwCEShZfvDYKZpZTfOEjQ@mail.gmail.com
Backpatch-through: 18
contrib/pg_overexplain/expected/pg_overexplain.out
contrib/pg_overexplain/pg_overexplain.c
contrib/pg_overexplain/sql/pg_overexplain.sql