From 45de6e71210e34eba680e232140caac025a2b37a Mon Sep 17 00:00:00 2001 From: Aolin Date: Mon, 30 May 2022 16:46:06 +0800 Subject: [PATCH 01/12] add tidb_shard --- functions-and-operators/tidb-functions.md | 67 +++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index f62051603a640..d67d4a8990a82 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -17,6 +17,7 @@ The following functions are TiDB extensions, and are not present in MySQL: | [`TIDB_VERSION()`](#tidb_version) | The `TIDB_VERSION` function returns the TiDB version with additional build information. | | [`TIDB_DECODE_SQL_DIGESTS(digests, stmtTruncateLength)`](#tidb_decode_sql_digests) | The `TIDB_DECODE_SQL_DIGESTS()` function is used to query the normalized SQL statements (a form without formats and arguments) corresponding to the set of SQL digests in the cluster. | | `VITESS_HASH(str)` | The `VITESS_HASH` function returns the hash of a string that is compatible with Vitess' `HASH` function. This is intended to help the data migration from Vitess. | +| `TIDB_SHARD()` | The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the index hotspot. A SHARD INDEX is an expression index with a `TIDB_SHARD`function as the prefix.| ## Examples @@ -230,3 +231,69 @@ See also: - [`Statement Summary Tables`](/statement-summary-tables.md) - [`INFORMATION_SCHEMA.TIDB_TRX`](/information-schema/information-schema-tidb-trx.md) + +### TIDB_SHARD + +The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the index hotspot. A SHARD INDEX is an expression index with a `TIDB_SHARD`function as the prefix. + +#### SHARD INDEX + +- Creation method: + + When there is a hotspot on the index field `a` on the unique secondary index `uk((tidb_shard(a)), a))` caused by monotonically increasing or decreasing data, the prefix of index `tidb_shard(a)` can scatter the hotspot to improve the scalability of the cluster. + +- Scenario: + + - When there is a write hotspot caused by increasing or decreasing key values on the unique secondary key and the index contains integer type fields. + - In the business, the SQL statement executes an equivalent query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE`, etc. The equivalent query includes `a = 1` or `a IN (1, 2, ......)` these two ways. + +- Limitations: + + - SHARD INDEX cannot be used for non-equivalent or `IN` queries. + - SHARD INDEX cannot be used for queries with a mix of `AND` and `OR` and an outer `AND` operator. + - SHARD INDEX cannot be used for `GROUP BY`. + - SHARD INDEX cannot be used for `ORDER BY`. + - SHARD INDEX cannot be used for the `ON` clause. + - SHARD INDEX cannot be used for the `WHERE` subquery. + - SHARD INDEX can only scatter unique indexes of integer fields. + - SHARD INDEX might fail in composite indexes. + - SHARD INDEX cannot go through the FastPlan process, which affects optimizer performance. + - SHARD INDEX cannot be used for preparing execution plan cache. + +#### Synopsis + +```ebnf+diagram +TIDBShardExpr ::= + "TIDB_SHARD" "(" expr ")" +``` + +#### Example + +- Use the `TIDB_SHARD` function to calculate the SHARD value. + + The following command shows how to use the `TIDB_SHARD` function to calculate the SHARD value of `12373743746`: + + {{< copyable "sql" >}} + + ```sql + select TIDB_SHARD(12373743746); + ``` + +- The SHARD value is: + + ```sql + +-------------------------+ + | TIDB_SHARD(12373743746) | + +-------------------------+ + | 184 | + +-------------------------+ + 1 row in set (0.00 sec) + ``` + +- Create a SHARD INDEX with the `TIDB_SHARD` function: + + {{< copyable "sql" >}} + + ```sql + create table test(id int primary key clustered, a int, b int, unique key uk((tidb_shard(a)), a)); + ``` From c82d1ac578faa9a4070d2c862d4c9bdc5ad76add Mon Sep 17 00:00:00 2001 From: Aolin Date: Tue, 31 May 2022 23:46:08 +0800 Subject: [PATCH 02/12] update tidb_shard --- functions-and-operators/tidb-functions.md | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index d67d4a8990a82..c413ed4a709fc 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -238,27 +238,27 @@ The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the ind #### SHARD INDEX -- Creation method: +- Creation: - When there is a hotspot on the index field `a` on the unique secondary index `uk((tidb_shard(a)), a))` caused by monotonically increasing or decreasing data, the prefix of index `tidb_shard(a)` can scatter the hotspot to improve the scalability of the cluster. + When there is a hotspot caused by monotonically increasing or decreasing data on the index field `a` in the unique secondary index `uk((tidb_shard(a)), a))`, the index's prefix `tidb_shard(a)` can scatter the hotspot to improve the cluster's scalability. - Scenario: - - When there is a write hotspot caused by increasing or decreasing key values on the unique secondary key and the index contains integer type fields. - - In the business, the SQL statement executes an equivalent query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE`, etc. The equivalent query includes `a = 1` or `a IN (1, 2, ......)` these two ways. + - When there is a write hotspot caused by increasing or decreasing keys on the unique secondary index, and the index contains integer type fields. + - The SQL statement executes an equality query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE`, etc. The equality query includes `a = 1` or `a IN (1, 2, ......)` these two ways. - Limitations: - - SHARD INDEX cannot be used for non-equivalent or `IN` queries. - - SHARD INDEX cannot be used for queries with a mix of `AND` and `OR` and an outer `AND` operator. - - SHARD INDEX cannot be used for `GROUP BY`. - - SHARD INDEX cannot be used for `ORDER BY`. - - SHARD INDEX cannot be used for the `ON` clause. - - SHARD INDEX cannot be used for the `WHERE` subquery. + - SHARD INDEX cannot be used with inequality or `IN` queries. + - SHARD INDEX cannot be used with an outmost `AND` operator mixed with `OR`. + - SHARD INDEX cannot be used with `GROUP BY` clause. + - SHARD INDEX cannot be used with `ORDER BY` clause. + - SHARD INDEX cannot be used with the `ON` clause. + - SHARD INDEX cannot be used with the `WHERE` subquery. - SHARD INDEX can only scatter unique indexes of integer fields. - - SHARD INDEX might fail in composite indexes. - - SHARD INDEX cannot go through the FastPlan process, which affects optimizer performance. - - SHARD INDEX cannot be used for preparing execution plan cache. + - SHARD INDEX might be ineffective in composite indexes. + - SHARD INDEX cannot go through FastPlan process, which affects optimizer performance. + - SHARD INDEX cannot be used with preparing execution plan cache. #### Synopsis @@ -276,7 +276,7 @@ TIDBShardExpr ::= {{< copyable "sql" >}} ```sql - select TIDB_SHARD(12373743746); + SELECT TIDB_SHARD(12373743746); ``` - The SHARD value is: @@ -295,5 +295,5 @@ TIDBShardExpr ::= {{< copyable "sql" >}} ```sql - create table test(id int primary key clustered, a int, b int, unique key uk((tidb_shard(a)), a)); + CREATE TABLE test(id INT PRIMARY KEY CLUSTERED, a INT, b INT, UNIQUE KEY uk((tidb_shard(a)), a)); ``` From 24a4364e9641fadf1fd69431268bdf0f1e4713a9 Mon Sep 17 00:00:00 2001 From: Aolin Date: Wed, 1 Jun 2022 11:24:12 +0800 Subject: [PATCH 03/12] Apply suggestions from code review --- functions-and-operators/tidb-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index c413ed4a709fc..3100c1ad40bd8 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -249,7 +249,7 @@ The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the ind - Limitations: - - SHARD INDEX cannot be used with inequality or `IN` queries. + - SHARD INDEX cannot be used with inequality queries. - SHARD INDEX cannot be used with an outmost `AND` operator mixed with `OR`. - SHARD INDEX cannot be used with `GROUP BY` clause. - SHARD INDEX cannot be used with `ORDER BY` clause. From f6aefd5f35a82a3dc9dd444ccac7ce4754d4aecc Mon Sep 17 00:00:00 2001 From: Aolin Date: Wed, 1 Jun 2022 13:38:56 +0800 Subject: [PATCH 04/12] Apply suggestions from code review --- functions-and-operators/tidb-functions.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index 3100c1ad40bd8..ff95291e9a7f3 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -244,21 +244,21 @@ The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the ind - Scenario: - - When there is a write hotspot caused by increasing or decreasing keys on the unique secondary index, and the index contains integer type fields. + - When there is a write hotspot caused by monotonically increasing or decreasing keys on the unique secondary index, and the index contains integer type fields. - The SQL statement executes an equality query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE`, etc. The equality query includes `a = 1` or `a IN (1, 2, ......)` these two ways. - Limitations: - - SHARD INDEX cannot be used with inequality queries. - - SHARD INDEX cannot be used with an outmost `AND` operator mixed with `OR`. - - SHARD INDEX cannot be used with `GROUP BY` clause. - - SHARD INDEX cannot be used with `ORDER BY` clause. - - SHARD INDEX cannot be used with the `ON` clause. - - SHARD INDEX cannot be used with the `WHERE` subquery. + - SHARD INDEX cannot be used in inequality queries. + - SHARD INDEX cannot be used in an outmost `AND` operator mixed with `OR`. + - SHARD INDEX cannot be used in `GROUP BY` clause. + - SHARD INDEX cannot be used in `ORDER BY` clause. + - SHARD INDEX cannot be used in the `ON` clause. + - SHARD INDEX cannot be used in the `WHERE` subquery. - SHARD INDEX can only scatter unique indexes of integer fields. - SHARD INDEX might be ineffective in composite indexes. - SHARD INDEX cannot go through FastPlan process, which affects optimizer performance. - - SHARD INDEX cannot be used with preparing execution plan cache. + - SHARD INDEX cannot be used in preparing execution plan cache. #### Synopsis From 15faa46d805d03a5138900f71761355c7af55bcf Mon Sep 17 00:00:00 2001 From: Aolin Date: Wed, 1 Jun 2022 16:28:38 +0800 Subject: [PATCH 05/12] Apply suggestions from code review --- functions-and-operators/tidb-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index ff95291e9a7f3..e43edfcf65f29 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -245,7 +245,7 @@ The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the ind - Scenario: - When there is a write hotspot caused by monotonically increasing or decreasing keys on the unique secondary index, and the index contains integer type fields. - - The SQL statement executes an equality query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE`, etc. The equality query includes `a = 1` or `a IN (1, 2, ......)` these two ways. + - The SQL statement executes an equality query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE` and so on. The equality query includes `a = 1` or `a IN (1, 2, ......)` these two ways. - Limitations: From b84d8eb2e9f6684e269d41f7af379d304d107261 Mon Sep 17 00:00:00 2001 From: Aolin Date: Mon, 6 Jun 2022 21:37:09 +0800 Subject: [PATCH 06/12] Apply suggestions from code review Co-authored-by: TomShawn <41534398+TomShawn@users.noreply.github.com> --- functions-and-operators/tidb-functions.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index e43edfcf65f29..5b0aefb416e2c 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -234,7 +234,7 @@ See also: ### TIDB_SHARD -The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the index hotspot. A SHARD INDEX is an expression index with a `TIDB_SHARD`function as the prefix. +The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the index hotspot. A SHARD INDEX is an expression index prefixed with a `TIDB_SHARD`function. #### SHARD INDEX @@ -242,23 +242,23 @@ The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the ind When there is a hotspot caused by monotonically increasing or decreasing data on the index field `a` in the unique secondary index `uk((tidb_shard(a)), a))`, the index's prefix `tidb_shard(a)` can scatter the hotspot to improve the cluster's scalability. -- Scenario: +- Scenarios: - When there is a write hotspot caused by monotonically increasing or decreasing keys on the unique secondary index, and the index contains integer type fields. - - The SQL statement executes an equality query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE` and so on. The equality query includes `a = 1` or `a IN (1, 2, ......)` these two ways. + - The SQL statement executes an equality query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE` and so on. The equality query includes two ways: `a = 1` or `a IN (1, 2, ......)`. - Limitations: - SHARD INDEX cannot be used in inequality queries. - - SHARD INDEX cannot be used in an outmost `AND` operator mixed with `OR`. - - SHARD INDEX cannot be used in `GROUP BY` clause. - - SHARD INDEX cannot be used in `ORDER BY` clause. + - SHARD INDEX cannot be used in queries that contain `OR` mixed with an outmost `AND` operator. + - SHARD INDEX cannot be used in the `GROUP BY` clause. + - SHARD INDEX cannot be used in the `ORDER BY` clause. - SHARD INDEX cannot be used in the `ON` clause. - SHARD INDEX cannot be used in the `WHERE` subquery. - SHARD INDEX can only scatter unique indexes of integer fields. - SHARD INDEX might be ineffective in composite indexes. - SHARD INDEX cannot go through FastPlan process, which affects optimizer performance. - - SHARD INDEX cannot be used in preparing execution plan cache. + - SHARD INDEX cannot be used in preparing the execution plan cache. #### Synopsis @@ -271,7 +271,7 @@ TIDBShardExpr ::= - Use the `TIDB_SHARD` function to calculate the SHARD value. - The following command shows how to use the `TIDB_SHARD` function to calculate the SHARD value of `12373743746`: + The following statement shows how to use the `TIDB_SHARD` function to calculate the SHARD value of `12373743746`: {{< copyable "sql" >}} @@ -290,7 +290,7 @@ TIDBShardExpr ::= 1 row in set (0.00 sec) ``` -- Create a SHARD INDEX with the `TIDB_SHARD` function: +- Create a SHARD INDEX using the `TIDB_SHARD` function: {{< copyable "sql" >}} From 690fe9c61c834e6cf51d7dbf6917eb8f5ce073ac Mon Sep 17 00:00:00 2001 From: Aolin Zhang Date: Mon, 6 Jun 2022 21:43:02 +0800 Subject: [PATCH 07/12] Apply suggestions from code review --- functions-and-operators/tidb-functions.md | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index 5b0aefb416e2c..b9d3e7cafb08c 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -17,7 +17,7 @@ The following functions are TiDB extensions, and are not present in MySQL: | [`TIDB_VERSION()`](#tidb_version) | The `TIDB_VERSION` function returns the TiDB version with additional build information. | | [`TIDB_DECODE_SQL_DIGESTS(digests, stmtTruncateLength)`](#tidb_decode_sql_digests) | The `TIDB_DECODE_SQL_DIGESTS()` function is used to query the normalized SQL statements (a form without formats and arguments) corresponding to the set of SQL digests in the cluster. | | `VITESS_HASH(str)` | The `VITESS_HASH` function returns the hash of a string that is compatible with Vitess' `HASH` function. This is intended to help the data migration from Vitess. | -| `TIDB_SHARD()` | The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the index hotspot. A SHARD INDEX is an expression index with a `TIDB_SHARD`function as the prefix.| +| `TIDB_SHARD()` | The `TIDB_SHARD` function can be used to create a shard index to scatter the index hotspot. A shard index is an expression index with a `TIDB_SHARD`function as the prefix.| ## Examples @@ -234,9 +234,9 @@ See also: ### TIDB_SHARD -The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the index hotspot. A SHARD INDEX is an expression index prefixed with a `TIDB_SHARD`function. +The `TIDB_SHARD` function can be used to create a shard index to scatter the index hotspot. A shard index is an expression index prefixed with a `TIDB_SHARD` function. -#### SHARD INDEX +#### Shard index - Creation: @@ -249,16 +249,16 @@ The `TIDB_SHARD` function can be used to create a SHARD INDEX to scatter the ind - Limitations: - - SHARD INDEX cannot be used in inequality queries. - - SHARD INDEX cannot be used in queries that contain `OR` mixed with an outmost `AND` operator. - - SHARD INDEX cannot be used in the `GROUP BY` clause. - - SHARD INDEX cannot be used in the `ORDER BY` clause. - - SHARD INDEX cannot be used in the `ON` clause. - - SHARD INDEX cannot be used in the `WHERE` subquery. - - SHARD INDEX can only scatter unique indexes of integer fields. - - SHARD INDEX might be ineffective in composite indexes. - - SHARD INDEX cannot go through FastPlan process, which affects optimizer performance. - - SHARD INDEX cannot be used in preparing the execution plan cache. + - Shard index cannot be used in inequality queries. + - Shard index cannot be used in queries that contain `OR` mixed with an outmost `AND` operator. + - Shard index cannot be used in the `GROUP BY` clause. + - Shard index cannot be used in the `ORDER BY` clause. + - Shard index cannot be used in the `ON` clause. + - Shard index cannot be used in the `WHERE` subquery. + - Shard index can only scatter unique indexes of integer fields. + - Shard index might not take effect in composite indexes. + - Shard index cannot go through FastPlan process, which affects optimizer performance. + - Shard index cannot be used in preparing the execution plan cache. #### Synopsis @@ -290,7 +290,7 @@ TIDBShardExpr ::= 1 row in set (0.00 sec) ``` -- Create a SHARD INDEX using the `TIDB_SHARD` function: +- Create a shard index using the `TIDB_SHARD` function: {{< copyable "sql" >}} From 74fc80a75b54706adb0fc19afc2df8883eb6fec4 Mon Sep 17 00:00:00 2001 From: Aolin Date: Tue, 7 Jun 2022 11:10:38 +0800 Subject: [PATCH 08/12] Apply suggestions from code review --- functions-and-operators/tidb-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index b9d3e7cafb08c..aa08c84d1da81 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -240,7 +240,7 @@ The `TIDB_SHARD` function can be used to create a shard index to scatter the ind - Creation: - When there is a hotspot caused by monotonically increasing or decreasing data on the index field `a` in the unique secondary index `uk((tidb_shard(a)), a))`, the index's prefix `tidb_shard(a)` can scatter the hotspot to improve the cluster's scalability. + You can use `uk((tidb_shard(a)), a))` to create a shard index for the index `a`. When there is a hotspot caused by monotonically increasing or decreasing data on the index field `a` in the unique secondary index `uk((tidb_shard(a)), a))`, the index's prefix `tidb_shard(a)` can scatter the hotspot to improve the cluster's scalability. - Scenarios: From 9ff14c5646edee5b3a893abb71338baaa175969b Mon Sep 17 00:00:00 2001 From: Aolin Date: Tue, 7 Jun 2022 11:28:47 +0800 Subject: [PATCH 09/12] Apply suggestions from code review --- functions-and-operators/tidb-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index aa08c84d1da81..7bf333fd5c538 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -240,7 +240,7 @@ The `TIDB_SHARD` function can be used to create a shard index to scatter the ind - Creation: - You can use `uk((tidb_shard(a)), a))` to create a shard index for the index `a`. When there is a hotspot caused by monotonically increasing or decreasing data on the index field `a` in the unique secondary index `uk((tidb_shard(a)), a))`, the index's prefix `tidb_shard(a)` can scatter the hotspot to improve the cluster's scalability. + You can use `uk((tidb_shard(a)), a))` to create a shard index for the field `a`. When there is a hotspot caused by monotonically increasing or decreasing data on the index field `a` in the unique secondary index `uk((tidb_shard(a)), a))`, the index's prefix `tidb_shard(a)` can scatter the hotspot to improve the cluster's scalability. - Scenarios: From 748ee9ead5583d1a0a44db0fe1f98bdd4fb7c8e5 Mon Sep 17 00:00:00 2001 From: Aolin Date: Tue, 7 Jun 2022 13:54:31 +0800 Subject: [PATCH 10/12] Apply suggestions from code review Co-authored-by: TomShawn <41534398+TomShawn@users.noreply.github.com> --- functions-and-operators/tidb-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index 7bf333fd5c538..e3c2d48b17de0 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -17,7 +17,7 @@ The following functions are TiDB extensions, and are not present in MySQL: | [`TIDB_VERSION()`](#tidb_version) | The `TIDB_VERSION` function returns the TiDB version with additional build information. | | [`TIDB_DECODE_SQL_DIGESTS(digests, stmtTruncateLength)`](#tidb_decode_sql_digests) | The `TIDB_DECODE_SQL_DIGESTS()` function is used to query the normalized SQL statements (a form without formats and arguments) corresponding to the set of SQL digests in the cluster. | | `VITESS_HASH(str)` | The `VITESS_HASH` function returns the hash of a string that is compatible with Vitess' `HASH` function. This is intended to help the data migration from Vitess. | -| `TIDB_SHARD()` | The `TIDB_SHARD` function can be used to create a shard index to scatter the index hotspot. A shard index is an expression index with a `TIDB_SHARD`function as the prefix.| +| `TIDB_SHARD()` | The `TIDB_SHARD` function can be used to create a shard index to scatter the index hotspot. A shard index is an expression index with a `TIDB_SHARD` function as the prefix.| ## Examples From 871f099ff90ab14374da7062d3e50d9ff116ad6c Mon Sep 17 00:00:00 2001 From: aolin Date: Tue, 7 Jun 2022 14:26:03 +0800 Subject: [PATCH 11/12] Apply suggestions from code review --- functions-and-operators/tidb-functions.md | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index e3c2d48b17de0..c9dfc12d64ae9 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -240,25 +240,25 @@ The `TIDB_SHARD` function can be used to create a shard index to scatter the ind - Creation: - You can use `uk((tidb_shard(a)), a))` to create a shard index for the field `a`. When there is a hotspot caused by monotonically increasing or decreasing data on the index field `a` in the unique secondary index `uk((tidb_shard(a)), a))`, the index's prefix `tidb_shard(a)` can scatter the hotspot to improve the cluster's scalability. + To create a shard index for the index field `a`, you can use `uk((tidb_shard(a)), a))`. When there is a hotspot caused by monotonically increasing or decreasing data on the index field `a` in the unique secondary index `uk((tidb_shard(a)), a))`, the index's prefix `tidb_shard(a)` can scatter the hotspot to improve the scalability of the cluster. - Scenarios: - - When there is a write hotspot caused by monotonically increasing or decreasing keys on the unique secondary index, and the index contains integer type fields. + - There is a write hotspot caused by monotonically increasing or decreasing keys on the unique secondary index, and the index contains integer type fields. - The SQL statement executes an equality query based on all fields of the secondary index, either as a separate `SELECT` or as an internal query generated by `UPDATE`, `DELETE` and so on. The equality query includes two ways: `a = 1` or `a IN (1, 2, ......)`. - Limitations: - - Shard index cannot be used in inequality queries. - - Shard index cannot be used in queries that contain `OR` mixed with an outmost `AND` operator. - - Shard index cannot be used in the `GROUP BY` clause. - - Shard index cannot be used in the `ORDER BY` clause. - - Shard index cannot be used in the `ON` clause. - - Shard index cannot be used in the `WHERE` subquery. - - Shard index can only scatter unique indexes of integer fields. - - Shard index might not take effect in composite indexes. - - Shard index cannot go through FastPlan process, which affects optimizer performance. - - Shard index cannot be used in preparing the execution plan cache. + - Cannot be used in inequality queries. + - Cannot be used in queries that contain `OR` mixed with an outmost `AND` operator. + - Cannot be used in the `GROUP BY` clause. + - Cannot be used in the `ORDER BY` clause. + - Cannot be used in the `ON` clause. + - Cannot be used in the `WHERE` subquery. + - Can only be used to scatter unique indexes of integer fields. + - Might not take effect in composite indexes. + - Cannot go through FastPlan process, which affects optimizer performance. + - Cannot be used to prepare the execution plan cache. #### Synopsis From 764b94b3466d709bdf26514ab077067281b813ef Mon Sep 17 00:00:00 2001 From: TomShawn <41534398+TomShawn@users.noreply.github.com> Date: Tue, 7 Jun 2022 15:17:39 +0800 Subject: [PATCH 12/12] Update functions-and-operators/tidb-functions.md --- functions-and-operators/tidb-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index c9dfc12d64ae9..7462c91925b50 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -255,7 +255,7 @@ The `TIDB_SHARD` function can be used to create a shard index to scatter the ind - Cannot be used in the `ORDER BY` clause. - Cannot be used in the `ON` clause. - Cannot be used in the `WHERE` subquery. - - Can only be used to scatter unique indexes of integer fields. + - Can be used to scatter unique indexes of only the integer fields. - Might not take effect in composite indexes. - Cannot go through FastPlan process, which affects optimizer performance. - Cannot be used to prepare the execution plan cache.