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

Different tidb node in the same cluster get the different table ID for the same table in metrics_schema #56775

Closed
lcwangchao opened this issue Oct 22, 2024 · 1 comment · Fixed by #56839
Assignees
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@lcwangchao
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Setup a cluster with 2 tidb nodes.

Run the SQL below in each node:

select tidb_table_id, table_name from information_schema.tables where table_schema='metrics_schema' and table_name='tidb_ddl_total_time' limit 1;

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

The query returns the same result in different TiDB nodes.

3. What did you see instead (Required)

The results are not the same.

In one node

> select tidb_table_id, table_name from information_schema.tables where table_schema='metrics_schema' and table_name='tidb_ddl_total_time' limit 1;
+---------------------+---------------------+
| tidb_table_id       | table_name          |
+---------------------+---------------------+
| 4611686018427408458 | tidb_ddl_total_time |
+---------------------+---------------------+

In another node

> select tidb_table_id, table_name from information_schema.tables where table_schema='metrics_schema' and table_name='tidb_ddl_total_time' limit 1;
+---------------------+---------------------+
| tidb_table_id       | table_name          |
+---------------------+---------------------+
| 4611686018427408007 | tidb_ddl_total_time |
+---------------------+---------------------+
1 row in set
Time: 0.010s

4. What is your TiDB version? (Required)

@lcwangchao lcwangchao added type/bug The issue is confirmed as a bug. sig/sql-infra SIG: SQL Infra severity/moderate labels Oct 22, 2024
@lcwangchao
Copy link
Collaborator Author

The meta of tables in metrics_schema is generated in memory by iterating MetricTableMap

tableID := dbID + 1
metricTables := make([]*model.TableInfo, 0, len(MetricTableMap))
for name, def := range MetricTableMap {
cols := def.genColumnInfos()
tableInfo := buildTableMeta(name, cols)
tableInfo.ID = tableID
tableInfo.Comment = def.Comment
tableInfo.DBID = dbID
tableID++
metricTables = append(metricTables, tableInfo)
tableInfo.MaxColumnID = int64(len(tableInfo.Columns))
tableInfo.MaxIndexID = int64(len(tableInfo.Indices))
}

However, MetricTableMap is an object of type map that does not guarantee the order when iterating.

var MetricTableMap = map[string]MetricTableDef{

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant