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

Two table ids are allocated when creating a table, but only one is used. #48725

Open
mjonss opened this issue Nov 20, 2023 · 3 comments
Open
Labels
component/ddl This issue is related to DDL of TiDB. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.

Comments

@mjonss
Copy link
Contributor

mjonss commented Nov 20, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

tidb> create table t1 (a int);
Query OK, 0 rows affected (0.09 sec)

tidb> create table t2 (a int);
Query OK, 0 rows affected (0.08 sec)

tidb> SELECT TABLE_NAME, START_KEY, END_KEY FROM information_schema.TIKV_REGION_STATUS WHERE TABLE_NAME IN ('t1', 't2');
+------------+--------------------------------------+--------------------------------------+
| TABLE_NAME | START_KEY                            | END_KEY                              |
+------------+--------------------------------------+--------------------------------------+
| t1         | 7480000000000000FF6600000000000000F8 | 7480000000000000FF6800000000000000F8 |
| t2         | 7480000000000000FF6800000000000000F8 | 748000FFFFFFFFFFFFF900000000000000F8 |
+------------+--------------------------------------+--------------------------------------+
2 rows in set (0.00 sec)

tidb> select table_name, tidb_table_id from information_schema.tables where table_name in ('t1', 't2');
+------------+---------------+
| table_name | tidb_table_id |
+------------+---------------+
| t1         |           102 |
| t2         |           104 |
+------------+---------------+
2 rows in set (0.01 sec)

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

Consecutive table ids, not a gap of one id (wasted one table id).

3. What did you see instead (Required)

Two table ids used when creating a single table.
Also the region end key is table_id + 2, what can be between table_id +1 .. table_id +2?

4. What is your TiDB version? (Required)

tidb_version(): Release Version: v7.6.0-alpha
Edition: Community
Git Commit Hash: 3f94666b4bafd903886b89206ac603d26d9a9e87
Git Branch: heads/refs/tags/v7.6.0-alpha
UTC Build Time: 2023-11-18 14:26:36
GoVersion: go1.21.3
Race Enabled: false
Check Table Before Drop: false
Store: tikv
@Defined2014
Copy link
Contributor

Defined2014 commented Dec 21, 2023

Because the DDL job id and table id use the same allocator. So the it will have a gap between two tables. Maybe it's by design.
They both use func (m *Meta) GenGlobalIDs(n int) ([]int64, error) to get id from TiKV.
/cc @zimulala

@zimulala
Copy link
Contributor

@Defined2014
Yeah, it was designed that way from the beginning

@Defined2014
Copy link
Contributor

Because the DDL job id and table id use the same allocator. So the it will have a gap between two tables. Maybe it's by design. They both use func (m *Meta) GenGlobalIDs(n int) ([]int64, error) to get id from TiKV. /cc @zimulala

@Defined2014 Yeah, it was designed that way from the beginning

According to what was mentioned above, I will change the type to enhancement first.

@Defined2014 Defined2014 added type/enhancement The issue or PR belongs to an enhancement. component/ddl This issue is related to DDL of TiDB. sig/sql-infra SIG: SQL Infra and removed severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug. labels Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/ddl This issue is related to DDL of TiDB. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

4 participants