I have a MyISAM table with more than 10^7 rows. When adding data to it, I have to update ~10 rows at the end. Is it faster to delete them and then insert the new ones, or is it
UPDATE
is by far much faster.
When you UPDATE
, the table records are just being rewritten with new data.
When you DELETE
, the indexes should be updated (remember, you delete the whole row, not only the columns you need to modify) and datablocks may be moved (if you hit the PCTFREE
limit)
And all this must be done again on INSERT
.
That's why you should always use
INSERT ... ON DUPLICATE KEY UPDATE
instead of REPLACE
.
The former one is an UPDATE
operation in case of a key violation, while the latter one is DELETE
/ INSERT
.