|
| 1 | +--- |
| 2 | +title: TiDB Accelerated Table Creation |
| 3 | +summary: Learn the concept, principles, and implementation details of performance optimization for creating tables in TiDB. |
| 4 | +aliases: ['/tidb/dev/ddl-v2/'] |
| 5 | +--- |
| 6 | + |
| 7 | +# TiDB Accelerated Table Creation |
| 8 | + |
| 9 | +TiDB v7.6.0 introduces the system variable [`tidb_ddl_version`](https://docs.pingcap.com/tidb/v7.6/system-variables#tidb_enable_fast_create_table-new-in-v800) to support accelerating table creation, which improves the efficiency of bulk table creation. Starting from v8.0.0, this system variable is renamed to [`tidb_enable_fast_create_table`](/system-variables.md#tidb_enable_fast_create_table-new-in-v800). |
| 10 | + |
| 11 | +TiDB uses the online asynchronous schema change algorithm to change the metadata. All DDL jobs are submitted to the `mysql.tidb_ddl_job` table, and the owner node pulls the DDL job to execute. After executing each phase of the online DDL algorithm, the DDL job is marked as completed and moved to the `mysql.tidb_ddl_history` table. Therefore, DDL statements can only be executed on the owner node and cannot be linearly extended. |
| 12 | + |
| 13 | +However, for some DDL statements, it is not necessary to strictly follow the online DDL algorithm. For example, the `CREATE TABLE` statement only has two states for the job: `none` and `public`. Therefore, TiDB can simplify the execution process of DDL, and executes the `CREATE TABLE` statement on a non-owner node to accelerate table creation. |
| 14 | + |
| 15 | +> **Warning:** |
| 16 | +> |
| 17 | +> This feature is currently an experimental feature and it is not recommended to use in a production environment. This feature might change or be removed without prior notice. If you find a bug, please give feedback by raising an [issue](https://github.com/pingcap/tidb/issues) on GitHub. |
| 18 | +
|
| 19 | +## Compatibility with TiDB tools |
| 20 | + |
| 21 | +- [TiCDC](https://docs.pingcap.com/tidb/stable/ticdc-overview) does not support replicating the tables that are created by `tidb_enable_fast_create_table`. |
| 22 | + |
| 23 | +## Limitation |
| 24 | + |
| 25 | +You can now use performance optimization for table creation only in the [`CREATE TABLE`](/sql-statements/sql-statement-create-table.md) statement, and this statement must not include any foreign key constraints. |
| 26 | + |
| 27 | +## Use `tidb_enable_fast_create_table` to accelerate table creation |
| 28 | + |
| 29 | +You can enable or disable performance optimization for creating tables by specifying the value of the system variable [`tidb_enable_fast_create_table`](/system-variables.md#tidb_enable_fast_create_table-new-in-v800). |
| 30 | + |
| 31 | +To enable performance optimization for creating tables, set the value of this variable to `ON`: |
| 32 | + |
| 33 | +```sql |
| 34 | +SET GLOBAL tidb_enable_fast_create_table = ON; |
| 35 | +``` |
| 36 | + |
| 37 | +To disable performance optimization for creating tables, set the value of this variable to `OFF`: |
| 38 | + |
| 39 | +```sql |
| 40 | +SET GLOBAL tidb_enable_fast_create_table = OFF; |
| 41 | +``` |
| 42 | + |
| 43 | +## Implementation principle |
| 44 | + |
| 45 | +The detailed implementation principle of performance optimization for table creation is as follows: |
| 46 | + |
| 47 | +1. Create a `CREATE TABLE` Job. |
| 48 | + |
| 49 | + The corresponding DDL Job is generated by parsing the `CREATE TABLE` statement. |
| 50 | + |
| 51 | +2. Execute the `CREATE TABLE` job. |
| 52 | + |
| 53 | + The TiDB node that receives the `CREATE TABLE` statement executes it directly, and then persists the table structure to TiKV. At the same time, the `CREATE TABLE` job is marked as completed and inserted into the `mysql.tidb_ddl_history` table. |
| 54 | + |
| 55 | +3. Synchronize the table information. |
| 56 | + |
| 57 | + TiDB notifies other nodes to synchronize the newly created table structure. |
0 commit comments