Skip to main content
Version: V1.1.0

IS_FREE_LOCK

Description

This function checks whether the lock named by the string str is free, i.e., whether the named lock is held by any session.

Syntax

IS_FREE_LOCK('str')

Examples

Parameters

str: the name of the lock to check. The value is a string.

Return value

  • Returns 1: the lock is free, i.e., no session holds the lock.

  • Returns 0: the lock is not free, i.e., some session holds the lock.

Examples

Check whether the lock named my_lock is available.

SELECT IS_FREE_LOCK('my_lock');

The result is as follows:

+-------------------------+
| IS_FREE_LOCK('my_lock') |
+-------------------------+
| 0 |
+-------------------------+
1 row in set (0.001 sec)

The result is 0, indicating that the lock my_lock is held by some session. You can execute IS_USED_LOCK() to query the session identifier (session ID) of the session that holds the lock. Example:

SELECT IS_USED_LOCK('my_lock');

The result is as follows:

+-------------------------+
| IS_USED_LOCK('my_lock') |
+-------------------------+
| 3221487701 |
+-------------------------+
1 row in set (0.001 sec)

References

IS_USED_LOCK