Skip to content

Commit

Permalink
v6.1: add locking function docs (pingcap#9568)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomShawn authored May 27, 2022
1 parent ac34252 commit c0b51cc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@
- [位函数和操作符](/functions-and-operators/bit-functions-and-operators.md)
- [Cast 函数和操作符](/functions-and-operators/cast-functions-and-operators.md)
- [加密和压缩函数](/functions-and-operators/encryption-and-compression-functions.md)
- [锁函数](/functions-and-operators/locking-functions.md)
- [信息函数](/functions-and-operators/information-functions.md)
- [JSON 函数](/functions-and-operators/json-functions.md)
- [GROUP BY 聚合函数](/functions-and-operators/aggregate-group-by-functions.md)
Expand Down
27 changes: 27 additions & 0 deletions functions-and-operators/locking-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: 锁函数
summary: 了解 TiDB 中的用户级锁函数。
---

# 锁函数

TiDB 支持 MySQL 5.7 中的大部分用户级[锁函数](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html)

## 支持的函数

| 函数名 | 功能描述 |
|:---------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------|
| [`GET_LOCK(lockName, timeout)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_get-lock) | 获取咨询锁。`lockName` 参数不得超过 64 个字符。在超时前,TiDB 最长等待 `timeout` 秒并返回失败。 |
| [`RELEASE_LOCK(lockName)`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-lock) | 释放先前获取的锁。`lockName` 参数不得超过 64 个字符。 |
| [`RELEASE_ALL_LOCKS()`](https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_release-all-locks) | 释放当前会话持有的所有锁。 |

## MySQL 兼容性

* TiDB 允许的最短超时时间为 1 秒,最长超时时间为 1 小时(即 3600 秒)。而 MySQL 允许最短 0 秒和最长无限超时。TiDB 会自动将超出范围的值转换为最接近的允许值。
* TiDB 不会自动检测用户级锁导致的死锁。死锁会话将在 1 小时内超时,但你也可以在任一受影响的会话上使用 `KILL` 语句手动终止死锁。你还可以通过始终用相同顺序获取用户级锁的方法来防止死锁。
* 在 TiDB 中,锁对集群中所有 TiDB 服务器生效。而在 MySQL Cluster 和 Group Replication 中,锁只对本地单个服务器生效。

## 不支持的函数

* `IS_FREE_LOCK()`
* `IS_USED_LOCK()`
1 change: 0 additions & 1 deletion mysql-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ aliases: ['/docs-cn/dev/mysql-compatibility/','/docs-cn/dev/reference/mysql-comp
* `CHECKSUM TABLE` 语法 [#1895](https://github.com/pingcap/tidb/issues/1895)
* `REPAIR TABLE` 语法
* `OPTIMIZE TABLE` 语法
* `GET_LOCK``RELEASE_LOCK` 函数 [#14994](https://github.com/pingcap/tidb/issues/14994)
* `HANDLER` 语句
* `CREATE TABLESPACE` 语句

Expand Down
1 change: 0 additions & 1 deletion system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ MPP 是 TiFlash 引擎提供的分布式计算框架,允许节点之间的数
- 默认值:`OFF`
- 默认情况下,用户尝试将某些语法用于尚未实现的功能时,TiDB 会报错。若将该变量值设为 `ON`,TiDB 则自动忽略此类功能不可用的情况,即不会报错。若用户无法更改 SQL 代码,可考虑将变量值设为 `ON`
- 启用 `noop` 函数可以控制以下行为:
* `get_lock``release_lock` 函数
* `LOCK IN SHARE MODE` 语法
* `SQL_CALC_FOUND_ROWS` 语法
* `START TRANSACTION READ ONLY``SET TRANSACTION READ ONLY` 语法
Expand Down

0 comments on commit c0b51cc

Please sign in to comment.