RELEASE_LOCK()¶
Releases one reference to a named user-level advisory lock held by the current session.
Syntax¶
RELEASE_LOCK(name)
Arguments¶
Argument |
Description |
|---|---|
|
Case-insensitive lock name to release. |
Return Value¶
Returns
1when the current session releases a lock reference.Returns
0when the lock exists but is held by another session.Returns
NULLwhen the named lock does not exist or the input is invalid.
Usage Notes¶
Repeated
GET_LOCK()calls by one session are reference-counted; the lock becomes free after the matching number of releases.Source evidence:
test/distributed/cases/function/user_lock.sql.
Examples¶
DROP DATABASE IF EXISTS release_lock_demo;
CREATE DATABASE release_lock_demo;
USE release_lock_demo;
SELECT GET_LOCK('refresh_cache', 0);
SELECT GET_LOCK('refresh_cache', 0);
SELECT RELEASE_LOCK('refresh_cache') AS first_release;
SELECT RELEASE_LOCK('refresh_cache') AS final_release;
SELECT IS_FREE_LOCK('refresh_cache') AS is_free;
DROP DATABASE release_lock_demo;