Skip to content
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

Get wrong result when select TIKV_REGION_STATUS with table_id #45531

Closed
King-Dylan opened this issue Jul 24, 2023 · 1 comment · Fixed by #45556
Closed

Get wrong result when select TIKV_REGION_STATUS with table_id #45531

King-Dylan opened this issue Jul 24, 2023 · 1 comment · Fixed by #45556
Assignees
Labels

Comments

@King-Dylan
Copy link
Contributor

King-Dylan commented Jul 24, 2023

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

@King-Dylan King-Dylan added the type/bug The issue is confirmed as a bug. label Jul 24, 2023
@ti-chi-bot ti-chi-bot bot added may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Jul 24, 2023
@seiya-annie seiya-annie removed may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Jul 24, 2023
@Defined2014 Defined2014 self-assigned this Jul 25, 2023
@cgtz
Copy link

cgtz commented Jul 25, 2023

Thank you @Defined2014 for making this fix. Can this be pulled into the 6.5 release branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants