Deleting millions of rows in MySQL

前端 未结 14 784
春和景丽
春和景丽 2020-12-02 07:05

I recently found and fixed a bug in a site I was working on that resulted in millions of duplicate rows of data in a table that will be quite large even without them (still

14条回答
  •  悲哀的现实
    2020-12-02 07:39

    I have faced similar issue while deleting multiple records from transaction table after moving them to archival table.

    I used to use temporary table to identify records to be deleted.

    The temporary table that I used 'archive_temp' to store ids created in memory without any indexes.

    Hence while deleting records from original transaction table as e.g. DELETE from tat where id in (select id from archive_temp); query used to return an error "LOST Connection to server"

    I created index on that temporary table as follows after creating it: ALTER TABLE archive_temp ADD INDEX( id);

    After this my delete query used to execute in less than seconds irrespective of number of records to be deleted from transaction table.

    Hence it would be better to check indexes. Hope this might help.

提交回复
热议问题