How to update index in mysql when a row is deleted

时间:2017-10-12 10:21:24

标签: mysql

really sorry if someone already asked this question, I couldn't find it and I'm stuck with it. So if I have three records in table car :

1 | Maserati | red

2 | Ferarri | red

3 | Audi | blue

...and I delete Ferarri record, I'm left with :

1 | Maserati | red
3 | Audi | blue

Is there a way to have this table automatically indexed as such :

1 | Maserati | red
2 | Audi | blue

Note: I have an index column which is set to autoincrement.

Thanks a lot!

1 个答案:

答案 0 :(得分:0)

时间(绝对不是在每次删除查询之后),您可以运行以下语句:

  • CHECK TABLE tab; - 检查表是否有错误,MyISAM - 更新密钥统计信息!
  • ANALYZE TABLE tab; - 执行密钥分发分析。
  • OPTIMIZE TABLE tab; - 重新组织表数据和相关索引数据的物理存储(碎片整理)。

它们将提高您的索引性能。

相关问题