MySQL:索引长度零字节(innodb表)

时间:2016-02-20 14:22:50

标签: mysql percona

我有一个包含大约700M行的INNODB表。

我创建了一个没有索引的新空压缩表,在数据导入后我重新创建了7个索引

现在执行SHOW TABLE STATUS我看到索引长度为零字节:

name:mytable

引擎:InnoDB

行格式:压缩

行:691027999

Data_length:24464850944(22,78 GB)

Index_length:0

Data_free:2621440

IDB文件不是22,78Gb,而是130Gb和索引效果很好。

我尝试重新启动但没有任何改变。

为什么MySQL不会更新正确的索引长度?

(我使用Percona 5.6)

[解决]我用ANALYZE TABLE

修复它

1 个答案:

答案 0 :(得分:1)

这种行为似乎是MySQL的一个错误,可以轻松复制。

SQL:

drop table tbl;
create table tbl(c1 int, c2 int);
create index i1 on tbl(c1,c2);
show table status like 'tbl';
drop table tbl;
create table tbl(c1 int, c2 int, key i1(c1,c2));
show table status like 'tbl';

输出:

mysql> create table tbl(c1 int, c2 int);
Query OK, 0 rows affected (0.01 sec)

mysql> create index i1 on tbl(c1,c2);
show table status likQuery OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show table status like 'tbl';
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time | Check_time | Collation          | Checksum | Create_options | Comment |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| tbl  | InnoDB |      10 | Compact    |    0 |              0 |       16384 |               0 |            0 |         0 |           NULL | 2016-02-20 22:39:31 | NULL        | NULL       | utf8mb4_general_ci |     NULL |                |         |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
1 row in set (0.00 sec)

mysql> drop table tbl;
Query OK, 0 rows affected (0.00 sec)

mysql> create table tbl(c1 int, c2 int, key i1(c1,c2));
 status like 'tbl';
Query OK, 0 rows affected (0.01 sec)

mysql> show table status like 'tbl';
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time | Check_time | Collation          | Checksum | Create_options | Comment |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
| tbl  | InnoDB |      10 | Compact    |    0 |              0 |       16384 |               0 |        16384 |         0 |           NULL | 2016-02-20 22:39:31 | NULL        | NULL       | utf8mb4_general_ci |     NULL |                |         |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc  |
+-----------+
1 row in set (0.00 sec)