Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 456
Citizen Avatar asked Jul 14 '10 22:07

Citizen


People also ask

Which is faster INSERT or update in SQL?

INSERT is faster than UPDATE because UPDATE does what INSERT does and before that it finds the record(s) and marks them deletion. I have a database with 500,000 records.

Are updates faster than inserts?

Insert is more faster than update because in insert there's no checking of data.

Is INSERT same as update in MySQL?

Is insert same as update in MySQL? Insert is for adding data to the table, update is for updating data that is already in the table.

Is select into faster than update?

We conducted performance testing, and seems select into is slightly faster.


2 Answers

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.

like image 165
spinon Avatar answered Oct 04 '22 00:10

spinon


Insert Operation : Create  -> Store

Update Operation : Retrieve -> Modify -> Store

Insert Operation faster.

like image 32
Vishwanath Dalvi Avatar answered Oct 03 '22 23:10

Vishwanath Dalvi