mysqlsql

UPDATE vs INSERT performance


Am I correct to assume that an UPDATE query takes more resources than an INSERT query?


Solution

  • I am not a database guru but here my two cents:

    Personally I don't think you have much to do in this regard, even if INSERT would be faster (all to be proven), can you convert an update in an insert?! Frankly I don't think you can do it all the times.

    During an INSERT you don't usually have to use WHERE to identify which row to update but depending on your indices on that table the operation can have some cost.

    During an update if you do not change any column included in any indices you could have quick execution, if the where clause is easy and fast enough.

    Nothing is written in stones and really I would imagine it depends on whole database setup, indices and so on.

    Anyway, found this one as a reference:

    Top 84 MySQL Performance Tips