Skip to content

Commit 8dbd1e4

Browse files
author
Lauren
committed
Edits based on Jesse's feedback
1 parent e15db26 commit 8dbd1e4

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

v2.1/explain.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ The user requires the appropriate [privileges](privileges.html) for the statemen
5858

5959
## Parameters
6060

61-
| Parameter | Description |
62-
|-----------|-------------|
61+
Parameter | Description
62+
-----------|-----------
6363
`EXPRS` | Include the SQL expressions that are involved in each processing stage.
6464
`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.
6565
`METADATA` | Include the columns each level uses in the **Columns** column, as well as **Ordering** detail.
6666
`VERBOSE` | Imply the `EXPRS`, `METADATA`, and `QUALIFY` options.
6767
`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 legacy heuristic planner.
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.
6969
`explainable_stmt` | The [statement](#explainable-statements) you want details about.
7070

7171
{{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}}
@@ -74,13 +74,13 @@ The user requires the appropriate [privileges](privileges.html) for the statemen
7474

7575
Successful `EXPLAIN` statements return tables with the following columns:
7676

77-
| Column | Description |
78-
|-----------|-------------|
79-
| **Tree** | A tree representation showing the hierarchy of the query plan.
80-
| **Field** | The name of a parameter relevant to the query plan node immediately above. |
81-
| **Description** | Additional information for the parameter in **Field**. |
82-
| **Columns** | The columns provided to the processes at lower levels of the hierarchy. <br/><br>This column displays only if the `METADATA` option is specified or implied. |
83-
| **Ordering** | The order in which results are presented to the processes at each level of the hierarchy, as well as other properties of the result set at each level. <br/><br>This column displays only if the `METADATA` option is specified or implied. |
77+
Column | Description
78+
-----------|-------------
79+
**Tree** | A tree representation showing the hierarchy of the query plan.
80+
**Field** | The name of a parameter relevant to the query plan node immediately above.
81+
**Description** | Additional information for the parameter in **Field**.
82+
**Columns** | The columns provided to the processes at lower levels of the hierarchy. <br/><br>This column displays only if the `METADATA` option is specified or implied.
83+
**Ordering** | The order in which results are presented to the processes at each level of the hierarchy, as well as other properties of the result set at each level. <br/><br>This column displays only if the `METADATA` option is specified or implied.
8484

8585
## Examples
8686

@@ -318,7 +318,7 @@ The `TYPES` mode includes the types of the values used in the query plan, and im
318318

319319
### `OPT` option
320320

321-
<span class="version-tag">New in v2.1:</span> The `OPT` option displays 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 legacy heuristic planner.
321+
<span class="version-tag">New in v2.1:</span> The `OPT` option displays 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.
322322

323323
For example:
324324

@@ -351,7 +351,7 @@ For example:
351351
(15 rows)
352352
~~~
353353

354-
The query above will be run with the cost-based Optimizer and `EXPLAIN (OPT)` returns the query plan tree.
354+
The query above will be run with the cost-based optimizer and `EXPLAIN (OPT)` returns the query plan tree.
355355

356356

357357
{% include copy-clipboard.html %}
@@ -363,7 +363,7 @@ The query above will be run with the cost-based Optimizer and `EXPLAIN (OPT)` re
363363
pq: unsupported statement: *tree.Insert
364364
~~~
365365

366-
The query above will not be run with the cost-based Optimizer.
366+
The query above will not be run with the cost-based optimizer.
367367

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

v2.1/sql-optimizer.md

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
---
22
title: SQL Optimizer
3-
summary: Learn about the SQL Optimizer
4-
toc: false
3+
summary: Learn about the SQL optimizer
4+
toc: true
55
---
66

7-
<span class="version-tag">New in v2.1:</span> The cost-based Optimizer seeks the lowest cost for a query, usually related to time.
7+
<span class="version-tag">New in v2.1:</span> The cost-based optimizer seeks the lowest cost for a query, usually related to time.
88

99
In versions prior to v2.1, a heuristic planner was used to generate query execution plans.
10-
In version 2.1, CockroachDB's new **cost-based Optimizer will be enabled by default**, and the legacy heuristic planner will only be used in the following cases:
10+
In version 2.1, CockroachDB's new **cost-based optimizer will be enabled by default**, and the heuristic planner will only be used in the following cases:
1111

12-
- If your query uses functionality that is not supported by the cost-based Optimizer
13-
- If you explicitly [turn off the cost-based Optimizer](#how-to-turn-the-optimizer-off)
12+
- If your query uses functionality that is not supported by the cost-based optimizer
13+
- If you explicitly [turn off the cost-based optimizer](#how-to-turn-the-optimizer-off)
1414

1515
{% include {{ page.version.version }}/misc/beta-warning.md %}
1616

1717
<div id="toc"></div>
1818

1919
## View query plan
2020

21-
To see whether a given query will be run with the cost-based Optimizer, run the query with [`EXPLAIN (OPT)`](explain.html#opt-option). If `EXPLAIN (OPT)` returns a query plan tree, that query will be run with the cost-based Optimizer. If it returns `pq: unsupported statement: *tree.Insert`, the query will not be run with the cost-based Optimizer.
21+
To see whether a query will be run with the cost-based optimizer, run the query with [`EXPLAIN (OPT)`](explain.html#opt-option). If `EXPLAIN (OPT)` returns a query plan tree, the query will use the cost-based optimizer. If it returns `pq: unsupported statement: *tree.Insert`, the query will use the heuristic planner.
2222

23-
For example:
23+
For example, the following query returns the query plan tree, which means that it will be run with the cost-based optimizer:
2424

2525
{% include copy-clipboard.html %}
2626
~~~ sql
@@ -51,8 +51,7 @@ For example:
5151
(15 rows)
5252
~~~
5353

54-
The query above will be run with the cost-based Optimizer and `EXPLAIN (OPT)` returns the query plan tree.
55-
54+
In contrast, this query returns `pq: unsupported statement: *tree.Insert`, which means that it will use the legacy heuristic planner instead of the cost-based optimizer:
5655

5756
{% include copy-clipboard.html %}
5857
~~~ sql
@@ -63,34 +62,32 @@ The query above will be run with the cost-based Optimizer and `EXPLAIN (OPT)` re
6362
pq: unsupported statement: *tree.Insert
6463
~~~
6564

66-
The query above will not be run with the cost-based Optimizer.
67-
68-
## How to turn the Optimizer off
65+
## How to turn the optimizer off
6966

70-
With the Optimizer turned on, the performance of some workloads may change. If your workload performs worse than expected (e.g., lower throughput or higher latency), you can turn off the cost-based Optimizer and use the heuristic Optimizer.
67+
With the optimizer turned on, the performance of some workloads may change. If your workload performs worse than expected (e.g., lower throughput or higher latency), you can turn off the cost-based optimizer and use the heuristic planner.
7168

72-
To turn the cost-based Optimizer off by session:
69+
To turn the cost-based optimizer off for the current session:
7370

7471
{% include copy-clipboard.html %}
7572
~~~ sql
7673
> SET experimental_opt = 'off';
7774
~~~
7875

79-
To change the cost-based Optimizer's default cluster setting:
76+
To turn the cost-based optimizer off for all sessions:
8077

8178
{% include copy-clipboard.html %}
8279
~~~ sql
8380
> SET CLUSTER SETTING sql.defaults.optimizer = 'off';
8481
~~~
8582

8683
{{site.data.alerts.callout_info}}
87-
Changing the cluster setting does not immediately turn the Optimizer off; instead, it changes the default session setting to `off`. To see the change, restart your session.
84+
Changing the cluster setting does not immediately turn the optimizer off; instead, it changes the default session setting to `off`. To see the change, restart your session.
8885
{{site.data.alerts.end}}
8986

9087
## Known limitations
9188

92-
- The optimizer will not support automated use of statistics during this time period.
93-
- Some features present in v2.0 are not supported by the Optimizer; however, the Optimizer will fall back to the v2.0 code path for this functionality. If performance in the new alpha is worse than v2.0, you can [turn the Optimizer off](#how-to-turn-the-optimizer-off) to manually force it to fallback to the heuristic planner.
89+
- The cost-based optimizer will not support automated use of statistics during this time period.
90+
- Some features present in v2.0 are not supported by the cost-based optimizer; however, the optimizer will fall back to the v2.0 code path for this functionality. If performance in the new alpha is worse than v2.0, you can [turn the optimizer off](#how-to-turn-the-optimizer-off) to manually force it to fallback to the heuristic planner.
9491
- Some correlated subqueries are not supported yet.
9592

9693
## See also

0 commit comments

Comments
 (0)