-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql statements: add create binding, drop binding and show bindings (#…
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: CREATE BINDING | ||
summary: TiDB 数据库中 CREATE BINDING 的使用概况。 | ||
category: reference | ||
--- | ||
|
||
# CREATE BINDING | ||
|
||
`CREATE BINDING` 语句用于在 TiDB 上创建新 SQL BIND。 | ||
|
||
## 语法图 | ||
|
||
**CreateBindingStmt:** | ||
|
||
![CreateBindingStmt](/media/sqlgram/CreateBindingStmt.png) | ||
|
||
**GlobalScope:** | ||
|
||
![GlobalScope](/media/sqlgram/GlobalScope.png) | ||
|
||
**SelectStmt** | ||
|
||
![SelectStmt](/media/sqlgram/SelectStmt.png) | ||
|
||
**** | ||
|
||
## 语法说明 | ||
|
||
{{< copyable "sql" >}} | ||
|
||
```sql | ||
CREATE [GLOBAL | SESSION] BINDING FOR SelectStmt USING SelectStmt; | ||
``` | ||
|
||
该语句可以在 GLOBAL 或者 SESSION 作用域内为 SQL 绑定执行计划。在不指定作用域时,隐式作用域为 SESSION。 | ||
|
||
被绑定的 SQL 会被参数化后存储到系统表中。在处理 SQL 查询时,只要参数化后的 SQL 和系统表中某个被绑定的 SQL 语句一致,并且系统变量 `tidb_use_plan_baselines` 的值为 `on`(其默认值为 `on`),即可使用相应的优化器 Hint。如果存在多个可匹配的执行计划,优化器会从中选择代价最小的一个进行绑定。 | ||
|
||
## 另请参阅 | ||
|
||
* [DROP BINDING](/sql-statements/sql-statement-drop-binding.md) | ||
* [SHOW BINDINGS](/sql-statements/sql-statement-show-bindings.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: DROP BINDING | ||
summary: TiDB 数据库中 DROP BINDING 的使用概况。 | ||
category: reference | ||
--- | ||
|
||
# DROP BINDING | ||
|
||
`DROP BINDING` 语句用于逻辑删除指定的 SQL BIND。 | ||
|
||
## 语法图 | ||
|
||
**DropBindingStmt:** | ||
|
||
![DropBindingStmt](/media/sqlgram/DropBindingStmt.png) | ||
|
||
**GlobalScope:** | ||
|
||
![GlobalScope](/media/sqlgram/GlobalScope.png) | ||
|
||
**SelectStmt** | ||
|
||
![SelectStmt](/media/sqlgram/SelectStmt.png) | ||
|
||
## 语法说明 | ||
|
||
{{< copyable "sql" >}} | ||
|
||
```sql | ||
DROP [GLOBAL | SESSION] BINDING FOR SelectStmt; | ||
``` | ||
|
||
该语句可以在 GLOBAL 或者 SESSION 作用域内删除指定的执行计划绑定,在不指定作用域时默认作用域为 SESSION。 | ||
|
||
## 另请参阅 | ||
|
||
* [CREATE BINDING](/sql-statements/sql-statement-create-binding.md) | ||
* [SHOW BINDINGS](/sql-statements/sql-statement-show-bindings.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
title: SHOW BINDINGS | ||
summary: TiDB 数据库中 SHOW BINDINGS 的使用概况。 | ||
category: reference | ||
--- | ||
|
||
# SHOW BINDINGS | ||
|
||
`SHOW BINDINGS` 语句用于显示所有创建过的 SQL BIND 的相关信息。 | ||
|
||
## 语法图 | ||
|
||
**ShowStmt:** | ||
|
||
![ShowStmt](/media/sqlgram/ShowStmt.png) | ||
|
||
**ShowTargetFilterable:** | ||
|
||
![ShowTargetFilterable](/media/sqlgram/ShowTargetFilterable.png) | ||
|
||
**GlobalScope:** | ||
|
||
![GlobalScope](/media/sqlgram/GlobalScope.png) | ||
|
||
**ShowLikeOrWhereOpt** | ||
|
||
![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png) | ||
|
||
## 语法说明 | ||
|
||
{{< copyable "sql" >}} | ||
|
||
```sql | ||
SHOW [GLOBAL | SESSION] BINDINGS [ShowLikeOrWhereOpt]; | ||
``` | ||
|
||
该语句会输出 GLOBAL 或者 SESSION 作用域内的执行计划绑定,在不指定作用域时默认作用域为 SESSION。目前 `SHOW BINDINGS` 会输出 8 列,具体如下: | ||
|
||
| 列名 | 说明 | | ||
| -------- | ------------- | | ||
| original_sql | 参数化后的原始 SQL | | ||
| bind_sql | 带 Hint 的绑定 SQL | | ||
| default_db | 默认数据库名 | | ||
| status | 状态,包括 using(正在使用)、deleted(已删除)、 invalid(无效)、rejected(演进时被拒绝)和 pending verify(等待演进验证) | | ||
| create_time | 创建时间 | | ||
| update_time | 更新时间 | | ||
| charset | 字符集 | | ||
| collation | 排序规则 | | ||
|
||
## 另请参阅 | ||
|
||
* [CREATE BINDING](/sql-statements/sql-statement-create-binding.md) | ||
* [DROP BINDING](/sql-statements/sql-statement-drop-binding.md) |