bulk insert with or without index

后端 未结 3 2080
灰色年华
灰色年华 2021-02-20 16:58

In a comment I read

Just as a side note, it\'s sometimes faster to drop the indices of your table and recreate them after the bulk insert operation.

<
3条回答
  •  旧时难觅i
    2021-02-20 17:02

    Yes, it is true. When there are indexes on the table during an insert, the server will need to be constantly re-ordering/paging the table to keep the indexes up to date. If you drop the indexes, it can just add the rows without worrying about that, and then build the indexes all at once when you re-create them.


    The exception, of course, is when the import data is already in index order. In fact, I should note that I'm working on a project right now where this opposite effect was observed. We wanted to reduce the run-time of a large import (nightly dump from a mainframe system). We tried removing the indexes, importing the data, and re-creating them. It actually significantly increased the time for the import to complete. But, this is not typical. It just goes to show that you should always test first for your particular system.

提交回复
热议问题