Kiriakos Georgiou <kg.postgresql@olympiakos.com> writes:
> As I understand it the order the of evaluation of search arguments is up to the optimizer. I've tested the following
query,that is supposed to take advantage of advisory locks to skip over rows that are locked by other consumers running
theexact same query and it seems to work fine. It seems to me the optimizer should always prefer to scan by status.
Whatsay you?
"When it breaks, you get to keep both pieces." Was your testing even
capable of noticing the problem if the query locked more rows than you
wanted?
Less dangerous coding practices might involve putting the lock function
in an outer query, while using an OFFSET 0 in the sub-query as an
optimization fence.
regards, tom lane