Does a SELECT FOR UPDATE incur performance cost if a row does not exist?

Viewed 40

I'm performing a query where there is a high probability the row does not exist, but I do want to lock the row via a SELECT FOR UPDATE if it does exist. Would there be any performance hit from SELECT FOR UPDATE right away in the cases where the row doesn't exist?

My use case is on postgres if the DB affects the answer.

1 Answers

If there is no matching row, SELECT ... FOR UPDATE won't be any more expensive than plain 'SELECT'.

Related