| From: | Mohamed ALi <moali(dot)pg(at)gmail(dot)com> |
|---|---|
| To: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: [PATCH] Add NESTED_STATEMENTS option to EXPLAIN |
| Date: | 2026-05-21 20:51:58 |
| Message-ID: | CAGnOmWoyrffJeJ9uz6wkB0arO4BPDMRK-YemicT1Prp4umtrJA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Attached is v3 of the patch with the following improvements over v2:
New features:
- Execution Time per nested statement: each nested statement now shows
its total execution time (using query_instr->total, same source as
auto_explain). Controlled by the SUMMARY option — shown by default
with ANALYZE, hidden with SUMMARY OFF.
- Structured output formats: when using FORMAT JSON, XML, or YAML,
nested plans are now emitted as proper structured objects (with
Node Type, Plans array, typed fields, etc.) instead of flat text
strings. Each nested plan is a valid, independently parseable
document in the chosen format.
I also added new tests to the comprehensive test script to cover the
new features (now 24 tests).
One thing I'm considering for a future version: adding an option to
limit the number of captured statements or maximum nesting depth, e.g.:
EXPLAIN (ANALYZE, NESTED_STATEMENTS 10) SELECT complex_func();
-- or --
EXPLAIN (ANALYZE, NESTED_STATEMENTS, MAX_DEPTH 2) SELECT complex_func();
This would help with complex functions that execute hundreds of nested
statements. Would this be useful, or is the current behavior (capture
all) sufficient?
Attachments:
1- v3-0001-Add-NESTED_STATEMENTS-option-to-EXPLAIN.patch
2- comprehensive_nested_statements_test_v3.sql
3- test_output_all_v3.txt
Mohamed Ali
AWS RDS
| Attachment | Content-Type | Size |
|---|---|---|
| test_output_all_v3.txt | text/plain | 99.0 KB |
| v3-0001-Add-NESTED_STATEMENTS-option-to-EXPLAIN.patch | application/octet-stream | 23.6 KB |
| comprehensive_nested_statements_test_v3.sql | application/octet-stream | 41.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Tom Lane | 2026-05-21 20:25:13 | Re: Is there value in having optimizer stats for joins/foreignkeys? |