You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[explain] new syntax (LIR-based, Postgres like) (#32262)
Introduces new default syntax for `EXPLAIN`, such that now (1) `EXPLAIN`
by default explains LIR plans, which have unambiguous interpretations
(unlike MIR plans), and (2) `EXPLAIN` shows information in a
Postgres-like syntax, and significantly less information than it used to
for `EXPLAIN PHYSICAL PLAN FOR` (i.e., for LIR).
You can still explain MIR plans with the old syntax using `EXPLAIN
OPTIMIZED PLAN FOR`.
You can still explain LIR plans with the old, very verbose syntax using
`EXPLAIN PHYSICAL PLAN AS VERBOSE TEXT FOR`.
Remaining TODOs:
- [x] Update docs for `mz_lir_mapping` to describe new operator names.
- [x] Write docs for new default syntax.
- [x] Write test for new default syntax.
- [x] Write changelog post.
MaterializeInc/www#1457
Some remaining questions should be resolved by follow-up PRs, per conversation with @ggevay.
MaterializeInc/database-issues#9375MaterializeInc/database-issues#9376MaterializeInc/database-issues#9377
### Motivation
* This PR adds a known-desirable feature.
#31643MaterializeInc/database-issues#8889
Copy file name to clipboardExpand all lines: doc/user/content/sql/explain-plan.md
+52-20Lines changed: 52 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,12 +96,13 @@ FOR ] -- The FOR keyword is required if the PLAN keyword is specified
96
96
{{</tab>}}
97
97
{{</tabs>}}
98
98
99
-
Note that the `FOR` keyword is required if the `PLAN` keyword is present. In other words, the following three statements are equivalent:
99
+
Note that the `FOR` keyword is required if the `PLAN` keyword is present. The following four statements are equivalent:
100
100
101
101
```mzsql
102
102
EXPLAIN <explainee>;
103
103
EXPLAIN PLAN FOR <explainee>;
104
-
EXPLAIN OPTIMIZED PLAN FOR <explainee>;
104
+
EXPLAIN PHYSICAL PLAN FOR <explainee>;
105
+
EXPLAIN PHYSICAL PLAN AS TEXT FOR <explainee>;
105
106
```
106
107
107
108
### Explained object
@@ -138,8 +139,8 @@ Plan Stage | Description
138
139
**RAW PLAN** | Display the raw plan; this is closest to the original SQL.
139
140
**DECORRELATED PLAN** | Display the decorrelated but not-yet-optimized plan.
140
141
**LOCALLY OPTIMIZED** | Display the locally optimized plan (before view inlining and access path selection). This is the final stage for regular `CREATE VIEW` optimization.
141
-
**OPTIMIZED PLAN** | _(Default)_Display the optimized plan.
142
-
**PHYSICAL PLAN** | Display the physical plan; this is close but not identical to the operators shown in [`mz_introspection.mz_lir_mapping`](../../sql/system-catalog/mz_introspection/#mz_lir_mapping).
142
+
**OPTIMIZED PLAN** | Display the optimized plan.
143
+
**PHYSICAL PLAN** | _(Default)_Display the physical plan; this corresponds to the operators shown in [`mz_introspection.mz_lir_mapping`](../../sql/system-catalog/mz_introspection/#mz_lir_mapping).
143
144
144
145
### Output modifiers
145
146
@@ -246,19 +247,38 @@ Materialize plans are directed, potentially cyclic, graphs of operators. Each op
246
247
receives inputs from zero or more other operators and produces a single output.
247
248
Sub-graphs where each output is consumed only once are rendered as tree-shaped fragments.
248
249
Sub-graphs consumed more than once are represented as common table expressions (CTEs).
249
-
In the example below, the CTE `l0` represents a linear sub-plan (a chain of `Get`,
250
-
`Filter`, and `Project` operators) which is used in both inputs of a self-join.
250
+
In the example below, the CTE `l0` represents a linear sub-plan (a chain of `Read` from the table `t`)
251
+
which is used in both inputs of a self-join (`Differential Join`).
Note that CTEs in optimized plans do not directly correspond to CTEs in your original SQL query: For example, CTEs might disappear due to inlining (i.e., when a CTE is used only once, its definition is copied to that usage site); new CTEs can appear due to the optimizer recognizing that a part of the query appears more than once (aka common subexpression elimination). Also, certain SQL-level concepts, such as outer joins or subqueries, do not have an explicit representation in optimized plans, and are instead expressed as a pattern of operators involving CTEs. CTE names are always `l0`, `l1`, `l2`, ..., and do not correspond to SQL-level CTE names.
@@ -270,7 +290,7 @@ Many operators need to refer to columns in their input. These are displayed like
270
290
columns assigned to `Map` operators, it might be useful to request [the `arity` output modifier](#output-modifiers).
271
291
272
292
Each operator can also be annotated with additional metadata. Details are shown
273
-
by default in the `EXPLAIN PHYSICAL PLAN` output, but are hidden elsewhere. <a
293
+
by default in the `EXPLAIN PHYSICAL PLAN` output (the default), but are hidden elsewhere. <a
Operators are sometimes marked as `Fused ...`. We write this to mean that the operator is fused with its input. That is, if you see a `Fused X` operator above a `Y` operator:
374
+
375
+
```
376
+
→Fused X
377
+
→Y
378
+
```
379
+
380
+
Then the `X` and `Y` operators will be combined into a single, more efficient operator.
353
381
354
382
## Examples
355
383
@@ -489,6 +517,10 @@ EXPLAIN PHYSICAL PLAN FOR
489
517
MATERIALIZED VIEW my_mat_view;
490
518
```
491
519
520
+
## Debugging running dataflows
521
+
522
+
The [`EXPLAIN ANALYZE`](/sql/explain-analyze/) statement will let you debug memory and cpu usage (optionally with information about worker skew) for existing indexes and materialized views in terms of their physical plan operators. It can also attribute [TopK hints](/transform-data/idiomatic-materialize-sql/top-k/#query-hints-1) to individual operators.
523
+
492
524
## Privileges
493
525
494
526
The privileges required to execute this statement are:
0 commit comments