Skip to content

Add EXPLAIN - #439

Merged
tamnd merged 3 commits into
mainfrom
explain
Oct 20, 2026
Merged

tamnd merged 3 commits into
mainfrom
explain

Conversation

@tamnd

@tamnd tamnd commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Summary

This change adds EXPLAIN to the session. The planner makes a tree of plan nodes for a query, and the session shows the tree in the text, JSON, XML and YAML forms, as PostgreSQL 19 does. In the scripts against the PostgreSQL 19 oracle, 193 of 222 statements give the same output.

Changes

  • rupg-plan has the plan nodes and the output of EXPLAIN in each form.
  • rupg-opt makes the plan of a query: the scans, the joins, the aggregates, the windows, the set operations, the sorts, LIMIT, the subplans and the init plans, and the node of a statement that writes a table. It has the costs of PostgreSQL with no statistics.
  • rupg-func writes the expressions of the plan with the names of the relations that EXPLAIN chooses, and the names of the subplans and of the windows.
  • The session reads the options of EXPLAIN and their errors, and gives one row for each line of the text form, or one row for the other forms.
  • The windows sort as select_active_windows sorts them, and a window with no name takes the name w1, w2 and so on in that order.
  • The grouping sets with more items come first. DISTINCT ON sorts on all the items of ORDER BY.
  • A VALUES with one row that is the only relation becomes a Result.
  • The keys of a set operation show with the names of the leftmost SELECT.
  • The subquery of EXISTS gives no output. The scan of an UPDATE gives only the new values of the columns of SET and ctid, and the scan of a DELETE gives only ctid.
  • The rows of unnest of a constant array are the number of its elements.

Known differences

  • There is no index scan, and the planner does not know the unique keys of a table, so Inner Unique is always false.
  • The planner does not pull up subqueries, views, IN, EXISTS, NOT EXISTS and ANY into joins, and it does not push conditions into subqueries or into UNION ALL.
  • There is no exists_to_any, no MinMaxAggregate, and no order of the joins of three or more relations from equivalence classes.
  • VERBOSE does not show the output of RETURNING on the node that writes the table.
  • ANALYZE, GENERIC_PLAN, MEMORY and EXPLAIN EXECUTE give an error that they are not supported yet.
  • EXPLAIN in the extended protocol is not supported yet.

Tests

  • connection/explain.test and connection/explain_keys.test are the output of PostgreSQL 19 for the same scripts in a new database.
  • fmt, clippy, the workspace tests and the checks of xtask pass on server1.

@tamnd tamnd added kind/feature It does not do something that it must do. area/session Sessions, settings, pooling and the server runtime. area/sql The grammar, the lexer, the analyzer and the rewriter. labels Oct 20, 2026
@tamnd
tamnd merged commit 823fe27 into main Oct 20, 2026
@tamnd
tamnd deleted the explain branch October 20, 2026 05:31
This was referenced Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/session Sessions, settings, pooling and the server runtime. area/sql The grammar, the lexer, the analyzer and the rewriter. kind/feature It does not do something that it must do.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant