pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.88k stars 5.8k forks source link

INDEX_LENGTH is different in INFORMATION_SCHEMA.Tables in Mysql and TIDB #35141

Open Alkaagr81 opened 2 years ago

Alkaagr81 commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

 CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
 INSERT INTO t1 VALUES(0);
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
 UPDATE t1 SET val=1;
 SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
DROP TABLE t1;

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

mysql>  CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
Query OK, 0 rows affected (0.00 sec)

mysql>  INSERT INTO t1 VALUES(0);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
+--------------+
| INDEX_LENGTH |
+--------------+
|           37 |
+--------------+
1 row in set (0.00 sec)

mysql>  UPDATE t1 SET val=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>  SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
+--------------+
| INDEX_LENGTH |
+--------------+
|           37 |
+--------------+
1 row in set (0.00 sec)

mysql> DROP TABLE t1;
Query OK, 0 rows affected (0.00 sec)

### 3. What did you see instead (Required)
```sql
mysql>  CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
Query OK, 0 rows affected (0.00 sec)

mysql>  INSERT INTO t1 VALUES(0);
Query OK, 1 row affected (0.01 sec)

mysql> SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
+--------------+
| INDEX_LENGTH |
+--------------+
|            0 |
+--------------+
1 row in set (0.00 sec)

mysql>  UPDATE t1 SET val=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>  SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
+--------------+
| INDEX_LENGTH |
+--------------+
|            0 |
+--------------+
1 row in set (0.01 sec)

mysql> DROP TABLE t1;
Query OK, 0 rows affected (0.01 sec)

4. What is your TiDB version? (Required)

| Release Version: v6.1.0-alpha-480-g9f7813ca6
Edition: Community
Git Commit Hash: 9f7813ca6009fce061e92ae38a0b45cbfbc200f4
Git Branch: master
UTC Build Time: 2022-05-19 20:32:03
GoVersion: go1.18
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
fanrenhoo commented 2 years ago

/assign

fanrenhoo commented 2 years ago

I tested. this issue might be OK. because it seems that the index_length showed a bit later, that means, when you just created table and inserted value, it shows 0, but after a while, it shows OK. So its should be because TiDB has some thread schedulely check to update this value, if so, it should be OK

fanrenhoo commented 2 years ago

And the length did is not same as MySQL, but this related to charset encoding, so does not need to be same as MySQL

fanrenhoo commented 2 years ago

So this issue I think it should be closed

kennedy8312 commented 8 months ago

/type compatibility

fanrenhoo commented 1 month ago

/close

ti-chi-bot[bot] commented 1 month ago

@fanrenhoo: You can't close an active issue/PR unless you authored it or you are a collaborator.

In response to [this](https://github.com/pingcap/tidb/issues/35141#issuecomment-2261744905): >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.