Search code examples
mysqlinnodb

How can I rebuild indexes and update stats in MySQL innoDB?


I have experience with MS SQL server where it is possible and useful to update statistic and rebuild indexes. I can't find such option in MySQL innoDB, is there such option? If not, how MySQL database create an execution plan? Does the MySQL update indexes and statistic with every UPDATE and INSERT?


Solution

  • This is done with

    ANALYZE TABLE table_name;
    

    Read more about it here.

    ANALYZE TABLE analyzes and stores the key distribution for a table. During the analysis, the table is locked with a read lock for MyISAM, BDB, and InnoDB. This statement works with MyISAM, BDB, InnoDB, and NDB tables.