Tweak to locking query