tidb_decode_key() doesn't show primary keys and some key fields
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### 1. Minimal reproduce step (Required)
1. create table:
```sql
CREATE TABLE `events` (
`timestamp` TIMESTAMP NOT NULL,
`institution_id` VARCHAR(64) NOT NULL,
`event_id` BINARY(16) NOT NULL,
`event_type` VARCHAR(32),
`payload` TEXT,
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`timestamp`, `institution_id`, `event_id`) /*T![clustered_index] CLUSTERED */
);
```
2. Load data using [this](https://gist.github.com/mzhang77/73a8f9f2304b43d991f222699c203916) script.
3. create index:
```sql
CREATE INDEX idx_event_type ON events(event_type);
```
4. Run following queries:
```sql
mysql> select start_key from information_schema.tikv_region_status where table_name='events' limit 1;
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| start_key |
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| 7480000000000000FF665F720419B6CC77FFE100000001494E53FF5430363900FE0149FF442FDED8DA3F07FFFFD1B11729D2125020FFFF00000000000000FF00F7000000000000F9 |
+--------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select tidb_decode_key('7480000000000000FF665F720419B6CC77FFE100000001494E53FF5430363900FE0149FF442FDED8DA3F07FFFFD1B11729D2125020FFFF00000000000000FF00F7000000000000F9');
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_decode_key('7480000000000000FF665F720419B6CC77FFE100000001494E53FF5430363900FE0149FF442FDED8DA3F07FFFFD1B11729D2125020FFFF00000000000000FF00F7000000000000F9') |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"handle":{"event_id":"ID/\ufffd\ufffd\ufffd?\u0007ѱ\u0017)\ufffd\u0012P ","timestamp":"2025-06-06 03:31:33"},"table_id":102} |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select start_key from information_schema.tikv_region_status where table_name='events' and index_id=2 limit 1;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| start_key |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 7480000000000000FF665F698000000000FF000003016C6F6769FF6E000000FC0419B6FFCAE0000000000149FF4E535430313600FEFF01A11E3F06186CDDFF99FF2D53A43DE789FFA031FF0000000000FF000000F700000000FB |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> select tidb_decode_key('7480000000000000FF665F698000000000FF000003016C6F6769FF6E000000FC0419B6FFCAE0000000000149FF4E535430313600FEFF01A11E3F06186CDDFF99FF2D53A43DE789FFA031FF0000000000FF000000F700000000FB');
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_decode_key('7480000000000000FF665F698000000000FF000003016C6F6769FF6E000000FC0419B6FFCAE0000000000149FF4E535430313600FEFF01A11E3F06186CDDFF99FF2D53A43DE789FFA031FF0000000000FF000000F700000000FB') |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"index_id":3,"index_vals":{"event_type":"login"},"table_id":102} |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
There are 2 issues here:
1. For the non-index region, tidb_decode_key() function does not show `institution_id` value.
2. For the index region, tidb_decode_key() function does not show primary key.
However, if I find a new cluster without table: 102, I'll get correct result:
```sql
mysql> select tidb_decode_key('7480000000000000FF665F720419B6CC77FFE100000001494E53FF5430363900FE0149FF442FDED8DA3F07FFFFD1B11729D2125020FFFF00000000000000FF00F7000000000000F9');
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_decode_key('7480000000000000FF665F720419B6CC77FFE100000001494E53FF5430363900FE0149FF442FDED8DA3F07FFFFD1B11729D2125020FFFF00000000000000FF00F7000000000000F9') |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"handle":"{1852893111957585920, INST069, ID/\ufffd\ufffd\ufffd?\u0007ѱ\u0017)\ufffd\u0012P }","table_id":102} |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select tidb_decode_key('7480000000000000FF665F698000000000FF000003016C6F6769FF6E000000FC0419B6FFCAE0000000000149FF4E535430313600FEFF01A11E3F06186CDDFF99FF2D53A43DE789FFA031FF0000000000FF000000F700000000FB');
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_decode_key('7480000000000000FF665F698000000000FF000003016C6F6769FF6E000000FC0419B6FFCAE0000000000149FF4E535430313600FEFF01A11E3F06186CDDFF99FF2D53A43DE789FFA031FF0000000000FF000000F700000000FB') |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"index_id":3,"index_vals":"login, 1852891360131022848, INST016, \ufffd\u001e?\u0006\u0018lݙ-S\ufffd=牠1","table_id":102} |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
### 2. What did you expect to see? (Required)
tidb_decode_key() should not be impacted by the existing objects in cluster
### 3. What did you see instead (Required)
tidb_decode_key() returns different result for same key depending on the objects in cluster
### 4. What is your TiDB version? (Required)
v7.5.5
Contributor guide
Assessment
This issue has not been assessed yet.