[MDEV-25338] add SKIP LOCKED to UPDATE syntax Created: 2021-04-05  Updated: 2023-08-31

Status: Open
Project: MariaDB Server
Component/s: None
Fix Version/s: None

Type: Task Priority: Major
Reporter: Olaf Buitelaar Assignee: Unassigned
Resolution: Unresolved Votes: 2
Labels: None

Issue Links:
Relates
relates to MDEV-13115 Implement SELECT [FOR UPDATE|LOCK IN ... Closed
relates to MDEV-19986 MyRocks: Range Locking: SeekForUpdate... Open

 Description   

As being discussed in MDEV-13115. It would be great if the UPDATE syntax would allow for the SKIP LOCKED instruction similar on how it's implemented for SELECT * FROM x FOR UPDATE SKIP LOCKED.
For example:

UPDATE tableX SET col1=1 SKIP LOCKED

Which would update all records in tableX which rows aren't currently locked.



 Comments   
Comment by Daniel Black [ 2021-04-06 ]

Thanks for the use case in MDEV-13115.

I've had a bit of a look at Oracle, Postgres, SQLite and have yet to see this supported feature on any UPDATE sql syntax. Can you see anything? Anything similar in other syntaxes like MERGE/UPSERT?

Sqlite has https://www.sqlite.org/lang_update.html which has a on-conflict ignore (https://www.sqlite.org/lang_conflict.html) which I don't think is the same thing because AFAIK sqlite is table level locks.

Comment by Olaf Buitelaar [ 2021-04-06 ]

I've unfortunately not found another database implementing this, while the adaptation of the SELECT ... FOR UPDATE SKIP LOCKED syntax seems to be pretty wide. I did find however that MS-SQL implements a table hint: READPAST (https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?view=sql-server-ver15) which seems to achieve the same goal.
For me it seems also just a logical extension of the SELECT ... FOR UPDATE SKIP LOCKED syntax, to be support on UPDATE and possibly DELETE (not required for my specific use-case). Since we already crossed the bridge of none-repeatable reads introduced by this syntax, why not support none-repeatable/deterministic update's(/delete's). I understand this violates many of the core foundations of a ACID database. But it seems to be very use-full in certain use-cases. And i do think when you know what your doing this allows for great features build upon.

Comment by Daniel Black [ 2021-04-07 ]

Thanks for looking. It wasn't a prerequisite, just something to syntax model if it did exist.

Significant aspects of SELECT ... FOR UPDATE SKIP LOCKED are going to be reusable with this feature.

Comment by Daniel Black [ 2022-02-11 ]

monty, serg do you have a syntax preference or objection to this feature?

Comment by Sergei Golubchik [ 2022-02-11 ]

what are the use cases?

Comment by Olaf Buitelaar [ 2022-02-11 ]

see; https://jira.mariadb.org/browse/MDEV-13115?focusedCommentId=184792&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-184792
But generally i would say certain kind of queue's with concurrent workload.

Comment by Pavel Cibulka [ 2023-08-31 ]

DELETE SKIP LOCKED - would be nice for cleaning old rows. (Remove all rows not modified in last year etc)

Generated at Thu Feb 08 09:36:56 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.