Skip to content

Get wrong result when select TIKV_REGION_STATUS with table_id #45531

@King-Dylan

Description

@King-Dylan

Bug Report

Get wrong result when select TIKV_REGION_STATUS with table_id,it may limited by https://github.com/tikv/pd/blob/v6.5.1/server/api/region.go#L351

1. Minimal reproduce step (Required)

  1. Launch tiup playground 6.5.1

  2. Run mysql cli: mysql --comments --host 127.0.0.1 --port 4000 -u root

  3. Create simple table:

mysql> CREATE TABLE test.t1 (k varchar(32) primary key, v varchar(32) not null);
Query OK, 0 rows affected (0.08 sec)
  1. Split table into 25 regions:
mysql> SPLIT TABLE test.t1 BETWEEN ("a") AND ("z") REGIONS 25;
+--------------------+----------------------+
| TOTAL_SPLIT_REGION | SCATTER_FINISH_RATIO |
+--------------------+----------------------+
| 24 | 1 |
+--------------------+----------------------+
1 row in set (0.02 sec)
  1. The following query that does not do the pushdown to pd will return the right number of regions (25 data + 1 index column):
mysql> select region_id, is_index, start_key from information_schema.tikv_region_status where db_name = 'test' and table_name = 't1';
+-----------+----------+--------------------------------------------------------+
| region_id | is_index | start_key |
+-----------+----------+--------------------------------------------------------+
| 10 | 0 | 7480000000000000FF595F720179000000FF0000000000000000FB |
| 107 | 0 | 7480000000000000FF595F720166000000FF0000000000000000FB |
| 121 | 0 | 7480000000000000FF595F72016D000000FF0000000000000000FB |
| 103 | 0 | 7480000000000000FF595F720164000000FF0000000000000000FB |
| 109 | 0 | 7480000000000000FF595F720167000000FF0000000000000000FB |
| 143 | 0 | 7480000000000000FF595F720178000000FF0000000000000000FB |
| 131 | 0 | 7480000000000000FF595F720172000000FF0000000000000000FB |
| 99 | 0 | 7480000000000000FF595F720162000000FF0000000000000000FB |
| 137 | 0 | 7480000000000000FF595F720175000000FF0000000000000000FB |
| 141 | 0 | 7480000000000000FF595F720177000000FF0000000000000000FB |
| 113 | 0 | 7480000000000000FF595F720169000000FF0000000000000000FB |
| 127 | 0 | 7480000000000000FF595F720170000000FF0000000000000000FB |
| 125 | 0 | 7480000000000000FF595F72016F000000FF0000000000000000FB |
| 105 | 0 | 7480000000000000FF595F720165000000FF0000000000000000FB |
| 111 | 0 | 7480000000000000FF595F720168000000FF0000000000000000FB |
| 97 | 1 | 7480000000000000FF5900000000000000F8 |
| 97 | 0 | 7480000000000000FF5900000000000000F8 |
| 133 | 0 | 7480000000000000FF595F720173000000FF0000000000000000FB |
| 139 | 0 | 7480000000000000FF595F720176000000FF0000000000000000FB |
| 115 | 0 | 7480000000000000FF595F72016A000000FF0000000000000000FB |
| 117 | 0 | 7480000000000000FF595F72016B000000FF0000000000000000FB |
| 129 | 0 | 7480000000000000FF595F720171000000FF0000000000000000FB |
| 135 | 0 | 7480000000000000FF595F720174000000FF0000000000000000FB |
| 101 | 0 | 7480000000000000FF595F720163000000FF0000000000000000FB |
| 119 | 0 | 7480000000000000FF595F72016C000000FF0000000000000000FB |
| 123 | 0 | 7480000000000000FF595F72016E000000FF0000000000000000FB |
+-----------+----------+--------------------------------------------------------+
26 rows in set (0.00 sec)

2. What did you expect to see? (Required)

  1. The following query that uses the table_id will be truncated (16 data regions + 1 index region):
mysql> select tidb_table_id from information_schema.tables where table_schema='test' and table_name='t1';
+---------------+
| tidb_table_id |
+---------------+
| 89 |
+---------------+
1 row in set (0.00 sec)

mysql> select region_id, is_index, start_key from information_schema.tikv_region_status where table_id = 89;
+-----------+----------+--------------------------------------------------------+
| region_id | is_index | start_key |
+-----------+----------+--------------------------------------------------------+
| 10 | 0 | 7480000000000000FF595F720179000000FF0000000000000000FB |
| 107 | 0 | 7480000000000000FF595F720166000000FF0000000000000000FB |
| 121 | 0 | 7480000000000000FF595F72016D000000FF0000000000000000FB |
| 103 | 0 | 7480000000000000FF595F720164000000FF0000000000000000FB |
| 109 | 0 | 7480000000000000FF595F720167000000FF0000000000000000FB |
| 143 | 0 | 7480000000000000FF595F720178000000FF0000000000000000FB |
| 131 | 0 | 7480000000000000FF595F720172000000FF0000000000000000FB |
| 99 | 0 | 7480000000000000FF595F720162000000FF0000000000000000FB |
| 137 | 0 | 7480000000000000FF595F720175000000FF0000000000000000FB |
| 141 | 0 | 7480000000000000FF595F720177000000FF0000000000000000FB |
| 113 | 0 | 7480000000000000FF595F720169000000FF0000000000000000FB |
| 127 | 0 | 7480000000000000FF595F720170000000FF0000000000000000FB |
| 125 | 0 | 7480000000000000FF595F72016F000000FF0000000000000000FB |
| 105 | 0 | 7480000000000000FF595F720165000000FF0000000000000000FB |
| 111 | 0 | 7480000000000000FF595F720168000000FF0000000000000000FB |
| 97 | 1 | 7480000000000000FF5900000000000000F8 |
| 97 | 0 | 7480000000000000FF5900000000000000F8 |
| 133 | 0 | 7480000000000000FF595F720173000000FF0000000000000000FB |
| 139 | 0 | 7480000000000000FF595F720176000000FF0000000000000000FB |
| 115 | 0 | 7480000000000000FF595F72016A000000FF0000000000000000FB |
| 117 | 0 | 7480000000000000FF595F72016B000000FF0000000000000000FB |
| 129 | 0 | 7480000000000000FF595F720171000000FF0000000000000000FB |
| 135 | 0 | 7480000000000000FF595F720174000000FF0000000000000000FB |
| 101 | 0 | 7480000000000000FF595F720163000000FF0000000000000000FB |
| 119 | 0 | 7480000000000000FF595F72016C000000FF0000000000000000FB |
| 123 | 0 | 7480000000000000FF595F72016E000000FF0000000000000000FB |
+-----------+----------+--------------------------------------------------------+
26 rows in set (0.00 sec)

3. What did you see instead (Required)

  1. The following query that uses the table_id will be truncated (16 data regions + 1 index region):
mysql> select tidb_table_id from information_schema.tables where table_schema='test' and table_name='t1';
+---------------+
| tidb_table_id |
+---------------+
| 89 |
+---------------+
1 row in set (0.00 sec)

mysql> select region_id, is_index, start_key from information_schema.tikv_region_status where table_id = 89;
+-----------+----------+--------------------------------------------------------+
| region_id | is_index | start_key |
+-----------+----------+--------------------------------------------------------+
| 97 | 1 | 7480000000000000FF5900000000000000F8 |
| 97 | 0 | 7480000000000000FF5900000000000000F8 |
| 105 | 0 | 7480000000000000FF595F720165000000FF0000000000000000FB |
| 115 | 0 | 7480000000000000FF595F72016A000000FF0000000000000000FB |
| 99 | 0 | 7480000000000000FF595F720162000000FF0000000000000000FB |
| 103 | 0 | 7480000000000000FF595F720164000000FF0000000000000000FB |
| 107 | 0 | 7480000000000000FF595F720166000000FF0000000000000000FB |
| 111 | 0 | 7480000000000000FF595F720168000000FF0000000000000000FB |
| 113 | 0 | 7480000000000000FF595F720169000000FF0000000000000000FB |
| 119 | 0 | 7480000000000000FF595F72016C000000FF0000000000000000FB |
| 123 | 0 | 7480000000000000FF595F72016E000000FF0000000000000000FB |
| 125 | 0 | 7480000000000000FF595F72016F000000FF0000000000000000FB |
| 127 | 0 | 7480000000000000FF595F720170000000FF0000000000000000FB |
| 121 | 0 | 7480000000000000FF595F72016D000000FF0000000000000000FB |
| 101 | 0 | 7480000000000000FF595F720163000000FF0000000000000000FB |
| 109 | 0 | 7480000000000000FF595F720167000000FF0000000000000000FB |
| 117 | 0 | 7480000000000000FF595F72016B000000FF0000000000000000FB |
+-----------+----------+--------------------------------------------------------+
17 rows in set (0.01 sec)

4. What is your TiDB version? (Required)

master

Metadata

Metadata

Assignees

Labels

affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.severity/majorsig/sql-infraSIG: SQL Infratype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions