From 3bcfbe53723d09c868a4769fd6e166de9a47b60a Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Wed, 17 Jun 2020 13:45:17 +0800 Subject: [PATCH 01/14] sql-statements: add sql statements for sql bind --- .../sql-statement-create-binding.md | 42 +++++++++++++++ sql-statements/sql-statement-drop-binding.md | 38 +++++++++++++ sql-statements/sql-statement-show-bindings.md | 54 +++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 sql-statements/sql-statement-create-binding.md create mode 100644 sql-statements/sql-statement-drop-binding.md create mode 100644 sql-statements/sql-statement-show-bindings.md diff --git a/sql-statements/sql-statement-create-binding.md b/sql-statements/sql-statement-create-binding.md new file mode 100644 index 0000000000000..3d04b0bd5cb21 --- /dev/null +++ b/sql-statements/sql-statement-create-binding.md @@ -0,0 +1,42 @@ +--- +title: CREATE BINDING +summary: Use of CREATE BINDING in TiDB database. +category: reference +--- + +# CREATE BINDING + +The `CREATE BINDING` statement is used to create a new SQL bind on TiDB. + +## Statement Diagram + +**CreateBindingStmt:** + +![CreateBindingStmt](/media/sqlgram/CreateBindingStmt.png) + +**GlobalScope:** + +![GlobalScope](/media/sqlgram/GlobalScope.png) + +**SelectStmt** + +![SelectStmt](/media/sqlgram/SelectStmt.png) + +**** + +## Statement Description + +{{< copyable "sql" >}} + +```sql +CREATE [GLOBAL | SESSION] BINDING FOR SelectStmt USING SelectStmt; +``` + +This statement binds SQL execution plans at the GLOBAL or SESSION level. The default scope is SESSION. The bound SQL statement is parameterized and stored in the system table. When a SQL query is processed, as long as the parameterized SQL statement and a bound one in the system table are consistent and the system variable `tidb_use_plan_baselines` is set to `on` (the default value is `on`), the corresponding optimizer hint is available. If multiple execution plans are available, the optimizer chooses to bind the plan with the least cost. + +When a SQL statement has bound execution plans in both GLOBAL and SESSION scopes, because the optimizer ignores the bound execution plan in the GLOBAL scope when it encounters the SESSION binding, the bound execution plan of this statement in the SESSION scope shields the execution plan in the GLOBAL scope. + +## See also + +* [DROP BINDING](/sql-statements/sql-statement-drop-binding.md) +* [SHOW BINDINGS](/sql-statements/sql-statement-show-bindings.md) diff --git a/sql-statements/sql-statement-drop-binding.md b/sql-statements/sql-statement-drop-binding.md new file mode 100644 index 0000000000000..ba790f6529e7f --- /dev/null +++ b/sql-statements/sql-statement-drop-binding.md @@ -0,0 +1,38 @@ +--- +title: DROP BINDING +summary: Use of DROP BINDING in TiDB database. +category: reference +--- + +# DROP BINDING + +The `DROP BINDING` statement is used to drop a SQL bind on TiDB. + +## Statement Diagram + +**DropBindingStmt:** + +![DropBindingStmt](/media/sqlgram/DropBindingStmt.png) + +**GlobalScope:** + +![GlobalScope](/media/sqlgram/GlobalScope.png) + +**SelectStmt** + +![SelectStmt](/media/sqlgram/SelectStmt.png) + +## Statement Description + +{{< copyable "sql" >}} + +```sql +DROP [GLOBAL | SESSION] BINDING FOR SelectStmt; +``` + +This statement removes a specified execution plan binding at the GLOBAL or SESSION level. The default scope is SESSION. + +## See also + +* [CREATE BINDING](/sql-statements/sql-statement-create-binding.md) +* [SHOW BINDINGS](/sql-statements/sql-statement-show-bindings.md) diff --git a/sql-statements/sql-statement-show-bindings.md b/sql-statements/sql-statement-show-bindings.md new file mode 100644 index 0000000000000..553c6791280a5 --- /dev/null +++ b/sql-statements/sql-statement-show-bindings.md @@ -0,0 +1,54 @@ +--- +title: SHOW BINDINGS +summary: Use of SHOW BINDINGS binding in TiDB database. +category: reference +--- + +# SHOW BINDINGS + +The `SHOW BINDINGS` statement is used to display information about all created SQL BIND. + +## Statement Diagram + +**ShowStmt:** + +![ShowStmt](/media/sqlgram/ShowStmt.png) + +**ShowTargetFilterable:** + +![ShowTargetFilterable](/media/sqlgram/ShowTargetFilterable.png) + +**GlobalScope:** + +![GlobalScope](/media/sqlgram/GlobalScope.png) + +**ShowLikeOrWhereOpt** + +![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png) + +## Statement Description + +{{< copyable "sql" >}} + +```sql +SHOW [GLOBAL | SESSION] BINDINGS [ShowLikeOrWhereOpt]; +``` + +This statement outputs the execution plan bindings at the GLOBAL or SESSION level. The default scope is SESSION. Currently `SHOW BINDINGS` outputs eight columns, as shown below: + +| Column Name | Note | +| :-------- | :------------- | +| original_sql | Original SQL statement after parameterization | +| bind_sql | Bound SQL statement with hints | +| default_db | Default database | +| status | Status including 'Using', 'Deleted', 'Invalid', 'Rejected', and 'Pending verification'| +| create_time | Creating time | +| update_time | Updating time | +| charset | Character set | +| collation | Ordering rule | +| source | Create way,include 'manual', 'capture' and 'evolve' | + +## See also + +* [CREATE BINDING](/sql-statements/sql-statement-create-binding.md) +* [DROP BINDING](/sql-statements/sql-statement-drop-binding.md) From 4e44ebc243030a6b7504bc093ec5425dc6829318 Mon Sep 17 00:00:00 2001 From: lzmhhh123 Date: Wed, 17 Jun 2020 13:47:29 +0800 Subject: [PATCH 02/14] change TOC.md --- TOC.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TOC.md b/TOC.md index 31442104ad26c..65775f2deb289 100644 --- a/TOC.md +++ b/TOC.md @@ -212,6 +212,7 @@ + [`BEGIN`](/sql-statements/sql-statement-begin.md) + [`CHANGE COLUMN`](/sql-statements/sql-statement-change-column.md) + [`COMMIT`](/sql-statements/sql-statement-commit.md) + + [`CREATE BINDING`](/sql-statements/sql-statement-create-binding.md) + [`CREATE DATABASE`](/sql-statements/sql-statement-create-database.md) + [`CREATE INDEX`](/sql-statements/sql-statement-create-index.md) + [`CREATE SEQUENCE`](/sql-statements/sql-statement-create-sequence.md) @@ -224,6 +225,7 @@ + [`DESC`](/sql-statements/sql-statement-desc.md) + [`DESCRIBE`](/sql-statements/sql-statement-describe.md) + [`DO`](/sql-statements/sql-statement-do.md) + + [`DROP BINDING`](/sql-statements/sql-statement-drop-binding.md) + [`DROP COLUMN`](/sql-statements/sql-statement-drop-column.md) + [`DROP DATABASE`](/sql-statements/sql-statement-drop-database.md) + [`DROP INDEX`](/sql-statements/sql-statement-drop-index.md) @@ -259,6 +261,7 @@ + [`SET [GLOBAL|SESSION] `](/sql-statements/sql-statement-set-variable.md) + [`SHOW ANALYZE STATUS`](/sql-statements/sql-statement-show-analyze-status.md) + [`SHOW [BACKUPS|RESTORES]`](/sql-statements/sql-statement-show-backups.md) + + [`SHOW BINDINGS`](/sql-statements/sql-statement-show-bindings.md) + [`SHOW BUILTINS`](/sql-statements/sql-statement-show-builtins.md) + [`SHOW CHARACTER SET`](/sql-statements/sql-statement-show-character-set.md) + [`SHOW COLLATION`](/sql-statements/sql-statement-show-collation.md) From d0cadce1036ee6c966a85ac3c6ac229484386240 Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:56:54 +0800 Subject: [PATCH 03/14] Update sql-statements/sql-statement-create-binding.md Co-authored-by: Ran --- sql-statements/sql-statement-create-binding.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-create-binding.md b/sql-statements/sql-statement-create-binding.md index 3d04b0bd5cb21..ac3c290cfb693 100644 --- a/sql-statements/sql-statement-create-binding.md +++ b/sql-statements/sql-statement-create-binding.md @@ -8,7 +8,7 @@ category: reference The `CREATE BINDING` statement is used to create a new SQL bind on TiDB. -## Statement Diagram +## Synopsis **CreateBindingStmt:** From 05339f0e1b6f0746bb2bb7f3ad17765468788701 Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:57:05 +0800 Subject: [PATCH 04/14] Update sql-statements/sql-statement-create-binding.md Co-authored-by: Ran --- sql-statements/sql-statement-create-binding.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-create-binding.md b/sql-statements/sql-statement-create-binding.md index ac3c290cfb693..106f39c071c93 100644 --- a/sql-statements/sql-statement-create-binding.md +++ b/sql-statements/sql-statement-create-binding.md @@ -32,7 +32,9 @@ The `CREATE BINDING` statement is used to create a new SQL bind on TiDB. CREATE [GLOBAL | SESSION] BINDING FOR SelectStmt USING SelectStmt; ``` -This statement binds SQL execution plans at the GLOBAL or SESSION level. The default scope is SESSION. The bound SQL statement is parameterized and stored in the system table. When a SQL query is processed, as long as the parameterized SQL statement and a bound one in the system table are consistent and the system variable `tidb_use_plan_baselines` is set to `on` (the default value is `on`), the corresponding optimizer hint is available. If multiple execution plans are available, the optimizer chooses to bind the plan with the least cost. +This statement binds SQL execution plans at the GLOBAL or SESSION scope. The default scope is SESSION. + +The bound SQL statement is parameterized and stored in the system table. When a SQL query is processed, as long as the parameterized SQL statement and a bound one in the system table are consistent and the system variable `tidb_use_plan_baselines` is set to `on` (`on` by default), the corresponding optimizer hint is available. If multiple execution plans are available, the optimizer chooses to bind the plan with the least cost. When a SQL statement has bound execution plans in both GLOBAL and SESSION scopes, because the optimizer ignores the bound execution plan in the GLOBAL scope when it encounters the SESSION binding, the bound execution plan of this statement in the SESSION scope shields the execution plan in the GLOBAL scope. From f01c41a63d4d23590f0319cb92311e081a2bcacd Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:57:19 +0800 Subject: [PATCH 05/14] Update sql-statements/sql-statement-drop-binding.md Co-authored-by: Ran --- sql-statements/sql-statement-drop-binding.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-drop-binding.md b/sql-statements/sql-statement-drop-binding.md index ba790f6529e7f..148acbb5aeb65 100644 --- a/sql-statements/sql-statement-drop-binding.md +++ b/sql-statements/sql-statement-drop-binding.md @@ -8,7 +8,7 @@ category: reference The `DROP BINDING` statement is used to drop a SQL bind on TiDB. -## Statement Diagram +## Synopsis **DropBindingStmt:** From 56f7cfdada626ee3e526729e3ecb53d57b9aabd1 Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:57:27 +0800 Subject: [PATCH 06/14] Update sql-statements/sql-statement-show-bindings.md Co-authored-by: Ran --- sql-statements/sql-statement-show-bindings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-bindings.md b/sql-statements/sql-statement-show-bindings.md index 553c6791280a5..30921889b2d45 100644 --- a/sql-statements/sql-statement-show-bindings.md +++ b/sql-statements/sql-statement-show-bindings.md @@ -26,7 +26,7 @@ The `SHOW BINDINGS` statement is used to display information about all created S ![ShowLikeOrWhereOpt](/media/sqlgram/ShowLikeOrWhereOpt.png) -## Statement Description +## Syntax description {{< copyable "sql" >}} From 71b7a27cb6f5e0a42ccd8de64a863375f91d6798 Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:57:32 +0800 Subject: [PATCH 07/14] Update sql-statements/sql-statement-drop-binding.md Co-authored-by: Ran --- sql-statements/sql-statement-drop-binding.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-drop-binding.md b/sql-statements/sql-statement-drop-binding.md index 148acbb5aeb65..27fcf8b6e4414 100644 --- a/sql-statements/sql-statement-drop-binding.md +++ b/sql-statements/sql-statement-drop-binding.md @@ -22,7 +22,7 @@ The `DROP BINDING` statement is used to drop a SQL bind on TiDB. ![SelectStmt](/media/sqlgram/SelectStmt.png) -## Statement Description +## Syntax description {{< copyable "sql" >}} From c59d15b81fd3fe6be06eb1e5d01cfe79a188859b Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:57:40 +0800 Subject: [PATCH 08/14] Update sql-statements/sql-statement-show-bindings.md Co-authored-by: Ran --- sql-statements/sql-statement-show-bindings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-bindings.md b/sql-statements/sql-statement-show-bindings.md index 30921889b2d45..750dd5ee47455 100644 --- a/sql-statements/sql-statement-show-bindings.md +++ b/sql-statements/sql-statement-show-bindings.md @@ -6,7 +6,7 @@ category: reference # SHOW BINDINGS -The `SHOW BINDINGS` statement is used to display information about all created SQL BIND. +The `SHOW BINDINGS` statement is used to display information about all created SQL bindings. ## Statement Diagram From f82772c423f568c6ee6f655383621324785ecd28 Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:58:24 +0800 Subject: [PATCH 09/14] Update sql-statements/sql-statement-show-bindings.md Co-authored-by: Ran --- sql-statements/sql-statement-show-bindings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-bindings.md b/sql-statements/sql-statement-show-bindings.md index 750dd5ee47455..ca3eaeb249b26 100644 --- a/sql-statements/sql-statement-show-bindings.md +++ b/sql-statements/sql-statement-show-bindings.md @@ -36,7 +36,7 @@ SHOW [GLOBAL | SESSION] BINDINGS [ShowLikeOrWhereOpt]; This statement outputs the execution plan bindings at the GLOBAL or SESSION level. The default scope is SESSION. Currently `SHOW BINDINGS` outputs eight columns, as shown below: -| Column Name | Note | +| Column Name | Description | | :-------- | :------------- | | original_sql | Original SQL statement after parameterization | | bind_sql | Bound SQL statement with hints | From 75b611671acc6dc1dfc78c626c43dd88b5968bcb Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:58:33 +0800 Subject: [PATCH 10/14] Update sql-statements/sql-statement-show-bindings.md Co-authored-by: Ran --- sql-statements/sql-statement-show-bindings.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-statements/sql-statement-show-bindings.md b/sql-statements/sql-statement-show-bindings.md index ca3eaeb249b26..b7928b3f45c4a 100644 --- a/sql-statements/sql-statement-show-bindings.md +++ b/sql-statements/sql-statement-show-bindings.md @@ -42,8 +42,8 @@ This statement outputs the execution plan bindings at the GLOBAL or SESSION leve | bind_sql | Bound SQL statement with hints | | default_db | Default database | | status | Status including 'Using', 'Deleted', 'Invalid', 'Rejected', and 'Pending verification'| -| create_time | Creating time | -| update_time | Updating time | +| create_time | Created time | +| update_time | Updated time | | charset | Character set | | collation | Ordering rule | | source | Create way,include 'manual', 'capture' and 'evolve' | From 569e57addc6bfc53f23b2e15f32da5a3f7c6b7ec Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Thu, 18 Jun 2020 11:58:47 +0800 Subject: [PATCH 11/14] Update sql-statements/sql-statement-show-bindings.md Co-authored-by: Ran --- sql-statements/sql-statement-show-bindings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-show-bindings.md b/sql-statements/sql-statement-show-bindings.md index b7928b3f45c4a..56c13455d30f3 100644 --- a/sql-statements/sql-statement-show-bindings.md +++ b/sql-statements/sql-statement-show-bindings.md @@ -45,7 +45,7 @@ This statement outputs the execution plan bindings at the GLOBAL or SESSION leve | create_time | Created time | | update_time | Updated time | | charset | Character set | -| collation | Ordering rule | +| collation | Sorting rule | | source | Create way,include 'manual', 'capture' and 'evolve' | ## See also From bf686c4d1e2b34032b961af8c8d347f3b4a4fbde Mon Sep 17 00:00:00 2001 From: Ran Date: Fri, 19 Jun 2020 11:00:55 +0800 Subject: [PATCH 12/14] Apply suggestions from code review --- sql-statements/sql-statement-create-binding.md | 2 +- sql-statements/sql-statement-show-bindings.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-statements/sql-statement-create-binding.md b/sql-statements/sql-statement-create-binding.md index 106f39c071c93..4c88157a880c1 100644 --- a/sql-statements/sql-statement-create-binding.md +++ b/sql-statements/sql-statement-create-binding.md @@ -24,7 +24,7 @@ The `CREATE BINDING` statement is used to create a new SQL bind on TiDB. **** -## Statement Description +## Syntax description {{< copyable "sql" >}} diff --git a/sql-statements/sql-statement-show-bindings.md b/sql-statements/sql-statement-show-bindings.md index 56c13455d30f3..062dc06c135cd 100644 --- a/sql-statements/sql-statement-show-bindings.md +++ b/sql-statements/sql-statement-show-bindings.md @@ -8,7 +8,7 @@ category: reference The `SHOW BINDINGS` statement is used to display information about all created SQL bindings. -## Statement Diagram +## Synopsis **ShowStmt:** From 4c957bc309cd39ca8a1b0ba12938affa3717eb2e Mon Sep 17 00:00:00 2001 From: Ran Date: Fri, 19 Jun 2020 11:43:24 +0800 Subject: [PATCH 13/14] Apply suggestions from code review --- sql-statements/sql-statement-create-binding.md | 1 - sql-statements/sql-statement-show-bindings.md | 1 - 2 files changed, 2 deletions(-) diff --git a/sql-statements/sql-statement-create-binding.md b/sql-statements/sql-statement-create-binding.md index 4c88157a880c1..1cd27c04fce2b 100644 --- a/sql-statements/sql-statement-create-binding.md +++ b/sql-statements/sql-statement-create-binding.md @@ -36,7 +36,6 @@ This statement binds SQL execution plans at the GLOBAL or SESSION scope. The def The bound SQL statement is parameterized and stored in the system table. When a SQL query is processed, as long as the parameterized SQL statement and a bound one in the system table are consistent and the system variable `tidb_use_plan_baselines` is set to `on` (`on` by default), the corresponding optimizer hint is available. If multiple execution plans are available, the optimizer chooses to bind the plan with the least cost. -When a SQL statement has bound execution plans in both GLOBAL and SESSION scopes, because the optimizer ignores the bound execution plan in the GLOBAL scope when it encounters the SESSION binding, the bound execution plan of this statement in the SESSION scope shields the execution plan in the GLOBAL scope. ## See also diff --git a/sql-statements/sql-statement-show-bindings.md b/sql-statements/sql-statement-show-bindings.md index 062dc06c135cd..c9d9681eb21cd 100644 --- a/sql-statements/sql-statement-show-bindings.md +++ b/sql-statements/sql-statement-show-bindings.md @@ -46,7 +46,6 @@ This statement outputs the execution plan bindings at the GLOBAL or SESSION leve | update_time | Updated time | | charset | Character set | | collation | Sorting rule | -| source | Create way,include 'manual', 'capture' and 'evolve' | ## See also From 0d4ef6b0d8fc7023f30969e1e276589bafb1f50d Mon Sep 17 00:00:00 2001 From: Ran Date: Fri, 19 Jun 2020 12:16:21 +0800 Subject: [PATCH 14/14] remove extra line --- sql-statements/sql-statement-create-binding.md | 1 - 1 file changed, 1 deletion(-) diff --git a/sql-statements/sql-statement-create-binding.md b/sql-statements/sql-statement-create-binding.md index 1cd27c04fce2b..7e7f095eaac49 100644 --- a/sql-statements/sql-statement-create-binding.md +++ b/sql-statements/sql-statement-create-binding.md @@ -36,7 +36,6 @@ This statement binds SQL execution plans at the GLOBAL or SESSION scope. The def The bound SQL statement is parameterized and stored in the system table. When a SQL query is processed, as long as the parameterized SQL statement and a bound one in the system table are consistent and the system variable `tidb_use_plan_baselines` is set to `on` (`on` by default), the corresponding optimizer hint is available. If multiple execution plans are available, the optimizer chooses to bind the plan with the least cost. - ## See also * [DROP BINDING](/sql-statements/sql-statement-drop-binding.md)