From 91ee903f34ec37c9c92772b43f6ccf7a2d9ce578 Mon Sep 17 00:00:00 2001 From: houfaxin Date: Wed, 14 Jan 2026 18:45:54 +0800 Subject: [PATCH 1/6] Update tidb-cloud-poc.md --- functions-and-operators/tidb-functions.md | 50 ++++++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index 14db38e2eac4b..360cff150cadc 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -583,7 +583,39 @@ SELECT VITESS_HASH(123); ## TIDB_ENCODE_INDEX_KEY -Encodes an index key. +Encodes an index key and returns the result as a hexadecimal string. The function syntax is as follows: + +`TIDB_ENCODE_INDEX_KEY(, , , ..., ...)` + +* ``: the name of the database that contains the target index. +* ``: the name of the table that contains the target index. For a partitioned table, you can specify the partition name in ``, for example, `'t(p0)'`. +* ``: the name of the target index. +* `...`: the values of the index columns, specified in the order defined by the index. For a composite index, provide the values for each column in the defined order. +* `...`: the handle value for the corresponding row. The rules are as follows: + + * If the table uses the hidden column `_tidb_rowid` as the handle (no primary key, or the primary key is `NONCLUSTERED`), use `_tidb_rowid`. + * If the table has a `CLUSTERED` primary key that is a single integer column, the handle is the value of that primary key column. + * If the table has a `CLUSTERED` primary key that is composite or non-integer (a common handle), the handle consists of all primary key columns and must be specified in primary key order. + +The following are examples of how to specify composite indexes and composite primary keys: + +```sql +-- Composite secondary index `idx(c1, c2)`, with no primary key or a `NONCLUSTERED` primary key. The handle is `_tidb_rowid`. +SELECT TIDB_ENCODE_INDEX_KEY( + '', '', '', + , , <_tidb_rowid> +); +-- Composite secondary index `idx(c1, c2)`, with a single-column integer CLUSTERED primary key id. +SELECT TIDB_ENCODE_INDEX_KEY( + '', '', '', + , , +); +-- Composite secondary index `idx(c1, c2)`, with a composite CLUSTERED primary key `PRIMARY KEY (p1, p2)` (common handle). +SELECT TIDB_ENCODE_INDEX_KEY( + '', '', '', + , , , +); +``` ```sql CREATE TABLE t(id int PRIMARY KEY, a int, KEY `idx` (a)); @@ -594,7 +626,7 @@ Query OK, 0 rows affected (0.00 sec) ``` ```sql -INSERT INTO t VALUES(1,1); +INSERT INTO t VALUES(1,2); ``` ``` @@ -602,12 +634,12 @@ Query OK, 1 row affected (0.00 sec) ``` ```sql -SELECT TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 1, 1); +SELECT TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 2, 1); ``` ``` +----------------------------------------------------------------------------+ -| TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 1, 1) | +| TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 2, 1) | +----------------------------------------------------------------------------+ | 74800000000000007f5f698000000000000001038000000000000001038000000000000001 | +----------------------------------------------------------------------------+ @@ -616,7 +648,13 @@ SELECT TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 1, 1); ## TIDB_ENCODE_RECORD_KEY -Encodes a record key. +Encodes a record key and returns the result as a hexadecimal string. The function syntax is as follows: + +`TIDB_ENCODE_RECORD_KEY(, , ...)` + +``: the name of the database that contains the target table. +``: the name of the table that contains the target table. For a partitioned table, you can specify the partition name in `table_name`, for example, `'t(p0)'`. +`...`: the handle (row key) value for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether it is CLUSTERED, whether it uses a common handle, or whether it uses the hidden column `_tidb_rowid`. For more information, see the `handle_columns...` section in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). ```sql CREATE TABLE t(id int PRIMARY KEY, a int, KEY `idx` (a)); @@ -627,7 +665,7 @@ Query OK, 0 rows affected (0.00 sec) ``` ```sql -INSERT INTO t VALUES(1,1); +INSERT INTO t VALUES(1,2); ``` ``` From 03a9482cf5c3854e451737d23be7c8918fd062a5 Mon Sep 17 00:00:00 2001 From: houfaxin Date: Wed, 14 Jan 2026 18:52:36 +0800 Subject: [PATCH 2/6] Update tidb-functions.md --- functions-and-operators/tidb-functions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index 360cff150cadc..19f254f2998d6 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -652,9 +652,9 @@ Encodes a record key and returns the result as a hexadecimal string. The functio `TIDB_ENCODE_RECORD_KEY(, , ...)` -``: the name of the database that contains the target table. -``: the name of the table that contains the target table. For a partitioned table, you can specify the partition name in `table_name`, for example, `'t(p0)'`. -`...`: the handle (row key) value for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether it is CLUSTERED, whether it uses a common handle, or whether it uses the hidden column `_tidb_rowid`. For more information, see the `handle_columns...` section in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). +* ``: the name of the database that contains the target table. +* ``: the name of the table that contains the target table. For a partitioned table, you can specify the partition name in `table_name`, for example, `'t(p0)'`. +* `...`: the handle (row key) value for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether it is CLUSTERED, whether it uses a common handle, or whether it uses the hidden column `_tidb_rowid`. For more information, see the `handle_columns...` section in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). ```sql CREATE TABLE t(id int PRIMARY KEY, a int, KEY `idx` (a)); From b6112a036591550811ae5a42d1684aeef855af68 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Thu, 15 Jan 2026 08:52:13 +0800 Subject: [PATCH 3/6] 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 19f254f2998d6..bba7903923ca8 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -641,7 +641,7 @@ SELECT TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 2, 1); +----------------------------------------------------------------------------+ | TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 2, 1) | +----------------------------------------------------------------------------+ -| 74800000000000007f5f698000000000000001038000000000000001038000000000000001 | +| 7480000000000000b45f698000000000000001038000000000000002038000000000000001 | +----------------------------------------------------------------------------+ 1 row in set (0.00 sec) ``` From 4c7c968127459a66b815a956e3574195344ee120 Mon Sep 17 00:00:00 2001 From: houfaxin Date: Mon, 19 Jan 2026 10:35:35 +0800 Subject: [PATCH 4/6] Update tidb-functions.md --- functions-and-operators/tidb-functions.md | 32 +++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index bba7903923ca8..a825ad5b8a2a8 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -583,34 +583,36 @@ SELECT VITESS_HASH(123); ## TIDB_ENCODE_INDEX_KEY -Encodes an index key and returns the result as a hexadecimal string. The function syntax is as follows: +The `TIDB_ENCODE_INDEX_KEY()` function encodes the specified index key into a hexadecimal string. The function syntax is as follows: `TIDB_ENCODE_INDEX_KEY(, , , ..., ...)` +Parameter descriptions: + * ``: the name of the database that contains the target index. -* ``: the name of the table that contains the target index. For a partitioned table, you can specify the partition name in ``, for example, `'t(p0)'`. +* ``: the name of the table that contains the target index. For a partitioned table, you can specify the partition name, for example, `'t(p0)'`. * ``: the name of the target index. -* `...`: the values of the index columns, specified in the order defined by the index. For a composite index, provide the values for each column in the defined order. -* `...`: the handle value for the corresponding row. The rules are as follows: +* `...`: the values of the index columns. You must specify the values in the order defined by the index. For a composite index, you must provide values for all index columns. +* `...`: the handle value corresponding to the row. The rules for determining the handle value vary depending on the primary key type of the table, as follows: - * If the table uses the hidden column `_tidb_rowid` as the handle (no primary key, or the primary key is `NONCLUSTERED`), use `_tidb_rowid`. - * If the table has a `CLUSTERED` primary key that is a single integer column, the handle is the value of that primary key column. - * If the table has a `CLUSTERED` primary key that is composite or non-integer (a common handle), the handle consists of all primary key columns and must be specified in primary key order. + * If the table has no primary key, or the primary key is `NONCLUSTERED`, the handle value is the value of the hidden column `_tidb_rowid`. + * If the table has a `CLUSTERED` primary key that is a single integer column, the handle value is the value of the primary key column. + * If the table has a `CLUSTERED` primary key that is composite or non-integer (a common handle), the handle value consists of the values of all primary key columns in order. -The following are examples of how to specify composite indexes and composite primary keys: +The following examples show how to call this function for the composite secondary index `idx(c1, c2)` under different primary key types. ```sql --- Composite secondary index `idx(c1, c2)`, with no primary key or a `NONCLUSTERED` primary key. The handle is `_tidb_rowid`. +-- For tables without a primary key or with a NONCLUSTERED primary key: Use the _tidb_rowid column. SELECT TIDB_ENCODE_INDEX_KEY( '', '', '', , , <_tidb_rowid> ); --- Composite secondary index `idx(c1, c2)`, with a single-column integer CLUSTERED primary key id. +-- For tables with a CLUSTERED integer primary key (column id): Use the id column. SELECT TIDB_ENCODE_INDEX_KEY( '', '', '', , , ); --- Composite secondary index `idx(c1, c2)`, with a composite CLUSTERED primary key `PRIMARY KEY (p1, p2)` (common handle). +-- For tables with CLUSTERED composite primary keys (columns p1 and p2): Provide the values of p1 and p2 in their defined order. SELECT TIDB_ENCODE_INDEX_KEY( '', '', '', , , , @@ -648,13 +650,15 @@ SELECT TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 2, 1); ## TIDB_ENCODE_RECORD_KEY -Encodes a record key and returns the result as a hexadecimal string. The function syntax is as follows: +The `TIDB_ENCODE_RECORD_KEY()` function encodes a specified row record key into a hexadecimal string. The function syntax is as follows: `TIDB_ENCODE_RECORD_KEY(, , ...)` +Parameter descriptions: + * ``: the name of the database that contains the target table. -* ``: the name of the table that contains the target table. For a partitioned table, you can specify the partition name in `table_name`, for example, `'t(p0)'`. -* `...`: the handle (row key) value for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether it is CLUSTERED, whether it uses a common handle, or whether it uses the hidden column `_tidb_rowid`. For more information, see the `handle_columns...` section in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). +* ``: the name of the table that contains the target table. For a partitioned table, you can specify the partition name in , for example, `'t(p0)'`. +* `...`: the handle (row key) value for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether it is CLUSTERED, whether it uses a common handle, or whether it uses the hidden column `_tidb_rowid`. For more information, see the section in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). ```sql CREATE TABLE t(id int PRIMARY KEY, a int, KEY `idx` (a)); From 5b5c679214d4c13ab43be1390a5c1a82ec52c7f9 Mon Sep 17 00:00:00 2001 From: houfaxin Date: Mon, 19 Jan 2026 10:37:39 +0800 Subject: [PATCH 5/6] Update tidb-functions.md --- functions-and-operators/tidb-functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index a825ad5b8a2a8..e193613c69d9b 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -657,8 +657,8 @@ The `TIDB_ENCODE_RECORD_KEY()` function encodes a specified row record key into Parameter descriptions: * ``: the name of the database that contains the target table. -* ``: the name of the table that contains the target table. For a partitioned table, you can specify the partition name in , for example, `'t(p0)'`. -* `...`: the handle (row key) value for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether it is CLUSTERED, whether it uses a common handle, or whether it uses the hidden column `_tidb_rowid`. For more information, see the section in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). +* ``: the name of the table that contains the target table. For a partitioned table, you can specify the partition name in ``, for example, `'t(p0)'`. +* `...`: the handle (row key) value for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether it is `CLUSTERED`, whether it uses a common handle, or whether it uses the hidden column `_tidb_rowid`. For more information, see the `` section in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). ```sql CREATE TABLE t(id int PRIMARY KEY, a int, KEY `idx` (a)); From d91babb2b517fbd61c954683561b396dabca6be5 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Mon, 19 Jan 2026 12:03:17 +0800 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Aolin --- functions-and-operators/tidb-functions.md | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/functions-and-operators/tidb-functions.md b/functions-and-operators/tidb-functions.md index e193613c69d9b..ceeb249db4009 100644 --- a/functions-and-operators/tidb-functions.md +++ b/functions-and-operators/tidb-functions.md @@ -583,36 +583,40 @@ SELECT VITESS_HASH(123); ## TIDB_ENCODE_INDEX_KEY -The `TIDB_ENCODE_INDEX_KEY()` function encodes the specified index key into a hexadecimal string. The function syntax is as follows: +The `TIDB_ENCODE_INDEX_KEY()` function encodes a specified index key into a hexadecimal string. The syntax is as follows: -`TIDB_ENCODE_INDEX_KEY(, , , ..., ...)` +```sql +TIDB_ENCODE_INDEX_KEY(, , , ..., ...) +``` Parameter descriptions: * ``: the name of the database that contains the target index. * ``: the name of the table that contains the target index. For a partitioned table, you can specify the partition name, for example, `'t(p0)'`. * ``: the name of the target index. -* `...`: the values of the index columns. You must specify the values in the order defined by the index. For a composite index, you must provide values for all index columns. -* `...`: the handle value corresponding to the row. The rules for determining the handle value vary depending on the primary key type of the table, as follows: +* `...`: the values of the index columns. You must specify the values in the same order as defined in the index. For a composite index, you must specify values for all index columns. +* `...`: the handle values for the row. The required handle values depend on the primary key type of the table: * If the table has no primary key, or the primary key is `NONCLUSTERED`, the handle value is the value of the hidden column `_tidb_rowid`. - * If the table has a `CLUSTERED` primary key that is a single integer column, the handle value is the value of the primary key column. - * If the table has a `CLUSTERED` primary key that is composite or non-integer (a common handle), the handle value consists of the values of all primary key columns in order. + * If the primary key is `CLUSTERED` and is a single-column integer, the handle value is the value of the primary key column. + * If the primary key is `CLUSTERED` and is a composite primary key or a non-integer type (common handle), the handle value consists of the values of all primary key columns in order. The following examples show how to call this function for the composite secondary index `idx(c1, c2)` under different primary key types. ```sql --- For tables without a primary key or with a NONCLUSTERED primary key: Use the _tidb_rowid column. +-- For tables without a primary key or with a NONCLUSTERED primary key, use the _tidb_rowid column. SELECT TIDB_ENCODE_INDEX_KEY( '', '', '', , , <_tidb_rowid> ); --- For tables with a CLUSTERED integer primary key (column id): Use the id column. + +-- For tables with a CLUSTERED integer primary key (the primary key column is id), use the id column. SELECT TIDB_ENCODE_INDEX_KEY( '', '', '', , , ); --- For tables with CLUSTERED composite primary keys (columns p1 and p2): Provide the values of p1 and p2 in their defined order. + +-- For tables with a CLUSTERED composite primary key (the primary key columns are p1, p2), provide the values of p1 and p2 in their defined order. SELECT TIDB_ENCODE_INDEX_KEY( '', '', '', , , , @@ -652,13 +656,15 @@ SELECT TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 2, 1); The `TIDB_ENCODE_RECORD_KEY()` function encodes a specified row record key into a hexadecimal string. The function syntax is as follows: -`TIDB_ENCODE_RECORD_KEY(, , ...)` +```sql +TIDB_ENCODE_RECORD_KEY(, , ...) +``` Parameter descriptions: * ``: the name of the database that contains the target table. -* ``: the name of the table that contains the target table. For a partitioned table, you can specify the partition name in ``, for example, `'t(p0)'`. -* `...`: the handle (row key) value for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether it is `CLUSTERED`, whether it uses a common handle, or whether it uses the hidden column `_tidb_rowid`. For more information, see the `` section in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). +* ``: the name of the target table. For a partitioned table, you can specify the partition name in ``, for example, `'t(p0)'`. +* `...`: the handle (row key) values for the corresponding row. The exact composition of the handle depends on the primary key type of the table, such as whether the primary key is `CLUSTERED`, a common handle, or uses the hidden column `_tidb_rowid`. For more information, see the description of `...` in [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key). ```sql CREATE TABLE t(id int PRIMARY KEY, a int, KEY `idx` (a));