I have Large table with 2 million rows and 50 columns.
When iam updating/inserting large amount of data iam dropping all indexes and rebuild them again using 2 queries. this works fine
But iam thinking to use another query for that example :
ALTER TABLE [table_name] ENGINE = InnoDB
as i read from the mysql guide here http://dev.mysql.com/doc/refman/5.6/en/optimize-table.html
InnoDB Details
For InnoDB tables, OPTIMIZE TABLE is mapped to ALTER TABLE ... FORCE, which rebuilds the table to update index statistics and free unused space in the clustered index. This is displayed in the output of OPTIMIZE TABLE when you run it on an InnoDB table
Also i think optimize will rebuild the index?
OPTIMIZE TABLE [table_name]
what do you recommend, my table have more then 2 million rows and 50 columns
Have you been doing
SHOW TABLE STATUS
before and after your drop+rebuild? Does Index_length change much? Probably not by even a factor of two.I almost never recommend rebuilding anything in InnoDB. It's not worth it. A glaring exception has to do with with
FULLTEXT
indexes.Yes the dummy
ALTER
will rebuild the indexes. So willOPTIMIZE TABLE
. Both will "defragment" (to some extent) the secondary index BTrees and the main BTree (which contains the data andPRIMARY KEY
).The statistics can be much more cheaply updated using just
ANALYZE TABLE
. Even that is not often needed. 5.6 has a much better way of maintaining the stats.If you are not already using
innodb_file_per_table=ON
, I suggest you set that (SET GLOBAL ...
) and doALTER TABLE tbl ENGINE=InnoDB;
one last time.Online alter
To change
ft_*
, you need to rebuild the index. This implies anALTER
(orOPTIMIZE
, which is implemented asALTER
). Newer versions of MySQL haveALGORITHM=INPLACE
which makesALTER
have little or no impact on the running system. But, there are limitations. Check the manual.An alternative to a non-INPLACE
ALTER
ispt-query-digest
orgh-ost
. See if either of them will work for your case.Short of "rebuilding the table", you can
DROP INDEX ...
andADD INDEX ...
. Again, I don't know if these work for FT indexes "inplace". Anyway, you would lose the use of that index during the process.