You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: configure-memory-usage.md
+4
Original file line number
Diff line number
Diff line change
@@ -130,6 +130,10 @@ The following example constructs a memory-intensive SQL statement that triggers
130
130
131
131
5. By checking the directory of status files (In the preceding example, the directory is `/tiup/deploy/tidb-4000/log/oom_record`), you can see a record directory with the corresponding timestamp (for example, `record2022-10-09T17:18:38+08:00`). The record directory includes three files: `goroutinue`, `heap`, and`running_sql`. These three files are suffixed with the time when status files are logged. They respectively record goroutine stack information, the usage status of heap memory, and the running SQL information when the alarm is triggered. For the content in`running_sql`, refer to [`expensive-queries`](/identify-expensive-queries.md).
132
132
133
+
## Reduce the memory usage for write transactions in tidb-server
134
+
135
+
The transaction model used by TiDB requires that all write operations of transactions are first cached in memory before being committed. When TiDB writes large transactions, memory usage might increase and become a bottleneck. To reduce or avoid high memory usage by large transactions under various constraints, you can adjust the [`tidb_dml_type`](/system-variables.md#tidb_dml_type-new-in-v800) system variable to `"bulk"` or use [Non-transactional DML statements](/non-transactional-dml.md).
Copy file name to clipboardExpand all lines: system-variables.md
+25
Original file line number
Diff line number
Diff line change
@@ -1806,6 +1806,31 @@ mysql> SELECT job_info FROM mysql.analyze_jobs ORDER BY end_time DESC LIMIT 1;
1806
1806
>
1807
1807
> Starting fromv7.0.0, `tidb_dml_batch_size` no longer takes effect on the [`LOAD DATA` statement](/sql-statements/sql-statement-load-data.md).
1808
1808
1809
+
### tidb_dml_type <span class="version-mark">New in v8.0.0</span>
1810
+
1811
+
>**Warning:**
1812
+
>
1813
+
> The bulk DML execution mode (`tidb_dml_type = "bulk"`) is an experimental feature. It is not recommended that you use it in the production environment. This feature might be changed or removed without prior notice. If you find a bug, you can report an [issue](https://github.com/pingcap/tidb/issues). When TiDB performs large transactions using the bulk DML mode, it might affect the memory usage and execution efficiency of TiCDC, TiFlash, and the resolved-ts module of TiKV, and might cause OOM issues. Therefore, it is not recommended to use this mode when these components or features are enabled.
1814
+
1815
+
- Scope: SESSION
1816
+
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): Yes
1817
+
- Type: String
1818
+
- Default value: `"standard"`
1819
+
- Value options: `"standard"`, `"bulk"`
1820
+
- This variable controls the execution mode of DML statements.
1821
+
-`"standard"` indicates the standard DML execution mode, where TiDB transactions are cached in memory before being committed. This mode is suitable for high-concurrency transaction scenarios with potential conflicts and is the default recommended execution mode.
1822
+
-`"bulk"` indicates the bulk DML execution mode, which is suitable for scenarios where a large amount of data is written, causing excessive memory usage in TiDB.
1823
+
- During the execution of TiDB transactions, the data is not fully cached in the TiDB memory, but is continuously written to TiKV to reduce memory usage and smooth the write pressure.
1824
+
- Only `INSERT`, `UPDATE`, `REPLACE`, and`DELETE` statements are affected by the `"bulk"` mode.
1825
+
-`"bulk"` mode is only suitable for scenarios where a large amount of **data is written without conflicts**. This mode is not efficient for handling write conflicts, as write-write conflicts might cause large transactions to fail and be rolled back.
1826
+
-`"bulk"` mode only takes effect on statements with auto-commit enabled, and requires the [`pessimistic-auto-commit`](https://docs.pingcap.com/tidb/stable/tidb-configuration-file#pessimistic-auto-commit-new-in-v600) configuration item to be set to `false`.
1827
+
- When using the `"bulk"` mode to execute statements, ensure that the [metadata lock](/metadata-lock.md) remains enabled during the execution process.
1828
+
-`"bulk"` mode cannot be used on [temporary tables](/temporary-tables.md) and [cached tables](/cached-tables.md).
1829
+
-`"bulk"` mode cannot be used on tables containing foreign keys and tables referenced by foreign keys when the foreign keyconstraintcheck is enabled (`foreign_key_checks = ON`).
1830
+
-In situations that the environment does not support or is incompatible with the `"bulk"` mode, TiDB falls back to the `"standard"` mode and returns a warning message. To verify if the `"bulk"` mode is used, you can check the `pipelined` field using [`tidb_last_txn_info`](#tidb_last_txn_info-new-in-v409). A `true` value indicates that the `"bulk"` mode is used.
1831
+
- When executing large transactions in the `"bulk"` mode, the transaction duration might be long. For transactions in this mode, the maximum TTL of the transaction lock is the greater value between [`max-txn-ttl`](https://docs.pingcap.com/tidb/stable/tidb-configuration-file#max-txn-ttl) and 24 hours. Additionally, if the transaction execution time exceeds the value set by [`tidb_gc_max_wait_time`](#tidb_gc_max_wait_time-new-in-v610), the GC might force a rollback of the transaction, leading to its failure.
1832
+
- This mode is implemented by the Pipelined DML feature. For detailed design and GitHub issues, see [Pipelined DML](https://github.com/pingcap/tidb/blob/master/docs/design/2024-01-09-pipelined-DML.md) and [#50215](https://github.com/pingcap/tidb/issues/50215).
1833
+
1809
1834
### tidb_enable_1pc <span class="version-mark">New in v5.0</span>
Copy file name to clipboardExpand all lines: tidb-configuration-file.md
+2
Original file line number
Diff line number
Diff line change
@@ -488,6 +488,7 @@ Configuration items related to performance.
488
488
- Default value: `3600000`
489
489
- Unit: Millisecond
490
490
- The transaction that holds locks longer than this time can only be committed or rolled back. The commit might not be successful.
491
+
- For transactions executed using the [`"bulk"` DML mode](/system-variables.md#tidb_dml_type-new-in-v800), the maximum TTL can exceed the limit of this configuration item. The maximum value is the greater value between this configuration item and 24 hours.
491
492
492
493
### `stmt-count-limit`
493
494
@@ -841,6 +842,7 @@ For pessimistic transaction usage, refer to [TiDB Pessimistic Transaction Mode](
841
842
+ Determines the transaction mode that the auto-commit transaction uses when the pessimistic transaction mode is globally enabled (`tidb_txn_mode='pessimistic'`). By default, even if the pessimistic transaction mode is globally enabled, the auto-commit transaction still uses the optimistic transaction mode. After enabling `pessimistic-auto-commit` (set to `true`), the auto-commit transaction also uses pessimistic mode, which is consistent with the other explicitly committed pessimistic transactions.
842
843
+ For scenarios with conflicts, after enabling this configuration, TiDB includes auto-commit transactions into the global lock-waiting management, which avoids deadlocks and mitigates the latency spike brought by deadlock-causing conflicts.
843
844
+ For scenarios with no conflicts, if there are many auto-commit transactions (the specific number is determined by the real scenarios. For example, the number of auto-commit transactions accounts for more than half of the total number of applications), and a single transaction operates a large data volume, enabling this configuration causes performance regression. For example, the auto-commit `INSERT INTO SELECT` statement.
845
+
+ When the session-level system variable [`tidb_dml_type`](/system-variables.md#tidb_dml_type-new-in-v800) is set to `"bulk"`, the effect of this configuration in the session is equivalent to setting it to `false`.
844
846
+ Default value: `false`
845
847
846
848
### constraint-check-in-place-pessimistic <spanclass="version-mark">New in v6.4.0</span>
0 commit comments