Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys var: add tidb_enable_shared_lock_upgrade #18447

Merged
merged 13 commits into from
Aug 15, 2024
6 changes: 5 additions & 1 deletion pessimistic-transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ Pessimistic transactions in TiDB behave similarly to those in MySQL. See the min

2. TiDB does not support `SELECT LOCK IN SHARE MODE`.

When `SELECT LOCK IN SHARE MODE` is executed, it has the same effect as that without the lock, so the read or write operation of other transactions is not blocked.
TiDB does not support `SELECT LOCK IN SHARE MODE` by default.

You can enable [`tidb_enable_noop_functions`](/system-variables.md#tidb_enable_noop_functions-new-in-v40) to be compatible with the `SELECT LOCK IN SHARE MODE` statement. The effect of the statement is the same as when there is no lock, and it will not block the read and write operations of other transactions.
hfxsd marked this conversation as resolved.
Show resolved Hide resolved

Starting from v8.3.0, TiDB supports using the [`tidb_enable_shared_lock_upgrade`](/system-variables.md#tidb_enable_shared_lock_upgrade-new-in-v830) system variable to enable the `SELECT LOCK IN SHARE MODE` statement to add locks. However, note that the lock added at this time is not a true shared lock, but consistent with `SELECT FOR UPDATE`, which actually adds an exclusive lock. You can enable this variable when you want to be compatible with the `SELECT LOCK IN SHARE MODE` syntax while blocking writes to prevent data from being modified by parallel write transactions during reads. This variable takes effect regardless of the configuration of [`tidb_enable_noop_functions`](/system-variables.md#tidb_enable_noop_functions-new-in-v40).
hfxsd marked this conversation as resolved.
Show resolved Hide resolved

3. DDL may result in failure of the pessimistic transaction commit.

Expand Down
10 changes: 10 additions & 0 deletions system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -2567,6 +2567,16 @@ mysql> SELECT job_info FROM mysql.analyze_jobs ORDER BY end_time DESC LIMIT 1;
- Value options: `OFF`, `ON`
- This variable controls whether TiDB enables chunk objects cache. If the value is `ON`, TiDB prefers to use the cached chunk object and only requests from the system if the requested object is not in the cache. If the value is `OFF`, TiDB requests chunk objects from the system directly.

### tidb_enable_shared_lock_upgrade <span class="version-mark">New in v8.3.0</span>
hfxsd marked this conversation as resolved.
Show resolved Hide resolved

- Scope: SESSION | GLOBAL
- Persists to cluster: Yes
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
- Type: Boolean
- Default value: `OFF`
- This variable controls whether to enable the function of upgrading shared locks to exclusive locks. TiDB does not support `SELECT LOCK IN SHARE MODE` by default. When the variable value is `ON`, TiDB will try to upgrade the `SELECT LOCK IN SHARE MODE` statement to `SELECT FOR UPDATE` and add a pessimistic lock. The default value of this variable is `OFF`, which means that the function of upgrading shared locks to exclusive locks is disabled.
- This variable takes effect on the `SELECT LOCK IN SHARE MODE` statement regardless of the configuration of [`tidb_enable_noop_functions`](/system-variables.md#tidb_enable_noop_functions-new-in-v40).

### tidb_enable_slow_log

> **Note:**
Expand Down
Loading