Search code examples
mysqlperformanceinsertsql-update

Is mysql UPDATE faster than INSERT INTO?


This is more of a theory question.

If I'm running 50,000 queries that insert new rows, and 50,000 queries that updates those rows, which one will take less time?


Solution

  • Insert would be faster because with update you need to first search for the record that you are going to update and then perform the update.

    Though this hardly seems like a valid comparison as you never have a choice whether to insert or update as the two fill two completely different needs.

    EDIT: I should add too that this is with the assumption that there are no insert triggers or other situations that could cause potential bottlenecks.