08.10.2022 16:47, Adriano dos Santos Fernandes wrote:
>
> At least PostgreSQL and Oracle has this feature.
>
> It allows to easily implement work queues, where many workers read
> records from a table and no one get duplicate records.
Agree, I also had it in mind for the nearest future.
> Firebird implements FOR UPDATE different than others, and actually WITH
> LOCK is more likely others FOR UPDATE (without SKIP LOCKED).
Correct.
> But I don't see a good way to mix WITH LOCK and SKIP LOCKED.
Just an idea:
WITH LOCK [{WAIT | NO WAIT}]
where WAIT is our current (and default) behaviour while NO WAIT means
skipping the record we could not lock.
But I admit it may be not really friendly to users.
> I propose we implement FOR UPDATE SKIP LOCKED clause with following
> semantics:
> - It will disable batches like FOR UPDATE
> - It will lock rows like WITH LOCK
> - It will skip locked rows (new feature)
I respectfully disagree, because I'd like FOR UPDATE to really do what
it means -- ensure the cursor is updatable (i.e. throw an error if it's
non-updatable). Disabling protocol-level buffering may remain as a bonus
feature (and to preserve backward compatibility). But this way it does
not match other DMBS's behaviour and mixing things is going to be even
more confusing.
Personally, I'd rather go for [somewhat ugly] WITH LOCK SKIP LOCKED
instead of reusing the FOR UPDATE semantics. Or maybe we could still
find a better syntax.
> Do you see any blocker to implement this for Firebird?
No. Although I have a question: whether only SELECT WITH LOCK is allowed
to skip already locked rows? Could it be useful for regular SELECTs
(without locking) too? What about UPDATEs and DELETEs?
Dmitry