Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXPLAIN(DISTSQL,TYPES) #7045

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified images/v20.1/explain-distsql-plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/v20.1/explain-distsql-types-plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion v19.1/explain-analyze.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Any or all of the above fields may display for a given query plan.

## Example

`EXPLAIN ANALYZE` executes a query and generate a link to a physical query plan with execution statistics:
`EXPLAIN ANALYZE` executes a query and generates a link to a physical query plan, with execution statistics.

{% include copy-clipboard.html %}
~~~ sql
Expand Down
2 changes: 1 addition & 1 deletion v19.2/explain-analyze.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Any or all of the above fields may display for a given query plan.

## Example

`EXPLAIN ANALYZE` executes a query and generates a link to a physical query plan with execution statistics:
The following `EXPLAIN ANALYZE` statement executes a simple query against the [TPC-H database](http://www.tpc.org/tpch/) loaded to a 3-node CockroachDB cluster, and then generates a link to a physical query plan with execution statistics:

{% include copy-clipboard.html %}
~~~ sql
Expand Down
2 changes: 2 additions & 0 deletions v19.2/explain.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ The `DISTSQL` option generates a URL for a physical query plan that provides hig
{% include {{ page.version.version }}/sql/physical-plan-url.md %}
{{site.data.alerts.end}}

For example, the following `EXPLAIN(DISTSQL)` statement generates a physical plan for a simple query against the [TPC-H database](http://www.tpc.org/tpch/) loaded to a 3-node CockroachDB cluster:

{% include copy-clipboard.html %}
~~~ sql
> EXPLAIN (DISTSQL) SELECT l_shipmode, AVG(l_extendedprice) FROM lineitem GROUP BY l_shipmode;
Expand Down
5 changes: 3 additions & 2 deletions v20.1/explain-analyze.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Out | The output columns.
@<n> | The index of the column relative to the input.
Render | The stage that renders the output.
unordered / ordered | _(Blue box)_ A synchronizer that takes one or more output streams and merges them to be consumable by a processor. An ordered synchronizer is used to merge ordered streams and keeps the rows in sorted order.
&lt;data type&gt; | <span class="version-tag">New in v20.1:</span> If [`EXPLAIN(DISTSQL, TYPES)`](explain.html#distsql-option) is specified, lists the data types of the input columns.
left(@&lt;n&gt;)=right(@&lt;n&gt;) | The equality columns used in the join.
rows read | The number of rows read by the processor.
stall time | How long the processor spent not doing work. This is aggregated into the stall time numbers as the query progresses down the tree (i.e., stall time is added up and overlaps with previous time).
Expand All @@ -69,7 +70,7 @@ Any or all of the above fields may display for a given query plan.

## Example

`EXPLAIN ANALYZE` executes a query and generates a link to a physical query plan with execution statistics:
The following `EXPLAIN ANALYZE` statement executes a simple query against the [TPC-H database](http://www.tpc.org/tpch/) loaded to a 3-node CockroachDB cluster, and then generates a link to a physical query plan with execution statistics:

{% include copy-clipboard.html %}
~~~ sql
Expand All @@ -78,7 +79,7 @@ Any or all of the above fields may display for a given query plan.

~~~
automatic | url
+-----------+----------------------------------------------+
------------+-----------------------------------------------
true | https://cockroachdb.github.io/distsqlplan...
~~~

Expand Down
20 changes: 20 additions & 0 deletions v20.1/explain.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ The `DISTSQL` option generates a URL for a physical query plan that provides hig
{% include {{ page.version.version }}/sql/physical-plan-url.md %}
{{site.data.alerts.end}}

For example, the following `EXPLAIN(DISTSQL)` statement generates a physical plan for a simple query against the [TPC-H database](http://www.tpc.org/tpch/) loaded to a 3-node CockroachDB cluster:

{% include copy-clipboard.html %}
~~~ sql
> EXPLAIN (DISTSQL) SELECT l_shipmode, AVG(l_extendedprice) FROM lineitem GROUP BY l_shipmode;
Expand All @@ -424,6 +426,24 @@ To view the [DistSQL Plan Viewer](explain-analyze.html#distsql-plan-viewer), poi

<img src="{{ 'images/v20.1/explain-distsql-plan.png' | relative_url }}" alt="EXPLAIN (DISTSQL)" style="border:1px solid #eee;max-width:100%" />

<span class="version-tag">New in v20.1:</span> To include the data types of the input columns in the physical plan, use `EXPLAIN(DISTSQL, TYPES)`:

{% include copy-clipboard.html %}
~~~ sql
> EXPLAIN (DISTSQL, TYPES) SELECT l_shipmode, AVG(l_extendedprice) FROM lineitem GROUP BY l_shipmode;
~~~

~~~
automatic | url
-----------+----------------------------------------------
true | https://cockroachdb.github.io/distsqlplan...
~~~

To view the [DistSQL Plan Viewer](explain-analyze.html#distsql-plan-viewer), point your browser to the URL provided:

<img src="{{ 'images/v20.1/explain-distsql-types-plan.png' | relative_url }}" alt="EXPLAIN (DISTSQL)" style="border:1px solid #eee;max-width:100%" />


### Find the indexes and key ranges a query uses

You can use `EXPLAIN` to understand which indexes and key ranges queries use, which can help you ensure a query isn't performing a full table scan.
Expand Down