Is it more efficient to always run a DELETE query by default whether an entry exists or not, for example to delete a user name after a certain period of time (DELETE * from table WHERE username='user'), or should you first check if the rows to be deleted exist using a SELECT query and checking mysql_num_rows.
What uses more processor resources on the server side?
Obviously one approach contains more code, but I was wondering if certain mysql operations used a lot more CPU than others.
Delete is more efficient since the system takes as much time (and literally do exactly the same work) finding rows to delete as it would have on select.
However, if you wish to have special logic kick in if zero rows were deleted, you can use ROW_COUNT() function and check if it’s zero after the delete.
Also, see the related answer here.