I'm trying to optimize queries modelled on the following example:
UPDATE posts
SET title = "Example", lock_version = 1
WHERE (
posts.id = 123
AND
posts.lock_version = 0
)
I have a unique index on posts.id, which ensures that positive hits on WHERE posts.id = 123 will never return more than one result.
Do I also need an index on posts.lock_version?
I imagine I would need it if the first part of the WHERE returned more than one result, because the index would make it faster to narrow down the filter.
What about the situation I described, though?