Skip to content

Commit 0b6ac43

Browse files
author
Jesse Seldess
authored
Merge pull request cockroachdb#3427 from cockroachdb/explain-statement
Add EXPLAIN(DISTSQL) and EXPLAIN ANALYZE(DISTSQL)
2 parents e37cc6b + 591f3bf commit 0b6ac43

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
73 KB
Loading

images/v2.1/explain-distsql-plan.png

49.6 KB
Loading

v2.1/explain.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Using `EXPLAIN`'s output, you can optimize your queries by taking the following
3838

3939
- Queries with fewer levels execute more quickly. Restructuring queries to require fewer levels of processing will generally improve performance.
4040

41+
- To view the distributed SQL query plan with execution statistics, use `EXPLAIN ANALYZE (DISTSQL)`.
42+
4143
- Avoid scanning an entire table, which is the slowest way to access data. You can avoid this by [creating indexes](indexes.html) that contain at least one of the columns that the query is filtering in its `WHERE` clause.
4244

4345
You can find out if your queries are performing entire table scans by using `EXPLAIN` to see which:
@@ -60,12 +62,14 @@ The user requires the appropriate [privileges](privileges.html) for the statemen
6062

6163
Parameter | Description
6264
-----------|-----------
65+
`ANALYZE` | <span class="version-tag">New in v2.1:</span> Execute the command and show execution statistics.
6366
`EXPRS` | Include the SQL expressions that are involved in each processing stage.
6467
`QUALIFY` | Include table names when referencing columns, which might be important to verify the behavior of joins across tables with the same column names.<br/><br/>To list qualified names, `QUALIFY` requires you to include the `EXPRS` option.
6568
`METADATA` | Include the columns each level uses in the **Columns** column, as well as **Ordering** detail.
6669
`VERBOSE` | Imply the `EXPRS`, `METADATA`, and `QUALIFY` options.
6770
`TYPES` | Include the intermediate [data types](data-types.html) CockroachDB chooses to evaluate intermediate SQL expressions. <br/><br/>`TYPES` also implies `METADATA` and `EXPRS` options.
68-
`OPT` | Display a query plan tree if the query will be run with the [cost-based optimizer](sql-optimizer.html). If it returns `pq: unsupported statement: *tree.Insert`, the query will not be run with the cost-based optimizer and will be run with the heuristic planner.
71+
`OPT` | <span class="version-tag">New in v2.1:</span> Display a query plan tree if the query will be run with the [cost-based optimizer](sql-optimizer.html). If it returns `pq: unsupported statement: *tree.Insert`, the query will not be run with the cost-based optimizer and will be run with the heuristic planner.
72+
`DISTSQL` | <span class="version-tag">New in v2.1:</span> Provide a link that displays a distributed SQL plan tree.
6973
`explainable_stmt` | The [statement](#explainable-statements) you want details about.
7074

7175
{{site.data.alerts.callout_danger}}<code>EXPLAIN</code> also includes other modes besides query plans that are useful only to CockroachDB developers, which are not documented here.{{site.data.alerts.end}}
@@ -365,6 +369,46 @@ pq: unsupported statement: *tree.Insert
365369

366370
The query above will not be run with the cost-based optimizer.
367371

372+
### `DISTSQL` option
373+
374+
<span class="version-tag">New in v2.1:</span> The `DISTSQL` option provides a link to a distributed query plan tree:
375+
376+
{% include copy-clipboard.html %}
377+
~~~ sql
378+
> EXPLAIN (DISTSQL) SELECT * FROM quotes WHERE episode = 13;
379+
~~~
380+
381+
~~~
382+
+-----------+----------------------------------------------+
383+
| Automatic | URL |
384+
+-----------+----------------------------------------------+
385+
| true | https://cockroachdb.github.io/distsqlplan... |
386+
+-----------+----------------------------------------------+
387+
~~~
388+
389+
Point your browser to the URL provided:
390+
391+
<img src="{{ 'images/v2.1/explain-distsql-plan.png' | relative_url }}" alt="EXPLAIN (DISTSQL)" style="border:1px solid #eee;max-width:100%" />
392+
393+
To view the distributed SQL query plan with execution statistics, use `EXPLAIN ANALYZE (DISTSQL)`:
394+
395+
{% include copy-clipboard.html %}
396+
~~~ sql
397+
> EXPLAIN ANALYZE (DISTSQL) SELECT * FROM quotes WHERE episode = 13;
398+
~~~
399+
400+
~~~
401+
+-----------+----------------------------------------------+
402+
| Automatic | URL |
403+
+-----------+----------------------------------------------+
404+
| true | https://cockroachdb.github.io/distsqlplan... |
405+
+-----------+----------------------------------------------+
406+
~~~
407+
408+
Point your browser to the URL provided:
409+
410+
<img src="{{ 'images/v2.1/explain-analyze-distsql-plan.png' | relative_url }}" alt="EXPLAIN ANALYZE (DISTSQL)" style="border:1px solid #eee;max-width:100%" />
411+
368412
### Find the indexes and key ranges a query uses
369413

370414
You can use `EXPLAIN` to understand which indexes and key ranges queries use,

0 commit comments

Comments
 (0)