2

I'm curious about what happend after execute "create index xxx" on a table of millions of rows.

According to this question Is it better to create an index before filling a table with data, or after the data is in place?,

1 million rows cost 4 seconds to create indexes, it seems fast enough.

I'm not sure if all data read and all the b+ tree index built during the 4 seconds, or the indexes are not built for whole table immediately?

Bryant
  • 101
  • 1
  • 7
  • 3
    No, the index should in fact build using the entire table's data, and also, whenever you do subsequent DML operations, MySQL should also rebuild/refresh the index. Indexing several millions rows doesn't necessarily have to take that long, depending on the data and the index. – Tim Biegeleisen Jul 28 '20 at 09:07
  • 1
    Thanks Tim, so all indexes are created synchronously after create index, and take effect for table query immediately? – Bryant Jul 28 '20 at 09:10
  • 4
    [Read here for more information](https://stackoverflow.com/questions/4244685/create-an-index-on-a-huge-mysql-production-table-without-table-locking). MySQL will not block reads/writes while the index is being created, but you still won't be able to use it until it has finished getting created. – Tim Biegeleisen Jul 28 '20 at 09:12
  • clear enough, thanks. – Bryant Jul 28 '20 at 09:16

0 Answers0