-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functions: Add TIDB_MVCC_INFO, TIDB_ENCODE_INDEX_KEY and TIDB_ENCODE_RECORD_KEY #19715
Open
dveeden
wants to merge
3
commits into
pingcap:master
Choose a base branch
from
dveeden:tidb_mvcc_info
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+121
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,8 +18,11 @@ The following functions are TiDB extensions, and are not present in MySQL: | |||||
| [`TIDB_DECODE_KEY()`](#tidb_decode_key) | Decodes a TiDB-encoded key entry into a JSON structure containing `_tidb_rowid` and `table_id`. These encoded keys can be found in some system tables and logging outputs. | | ||||||
| [`TIDB_DECODE_PLAN()`](#tidb_decode_plan) | Decodes a TiDB execution plan. | | ||||||
| [`TIDB_DECODE_SQL_DIGESTS()`](#tidb_decode_sql_digests) | Queries the normalized SQL statements (a form without formats and arguments) corresponding to a set of SQL digests in the cluster. | | ||||||
| [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key) | Encodes an index key. | | ||||||
| [`TIDB_ENCODE_RECORD_KEY()`](#tidb_encode_record_key) | Encodes a record key. | | ||||||
| [`TIDB_ENCODE_SQL_DIGEST()`](#tidb_encode_sql_digest) | Gets a digest for a query string. | | ||||||
| [`TIDB_IS_DDL_OWNER()`](#tidb_is_ddl_owner) | Checks whether or not the TiDB instance you are connected to is the DDL Owner. The DDL Owner is the TiDB instance that is tasked with executing DDL statements on behalf of all other nodes in the cluster. | | ||||||
| [`TIDB_MVCC_INFO()`](#tidb_mvcc_info) | Returns the MVCC (Multi-Version Concurrency Control) information about a key. | | ||||||
| [`TIDB_PARSE_TSO()`](#tidb_parse_tso) | Extracts the physical timestamp from a TiDB TSO timestamp. See also: [`tidb_current_ts`](/system-variables.md#tidb_current_ts). | | ||||||
| [`TIDB_PARSE_TSO_LOGICAL()`](#tidb_parse_tso_logical) | Extracts the logical timestamp from a TiDB TSO timestamp. | | ||||||
| [`TIDB_ROW_CHECKSUM()`](#tidb_row_checksum) | Queries the checksum value of a row. This function can only be used in `SELECT` statements within the FastPlan process. That is, you can query through statements like `SELECT TIDB_ROW_CHECKSUM() FROM t WHERE id = ?` or `SELECT TIDB_ROW_CHECKSUM() FROM t WHERE id IN (?, ?, ...)`. See also: [Data integrity validation for single-row data](/ticdc/ticdc-integrity-check.md). | | ||||||
|
@@ -40,9 +43,12 @@ The following functions are TiDB extensions, and are not present in MySQL: | |||||
| [`TIDB_DECODE_KEY()`](#tidb_decode_key) | Decodes a TiDB-encoded key entry into a JSON structure containing `_tidb_rowid` and `table_id`. These encoded keys can be found in some system tables and logging outputs. | | ||||||
| [`TIDB_DECODE_PLAN()`](#tidb_decode_plan) | Decodes a TiDB execution plan. | | ||||||
| [`TIDB_DECODE_SQL_DIGESTS()`](#tidb_decode_sql_digests) | Queries the normalized SQL statements (a form without formats and arguments) corresponding to a set of SQL digests in the cluster. | | ||||||
| [`TIDB_ENCODE_INDEX_KEY()`](#tidb_encode_index_key) | Encodes an index key. | | ||||||
| [`TIDB_ENCODE_RECORD_KEY()`](#tidb_encode_record_key) | Encodes a record key. | | ||||||
| [`TIDB_ENCODE_SQL_DIGEST()`](#tidb_encode_sql_digest) | Gets a digest for a query string. | | ||||||
| [`TIDB_IS_DDL_OWNER()`](#tidb_is_ddl_owner) | Checks whether or not the TiDB instance you are connected to is the DDL Owner. The DDL Owner is the TiDB instance that is tasked with executing DDL statements on behalf of all other nodes in the cluster. | | ||||||
| [`TIDB_PARSE_TSO()`](#tidb_parse_tso) | Extracts the physical timestamp from a TiDB TSO timestamp. See also: [`tidb_current_ts`](/system-variables.md#tidb_current_ts). | | ||||||
| [`TIDB_MVCC_INFO()`](#tidb_mvcc_info) | Returns MVCC info about a key. | | ||||||
| [`TIDB_PARSE_TSO_LOGICAL()`](#tidb_parse_tso_logical) | Extracts the logical timestamp from a TiDB TSO timestamp. | | ||||||
| [`TIDB_ROW_CHECKSUM()`](#tidb_row_checksum) | Queries the checksum value of a row. This function can only be used in `SELECT` statements within the FastPlan process. That is, you can query through statements like `SELECT TIDB_ROW_CHECKSUM() FROM t WHERE id = ?` or `SELECT TIDB_ROW_CHECKSUM() FROM t WHERE id IN (?, ?, ...)`. See also: [Data integrity validation for single-row data](https://docs.pingcap.com/tidb/stable/ticdc-integrity-check). | | ||||||
| [`TIDB_SHARD()`](#tidb_shard) | Creates a shard index to scatter the index hotspot. A shard index is an expression index with a `TIDB_SHARD` function as the prefix.| | ||||||
|
@@ -573,4 +579,118 @@ SELECT VITESS_HASH(123); | |||||
| 1155070131015363447 | | ||||||
+---------------------+ | ||||||
1 row in set (0.00 sec) | ||||||
``` | ||||||
``` | ||||||
|
||||||
## TIDB_ENCODE_INDEX_KEY | ||||||
|
||||||
Encodes an index key. | ||||||
|
||||||
```sql | ||||||
CREATE TABLE t(id int PRIMARY KEY, a int, KEY `idx` (a)); | ||||||
``` | ||||||
|
||||||
``` | ||||||
Query OK, 0 rows affected (0.00 sec) | ||||||
``` | ||||||
|
||||||
```sql | ||||||
INSERT INTO t VALUES(1,1); | ||||||
``` | ||||||
|
||||||
``` | ||||||
Query OK, 1 row affected (0.00 sec) | ||||||
``` | ||||||
|
||||||
```sql | ||||||
SELECT TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 1, 1); | ||||||
``` | ||||||
|
||||||
``` | ||||||
+----------------------------------------------------------------------------+ | ||||||
| TIDB_ENCODE_INDEX_KEY('test', 't', 'idx', 1, 1) | | ||||||
+----------------------------------------------------------------------------+ | ||||||
| 74800000000000007f5f698000000000000001038000000000000001038000000000000001 | | ||||||
+----------------------------------------------------------------------------+ | ||||||
1 row in set (0.00 sec) | ||||||
``` | ||||||
|
||||||
## TIDB_ENCODE_RECORD_KEY | ||||||
|
||||||
Encodes a record key. | ||||||
|
||||||
```sql | ||||||
CREATE TABLE t(id int PRIMARY KEY, a int, KEY `idx` (a)); | ||||||
``` | ||||||
|
||||||
``` | ||||||
Query OK, 0 rows affected (0.00 sec) | ||||||
``` | ||||||
|
||||||
```sql | ||||||
INSERT INTO t VALUES(1,1); | ||||||
``` | ||||||
|
||||||
``` | ||||||
Query OK, 1 row affected (0.00 sec) | ||||||
``` | ||||||
|
||||||
```sql | ||||||
SELECT TIDB_ENCODE_RECORD_KEY('test', 't', 1); | ||||||
``` | ||||||
|
||||||
``` | ||||||
+----------------------------------------+ | ||||||
| TIDB_ENCODE_RECORD_KEY('test', 't', 1) | | ||||||
+----------------------------------------+ | ||||||
| 7480000000000000845f728000000000000001 | | ||||||
+----------------------------------------+ | ||||||
1 row in set (0.00 sec) | ||||||
``` | ||||||
|
||||||
```sql | ||||||
SELECT TIDB_DECODE_KEY('7480000000000000845f728000000000000001'); | ||||||
``` | ||||||
|
||||||
``` | ||||||
+-----------------------------------------------------------+ | ||||||
| TIDB_DECODE_KEY('7480000000000000845f728000000000000001') | | ||||||
+-----------------------------------------------------------+ | ||||||
| {"id":1,"table_id":"132"} | | ||||||
+-----------------------------------------------------------+ | ||||||
1 row in set (0.00 sec) | ||||||
``` | ||||||
|
||||||
## TIDB_MVCC_INFO | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Returns MVCC info for a key. The `TIDB_ENCODE_INDEX_KEY` function can be used to obtain a key. | ||||||
|
||||||
```sql | ||||||
SELECT JSON_PRETTY(TIDB_MVCC_INFO('74800000000000007f5f698000000000000001038000000000000001038000000000000001')) AS info\G | ||||||
``` | ||||||
|
||||||
``` | ||||||
*************************** 1. row *************************** | ||||||
info: [ | ||||||
{ | ||||||
"key": "74800000000000007f5f698000000000000001038000000000000001038000000000000001", | ||||||
"mvcc": { | ||||||
"info": { | ||||||
"values": [ | ||||||
{ | ||||||
"start_ts": 454654803134119936, | ||||||
"value": "MA==" | ||||||
} | ||||||
], | ||||||
"writes": [ | ||||||
{ | ||||||
"commit_ts": 454654803134119937, | ||||||
"short_value": "MA==", | ||||||
"start_ts": 454654803134119936 | ||||||
} | ||||||
] | ||||||
} | ||||||
} | ||||||
} | ||||||
] | ||||||
1 row in set (0.00 sec) | ||||||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.