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
Copy file name to clipboardExpand all lines: v2.1/explain.md
+13-13
Original file line number
Diff line number
Diff line change
@@ -58,14 +58,14 @@ The user requires the appropriate [privileges](privileges.html) for the statemen
58
58
59
59
## Parameters
60
60
61
-
|Parameter | Description|
62
-
|-----------|-------------|
61
+
Parameter | Description
62
+
-----------|-----------
63
63
`EXPRS` | Include the SQL expressions that are involved in each processing stage.
64
64
`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.
65
65
`METADATA` | Include the columns each level uses in the **Columns** column, as well as **Ordering** detail.
66
66
`VERBOSE` | Imply the `EXPRS`, `METADATA`, and `QUALIFY` options.
67
67
`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.
69
69
`explainable_stmt` | The [statement](#explainable-statements) you want details about.
70
70
71
71
{{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
74
74
75
75
Successful `EXPLAIN` statements return tables with the following columns:
76
76
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.
84
84
85
85
## Examples
86
86
@@ -318,7 +318,7 @@ The `TYPES` mode includes the types of the values used in the query plan, and im
318
318
319
319
### `OPT` option
320
320
321
-
<spanclass="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
+
<spanclass="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.
322
322
323
323
For example:
324
324
@@ -351,7 +351,7 @@ For example:
351
351
(15 rows)
352
352
~~~
353
353
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.
355
355
356
356
357
357
{% include copy-clipboard.html %}
@@ -363,7 +363,7 @@ The query above will be run with the cost-based Optimizer and `EXPLAIN (OPT)` re
363
363
pq: unsupported statement: *tree.Insert
364
364
~~~
365
365
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.
Copy file name to clipboardExpand all lines: v2.1/sql-optimizer.md
+16-19
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,26 @@
1
1
---
2
2
title: SQL Optimizer
3
-
summary: Learn about the SQL Optimizer
4
-
toc: false
3
+
summary: Learn about the SQL optimizer
4
+
toc: true
5
5
---
6
6
7
-
<spanclass="version-tag">New in v2.1:</span> The cost-based Optimizer seeks the lowest cost for a query, usually related to time.
7
+
<spanclass="version-tag">New in v2.1:</span> The cost-based optimizer seeks the lowest cost for a query, usually related to time.
8
8
9
9
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:
11
11
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)
14
14
15
15
{% include {{ page.version.version }}/misc/beta-warning.md %}
16
16
17
17
<divid="toc"></div>
18
18
19
19
## View query plan
20
20
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.
22
22
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:
24
24
25
25
{% include copy-clipboard.html %}
26
26
~~~sql
@@ -51,8 +51,7 @@ For example:
51
51
(15 rows)
52
52
~~~
53
53
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:
56
55
57
56
{% include copy-clipboard.html %}
58
57
~~~sql
@@ -63,34 +62,32 @@ The query above will be run with the cost-based Optimizer and `EXPLAIN (OPT)` re
63
62
pq: unsupported statement: *tree.Insert
64
63
~~~
65
64
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
69
66
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.
71
68
72
-
To turn the cost-based Optimizer off by session:
69
+
To turn the cost-based optimizer off for the current session:
73
70
74
71
{% include copy-clipboard.html %}
75
72
~~~sql
76
73
>SET experimental_opt ='off';
77
74
~~~
78
75
79
-
To change the cost-based Optimizer's default cluster setting:
76
+
To turn the cost-based optimizer off for all sessions:
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.
88
85
{{site.data.alerts.end}}
89
86
90
87
## Known limitations
91
88
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.
94
91
- Some correlated subqueries are not supported yet.
0 commit comments