From 25d51af96d6ca0c0bbe5467695f3fd8b792dd25a Mon Sep 17 00:00:00 2001 From: D3Hunter Date: Tue, 22 Sep 2026 16:07:01 +0800 Subject: [PATCH] import into: document asynchronous preparation on TiDB X --- sql-statements/sql-statement-import-into.md | 23 +++++++++++++++++++ .../sql-statement-show-import-job.md | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/sql-statements/sql-statement-import-into.md b/sql-statements/sql-statement-import-into.md index da4ed9a2afc97..00e4e49f08dcd 100644 --- a/sql-statements/sql-statement-import-into.md +++ b/sql-statements/sql-statement-import-into.md @@ -227,6 +227,29 @@ SET GLOBAL tidb_server_memory_limit='75%'; > - If the KV range overlap in a source data file is low, enabling Global Sort might decrease import performance. This is because when Global Sort is enabled, TiDB needs to wait for the completion of local sorting in all sub-jobs before proceeding with the Global Sort operations and subsequent import. > - After an import job using Global Sort completes, the files stored in the cloud storage for Global Sort are cleaned up asynchronously in a background thread. +### Asynchronous preparation + + + +On TiDB X instances, `IMPORT INTO ... FROM FILE` uses [Global Sort](#global-sort). TiDB creates the import job first and then prepares it asynchronously in the background. The preparation work includes: + +- Listing the source files that match `fileLocation`. +- Detecting the file format when the `FORMAT` clause is omitted. +- Calculating resource-related parameters, such as the import concurrency. +- Splitting the source files into chunks for parallel processing. + +Before the preparation finishes, the job is in the `preparing` phase. Because the source files have not been listed yet, the `Source_File_Size` field in [`SHOW IMPORT JOB(s)`](/sql-statements/sql-statement-show-import-job.md) is `N/A` until the preparation succeeds. + +If you execute `IMPORT INTO ... FROM FILE` with the `DETACHED` option, the statement returns immediately after the import job is created. You can then use [`SHOW IMPORT JOB(s)`](/sql-statements/sql-statement-show-import-job.md) to check whether the preparation is still running. + +> **Note:** +> +> The preparation time grows with the number and size of the source files. For a large single-table import, such as an import of tens of TiB, the `preparing` phase can take a noticeable amount of time even when you execute the statement with the `DETACHED` option, and the import job does not import any data during this period. Before you take any action on the job, such as canceling it, check the job phase with [`SHOW IMPORT JOB(s)`](/sql-statements/sql-statement-show-import-job.md). + +For {{{ .starter }}} instances, TiDB prepares the import job synchronously, so the `preparing` phase is not shown in [`SHOW IMPORT JOB(s)`](/sql-statements/sql-statement-show-import-job.md). + + + ### Output When `IMPORT INTO ... FROM FILE` completes the import or when the `DETACHED` mode is enabled, TiDB returns the current job information in the output, as shown in the following examples. For the description of each field, see [`SHOW IMPORT JOB(s)`](/sql-statements/sql-statement-show-import-job.md). diff --git a/sql-statements/sql-statement-show-import-job.md b/sql-statements/sql-statement-show-import-job.md index 396f60558a137..8df0ed3eea1e7 100644 --- a/sql-statements/sql-statement-show-import-job.md +++ b/sql-statements/sql-statement-show-import-job.md @@ -29,9 +29,9 @@ The output fields of the `SHOW IMPORT` statement are described as follows: | Job_ID | The ID of the task | | Data_Source | Information about the data source | | Target_Table | The name of the target table | -| Phase | The current phase of the job, including `importing`, `validating`, and `add-index` | +| Phase | The current phase of the job, including `preparing`, `global-sorting`, `importing`, `resolving-conflicts`, and `validating` | | Status | The current status of the job, including `pending` (means created but not started yet), `running`, `canceled`, `failed`, and `finished` | -| Source_File_Size | The size of the source file | +| Source_File_Size | The total size of the source files. If the source files have not been listed yet, this column is `N/A`, which can happen while an import job on a TiDB X instance is waiting for or running the [asynchronous preparation](/sql-statements/sql-statement-import-into.md#asynchronous-preparation) | | Imported_Rows | The number of data rows that have been read and written to the target table | | Result_Message | If the import fails, this field returns the error message. Otherwise, it is empty.| | Create_Time | The time when the task is created |