Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Merge Risk:
|
| | 'INVISIBLE' | ||
| | 'GLOBAL' | ||
| | 'LOCAL' | ||
| | 'PRE_SPLIT_REGIONS' '='? 'AUTO' |
There was a problem hiding this comment.
Should not the other, manual, options be listed as well? = N, = (BETWEEN ... AND ... REGIONS n) and = (BY ...)
| ```sql | ||
| SET SESSION tidb_analyze_version = 2; | ||
| ANALYZE TABLE t COLUMNS a; | ||
| ALTER TABLE t ADD INDEX idx_a (a) PRE_SPLIT_REGIONS AUTO; | ||
| ``` |
There was a problem hiding this comment.
Please don't recommend ANALYZE TABLE t COLUMNS a. With the default tidb_persist_analyze_options = ON the column list is persisted, so later ANALYZE TABLE t and auto analyze only refresh a (plus indexed columns). The other columns' statistics go stale while SHOW STATS_HEALTHY still shows 100.
Suggest: check SHOW STATS_HEALTHY, and run ANALYZE TABLE t if needed.
SET SESSION tidb_analyze_version = 2 can go, it is the default, and since v9.0.0, setting it to 1 returns an error.
|
|
||
| Automatic pre-splitting is best-effort. If loading or decoding any part of the complete leading-column distribution fails, TiDB skips `AUTO` for that index instead of using partial statistics. Planning, split, scatter, or timeout failures do not cancel index creation. DDL pause and cancellation requests still take effect. Successful index creation does not guarantee that any Regions were pre-split. | ||
|
|
||
| To check the outcome, inspect the TiDB server log for `skip auto presplit index region`, `auto presplit index region failed, continue add-index`, or `split table index region finished`. The log entries include the table and index names and, depending on the outcome, a skip reason, an error, or split and scatter counts. These decisions and outcomes are not recorded in [`ADMIN SHOW DDL JOBS`](/sql-statements/sql-statement-admin-show-ddl.md). |
There was a problem hiding this comment.
The DDL owner's server log is the only way to tell whether AUTO did anything: a skipped AUTO gives no warning and nothing in ADMIN SHOW DDL JOBS. tidb already reports other DDL outcomes to the user: job warnings become statement warnings, and ADMIN SHOW DDL JOBS shows analyze_failed in COMMENTS.
Can that be a tidb follow-up, with the docs pointing to SHOW WARNINGS? I think it is much more user friendly to either return a warning or note on the DDL comand, or even visible in the ADMIN SHOW DDL JOBS (or an information_schema table) than having to find the right node and dig into its logs.
There was a problem hiding this comment.
This was included in an earlier version of the PR, but removed after review: result persistence and DDL job output. We also discussed SQL warnings and kept owner logs, since a skipped or failed pre-split does not mean index creation failed.
I’ll document the current behavior. We can revisit SQL visibility in a separate discussion.
| * It is not supported to modify multiple TiDB-specific schema objects using a single `ALTER TABLE` statement, such as `TIFLASH REPLICA`, `SHARD_ROW_ID_BITS`, and `AUTO_ID_CACHE`. | ||
| * TiDB does not support the changes of some data types using `ALTER TABLE`. For example, TiDB does not support the change from the `DECIMAL` type to the `DATE` type. If a data type change is unsupported, TiDB reports the `Unsupported modify column: type %d not match origin %d` error. Refer to [`ALTER TABLE`](/sql-statements/sql-statement-modify-column.md) for more details. | ||
| * The `ALGORITHM={INSTANT,INPLACE,COPY}` syntax functions only as an assertion in TiDB, and does not modify the `ALTER` algorithm. See [`ALTER TABLE`](/sql-statements/sql-statement-alter-table.md) for further details. | ||
| * The per-index [`PRE_SPLIT_REGIONS AUTO`](/sql-statements/sql-statement-add-index.md#automatic-region-pre-splitting) option is a TiDB extension and is not compatible with MySQL. |
There was a problem hiding this comment.
This section lists restrictions, not TiDB extensions (AUTO_RANDOM, global and partial indexes are not listed). Suggest dropping it.
| SET SESSION tidb_analyze_version = 2; | ||
| ANALYZE TABLE t COLUMNS a; |
There was a problem hiding this comment.
See note above regarding tidb_analyze_version and ANALYZE TABLE t COLUMNS a.
| - The table is partitioned, or the index is a partial index. | ||
| - The leading index column is a string column with an index prefix, such as `INDEX idx (a(10))`. | ||
| - The table has fewer than 1,000,000 rows according to statistics, or its [statistics health score](/statistics.md#health-state-of-tables) is unavailable or below 80. You can use [`SHOW STATS_HEALTHY`](/sql-statements/sql-statement-show-stats-healthy.md) to check the health score. | ||
| - The leading index column does not have usable [Version 2 statistics](/statistics.md#versions-of-statistics). Missing, pseudo, or outdated statistics cannot provide reliable split boundaries. If needed, run `ANALYZE TABLE ... COLUMNS ...` to refresh the statistics before adding the index. |
There was a problem hiding this comment.
Just mention ANALYZE TABLE, don't say ANALYZE TABLE ... COLUMNS ... since that may have side effects. And ANALYZE TABLE is a good enough reference. Also see above.
|
|
||
| ### Split behavior | ||
|
|
||
| TiDB combines NULL counts, Top-N value counts, and histogram bucket counts from the leading column statistics into an ordered distribution. It selects split boundaries at fixed 2% cumulative intervals, producing at most 49 distribution-derived boundaries per index. Repeated values contribute at most one boundary, so the actual number can be smaller. TiDB also adds index keyspace boundaries as needed. |
There was a problem hiding this comment.
What does 'TiDB also adds index keyspace boundaries as needed' mean?
I assume it means that the start and end temporary index key boundary are added? And I wonder if the start key can be skipped in some cases? I don't think it should ever be skipped (code issue, not documentation related), since otherwise the first temporary index region will be shared with another, non-temporary index region.
There was a problem hiding this comment.
This refers to the index start and end keys. The existing manual split logic skips the start key for the table’s first index to avoid an empty Region. AUTO reuses this rule before converting keys to temporary index keys, so a shared Region is possible.
I’ll remove the vague sentence from the docs.
| CREATE INDEX idx_a ON t (a) PRE_SPLIT_REGIONS AUTO; | ||
| ``` | ||
|
|
||
| This option is experimental and disabled unless explicitly specified for the index. It is best-effort: TiDB can skip pre-splitting and continue creating the index if the statistics are ineligible or if pre-splitting fails. For requirements, limitations, backfilling modes, and log messages, see [Automatic Region pre-splitting](/sql-statements/sql-statement-add-index.md#automatic-region-pre-splitting). |
There was a problem hiding this comment.
Is it actually experimental? Or just disabled by default?
| Query OK, 0 rows affected (0.09 sec) | ||
| ``` | ||
|
|
||
| Starting from v9.0.0, `AUTO` is a non-reserved keyword used by [`PRE_SPLIT_REGIONS AUTO`](/sql-statements/sql-statement-add-index.md#automatic-region-pre-splitting). You can still use it without backticks as a table, column, index, or alias name. For a role named `auto`, use backticks, for example, ``CREATE ROLE `auto`;`` and ``SET ROLE `auto`;``. SQL normalization treats unquoted `AUTO` as a keyword, so the normalized SQL text and SQL digest of statements that use an unquoted `auto` identifier change after upgrading. |
There was a problem hiding this comment.
I don't think this is needed here? It should be enough in the release notes and in the list below.
| | 'COMMENT' stringLit | ||
| | ("VISIBLE" | "INVISIBLE") | ||
| | ("GLOBAL" | "LOCAL") | ||
| | 'PRE_SPLIT_REGIONS' '='? 'AUTO' |
There was a problem hiding this comment.
See above for also covering existing options.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Minor · Cover all index-level PRE_SPLIT_REGIONS forms in the MySQL… · sql-statement-add-index.md:314
sql-statements/sql-statement-add-index.md:314
Minor · Functional Correctness · Quick win Cover all index-level
PRE_SPLIT_REGIONSforms in the MySQL compatibility note.The manual forms added above are not part of MySQL's
CREATE INDEXindex-option grammar. Limiting this bullet toPRE_SPLIT_REGIONS AUTOimplies that theN,BETWEEN, andBYforms are portable. Apply the same wording to the correspondingCREATE INDEXnote. (dev.mysql.com)* The index-level `PRE_SPLIT_REGIONS` option, including `AUTO`, is a TiDB extension and is not compatible with MySQL.Source: Path instructions

Review info
-
Run configuration-
- Source mode: Auto
- Repository: pingcap/docs
- Branch: master
- File: .coderabbit.yaml
- Commit: e5e80ae
- Layers: Repository YAML
- Review profile: ASSERTIVE
- Plan: Advanced
- Run ID:
9ab4dd5c-29f1-4ab1-8a21-55b6b0e86daa
Files selected for processing: 3-
keywords.mdsql-statements/sql-statement-add-index.mdsql-statements/sql-statement-create-index.md
Files with no reviewable changes: 1-
- keywords.md
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
-
D3Hunter
left a comment
There was a problem hiding this comment.
AI-assisted review by Codex of b97dd68c922c5b6edeb1bc077250aefb9d1661f3. One statistics-preparation issue is noted inline. Reviewed all four changed documents against the linked TiDB implementation and existing review discussion; all 13 added internal link targets and anchors resolve at this head. Static review only; no TiDB runtime tests were run. TiDB X rollout timing was not independently verified. Please manually confirm the proposed documentation change before applying it.
| - The table is partitioned, or the index is a partial index. | ||
| - The leading index column is a string column with an index prefix, such as `INDEX idx (a(10))`. | ||
| - The table has fewer than 1,000,000 rows according to statistics, or its [statistics health score](/statistics.md#health-state-of-tables) is unavailable or below 80. You can use [`SHOW STATS_HEALTHY`](/sql-statements/sql-statement-show-stats-healthy.md) to check the health score. | ||
| - The leading index column does not have usable [Version 2 statistics](/statistics.md#versions-of-statistics). Missing, pseudo, or outdated statistics cannot provide reliable split boundaries. If needed, run `ANALYZE TABLE` to refresh the statistics before adding the index. |
There was a problem hiding this comment.
[P2] Check leading-column coverage as well as table statistics health
ANALYZE TABLE t can still omit the leading column: for example, when a persisted COLUMNS b selection excludes the not-yet-indexed a, or when predicate-column collection excludes a. SHOW STATS_HEALTHY is table-level, so a healthy score does not establish that a has usable statistics. The analyze planner reuses the saved column selection, and AUTO skips an unanalyzed leading column. Consequently, the preparation recipes here and in CREATE INDEX can complete successfully while silently skipping the optimization, and repeating the suggested refresh does not resolve it.
Please add the column-coverage prerequisite to both recipes. The limitations bullet can give a conditional recovery while making its persistence effect explicit:
| - The leading index column does not have usable [Version 2 statistics](/statistics.md#versions-of-statistics). Missing, pseudo, or outdated statistics cannot provide reliable split boundaries. If needed, run `ANALYZE TABLE` to refresh the statistics before adding the index. | |
| - The leading index column does not have usable [Version 2 statistics](/statistics.md#versions-of-statistics). Missing, pseudo, or outdated statistics cannot provide reliable split boundaries. Before adding the index, ensure that statistics collection includes the leading column. `ANALYZE TABLE` can omit this column if it reuses a persisted column selection or collects only predicate columns. If needed, use `ANALYZE TABLE t ALL COLUMNS` to collect statistics for all columns. When `tidb_persist_analyze_options` is `ON`, this also persists `ALL COLUMNS` for subsequent analysis. |
There was a problem hiding this comment.
Fixed in 1f8f47694. Both the ADD INDEX and CREATE INDEX recipes now explicitly require usable Version 2 statistics for the leading index column and use ANALYZE TABLE t ALL COLUMNS when collection or refresh is needed. The limitations section explains how persisted column selections or predicate-column collection can omit the leading column, and that ALL COLUMNS is persisted for subsequent analysis when tidb_persist_analyze_options is ON.
|
|
||
| ## Automatic Region pre-splitting | ||
|
|
||
| <span class="version-mark">New in v9.0.0 for classic TiDB and in CLOUD.202609 for TiDB X</span> |
There was a problem hiding this comment.
since we have picked to 8.5.9, should also include it
There was a problem hiding this comment.
Fixed: both the ADD INDEX and CREATE INDEX introduction markers now include v8.5.9. The PR also now selects v8.5 in the affected-version checkboxes and has the needs-cherry-pick-release-8.5 label for the documentation backport.
| Query OK, 0 rows affected (0.31 sec) | ||
| ``` | ||
|
|
||
| ## Manual Region pre-splitting |
There was a problem hiding this comment.
since this part shares the same as the add index doc, can we ref to it directly, instead of dup it
There was a problem hiding this comment.
Fixed: the manual Region pre-splitting section in CREATE INDEX now links directly to the corresponding ADD INDEX section. I also removed the duplicated AUTO backfill-mode explanations, keeping the CREATE INDEX usage example and the link to the canonical ADD INDEX explanation.
wjhuang2016
left a comment
There was a problem hiding this comment.
Not approving yet:
-
The statistics recipes need to require coverage of the leading index column, not only table-level health. A plain
ANALYZE TABLE tcan reuse a persisted column selection or predicate-column selection that omits the not-yet-indexed leading column, whileAUTOexplicitly skips that column when its statistics are missing (index_auto_presplit.gocheckshasAnalyzedand returnsleading column stats missing or not analyzed). As written, both recipes can report healthy table statistics, complete successfully, and silently skip the optimization. Please incorporate the column-coverage prerequisite and recovery wording from the open thread. -
The feature was cherry-picked and merged into
release-8.5by pingcap/tidb#73106 on 2026-11-18, but this PR is marked master-only and uses only a v9.0.0 introduction. It needs the applicable v8.5 version/checkbox treatment (and branch-specific wording/cherry-pick if introduction versions differ), otherwise the released 8.5 docs will not document the feature.
Non-blocking: the duplicated AUTO behavior in CREATE INDEX can drift from ADD INDEX; linking to the canonical section, as suggested in the open thread, would be easier to maintain.
wjhuang2016
left a comment
There was a problem hiding this comment.
Thanks. The prior blockers are resolved:
- Both preparation recipes now require usable Version 2 statistics for the leading index column and recommend
ANALYZE TABLE ... ALL COLUMNS; the limitations also explain why a persisted or predicate-column selection can omit that column. - The docs now include the v8.5.9 introduction, select v8.5 in the PR description, and carry the release-8.5 cherry-pick label, matching the merged release-8.5 backport.
CREATE INDEXnow delegates the duplicated behavior details to the canonicalADD INDEXsection.
The current documentation checks pass, and I found no new blocking issues in the complete diff.
|
@wjhuang2016: adding LGTM is restricted to approvers and reviewers in OWNERS files. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
| * Descending indexes are not supported (similar to MySQL 5.7). | ||
| * Adding the primary key of the `CLUSTERED` type to a table is not supported. For more details about the primary key of the `CLUSTERED` type, refer to [clustered index](/clustered-indexes.md). | ||
| * Setting a `PRIMARY KEY` or `UNIQUE INDEX` as a [global index](/global-indexes.md) with the `GLOBAL` index option is a TiDB extension for [partitioned tables](/partitioned-table.md) and is not compatible with MySQL. | ||
| * `PRE_SPLIT_REGIONS AUTO` is a TiDB extension and is not compatible with MySQL. |
There was a problem hiding this comment.
| * `PRE_SPLIT_REGIONS AUTO` is a TiDB extension and is not compatible with MySQL. | |
| * The index-level `PRE_SPLIT_REGIONS` option, including `AUTO`, is a TiDB extension and is not compatible with MySQL. |
Reason: The manual forms (N, BETWEEN, and BY) are also TiDB-specific, so this note should cover the whole index option.
| * Expression indexes have compatibility issues with bindings. When the expression of an expression index has a constant, the binding created for the corresponding query expands its scope. For example, suppose that the expression in the expression index is `a+1`, and the corresponding query condition is `a+1 > 2`. In this case, the created binding is `a+? > ?`, which means that the query with the condition such as `a+2 > 2` is also forced to use the expression index and results in a poor execution plan. In addition, this also affects the baseline capturing and baseline evolution in SQL Plan Management (SPM). | ||
| * The data written with multi-valued indexes must exactly match the defined data type. Otherwise, data writes fail. For details, see [create multi-valued indexes](/sql-statements/sql-statement-create-index.md#create-multi-valued-indexes). | ||
| * Setting a `UNIQUE KEY` as a [global index](/global-indexes.md) with the `GLOBAL` index option is a TiDB extension for [partitioned tables](/partitioned-table.md) and is not compatible with MySQL. | ||
| * `PRE_SPLIT_REGIONS AUTO` is a TiDB extension and is not compatible with MySQL. |
There was a problem hiding this comment.
| * `PRE_SPLIT_REGIONS AUTO` is a TiDB extension and is not compatible with MySQL. | |
| * The index-level `PRE_SPLIT_REGIONS` option, including `AUTO`, is a TiDB extension and is not compatible with MySQL. |
Reason: The manual forms (N, BETWEEN, and BY) are also TiDB-specific, so this note should cover the whole index option.
|
|
||
| ## Automatic Region pre-splitting | ||
|
|
||
| <span class="version-mark">New in v8.5.9 and v9.0.0 for classic TiDB and in CLOUD.202609 for TiDB X</span> |
There was a problem hiding this comment.
| <span class="version-mark">New in v8.5.9 and v9.0.0 for classic TiDB and in CLOUD.202609 for TiDB X</span> | |
| <span class="version-mark">New in v8.5.9 and v9.0.0 for TiDB Self-Managed and TiDB Cloud Dedicated, and in CLOUD.202609.1 for TiDB Cloud Essential and Premium<</span> |
| - When [`tidb_ddl_enable_fast_reorg`](/system-variables.md#tidb_ddl_enable_fast_reorg-new-in-v630) is `ON`, TiDB uses the `ingest` or `txn-merge` backfill mode. In these modes, `AUTO` pre-splits temporary index Regions used by concurrent DML. It does not additionally pre-split the normal index Regions used to build the index from existing table data. | ||
| - When `tidb_ddl_enable_fast_reorg` is `OFF`, TiDB uses the `txn` backfill mode. In this mode, `AUTO` pre-splits the normal index Regions used to build the index from existing table data. |
There was a problem hiding this comment.
| - When [`tidb_ddl_enable_fast_reorg`](/system-variables.md#tidb_ddl_enable_fast_reorg-new-in-v630) is `ON`, TiDB uses the `ingest` or `txn-merge` backfill mode. In these modes, `AUTO` pre-splits temporary index Regions used by concurrent DML. It does not additionally pre-split the normal index Regions used to build the index from existing table data. | |
| - When `tidb_ddl_enable_fast_reorg` is `OFF`, TiDB uses the `txn` backfill mode. In this mode, `AUTO` pre-splits the normal index Regions used to build the index from existing table data. | |
| - When [`tidb_ddl_enable_fast_reorg`](/system-variables.md#tidb_ddl_enable_fast_reorg-new-in-v630) is `ON`, TiDB uses the `ingest` or `txn-merge` backfill mode. These modes use a temporary index to record concurrent DML changes during index creation, then merge those changes into the normal index. In these modes, `AUTO` pre-splits the Regions of the temporary index. It does not additionally pre-split the Regions of the normal index built from existing table data. | |
| - When `tidb_ddl_enable_fast_reorg` is `OFF`, TiDB uses the `txn` backfill mode. In this mode, `AUTO` pre-splits the normal index Regions used to build the index from existing table data. |
Reason: Briefly explain the temporary index so readers can understand which Regions are split without knowing the backfill internals.
|
|
||
| ## pre_split_regions | ||
|
|
||
| When adding an index to an existing table, you can use `PRE_SPLIT_REGIONS AUTO` to derive index Region split boundaries from existing column statistics. This per-index option differs from the table option described in this section and cannot be used as a `CREATE TABLE` table option. For details, see [Automatic Region pre-splitting](/sql-statements/sql-statement-add-index.md#automatic-region-pre-splitting). |
There was a problem hiding this comment.
| When adding an index to an existing table, you can use `PRE_SPLIT_REGIONS AUTO` to derive index Region split boundaries from existing column statistics. This per-index option differs from the table option described in this section and cannot be used as a `CREATE TABLE` table option. For details, see [Automatic Region pre-splitting](/sql-statements/sql-statement-add-index.md#automatic-region-pre-splitting). | |
| > **Note:** | |
| > | |
| > When adding an index to an existing table, you can use `PRE_SPLIT_REGIONS AUTO` to derive index Region split boundaries from existing column statistics. This per-index option differs from the table option described in this section and cannot be used as a `CREATE TABLE` table option. For more information, see [Automatic Region pre-splitting](/sql-statements/sql-statement-add-index.md#automatic-region-pre-splitting). |
Reason: This section describes the table option. A note separates the index-option cross-reference from the main explanation.
|
|
||
| Each index that specifies `AUTO` is split and scattered separately, even when multiple indexes share the same leading column. With fast reorganization, after garbage collection removes the temporary index data, empty Regions can remain until PD's [`split-merge-interval`](/pd-configuration-file.md#split-merge-interval) has elapsed (one hour by default). Actual merging also depends on PD's normal Region merge conditions. | ||
|
|
||
| All `AUTO` indexes in a DDL job share a time budget of 30 seconds plus [`tidb_wait_split_region_timeout`](/system-variables.md#tidb_wait_split_region_timeout), which defaults to 300 seconds. This budget starts before the first index is processed. Time spent on manual pre-splitting in the same job also consumes this budget. |
There was a problem hiding this comment.
| All `AUTO` indexes in a DDL job share a time budget of 30 seconds plus [`tidb_wait_split_region_timeout`](/system-variables.md#tidb_wait_split_region_timeout), which defaults to 300 seconds. This budget starts before the first index is processed. Time spent on manual pre-splitting in the same job also consumes this budget. | |
| All `AUTO` indexes in a DDL job share a time budget consisting of a fixed 30-second allowance for loading statistics plus [`tidb_wait_split_region_timeout`](/system-variables.md#tidb_wait_split_region_timeout), which defaults to 300 seconds. This budget starts before the first index is processed. Time spent on manual pre-splitting in the same job also consumes this budget. |
Reason: The 30-second allowance is fixed; only the split timeout is configurable.
|
|
||
| Each index that specifies `AUTO` is split and scattered separately, even when multiple indexes share the same leading column. With fast reorganization, after garbage collection removes the temporary index data, empty Regions can remain until PD's [`split-merge-interval`](/pd-configuration-file.md#split-merge-interval) has elapsed (one hour by default). Actual merging also depends on PD's normal Region merge conditions. | ||
|
|
||
| All `AUTO` indexes in a DDL job share a time budget of 30 seconds plus [`tidb_wait_split_region_timeout`](/system-variables.md#tidb_wait_split_region_timeout), which defaults to 300 seconds. This budget starts before the first index is processed. Time spent on manual pre-splitting in the same job also consumes this budget. |
There was a problem hiding this comment.
Could we also update the tidb_wait_split_region_timeout description in system-variables.md to mention its role in the shared AUTO budget? It currently only describes SPLIT REGION, so readers looking up the variable will miss this use.
| 2 rows in set (0.00 sec) | ||
| ``` | ||
|
|
||
| ## Manual Region pre-splitting |
There was a problem hiding this comment.
| ## Manual Region pre-splitting | |
| ### Custom Region pre-splitting |
There was a problem hiding this comment.
Rename Manual Region pre-splitting to Custom Region pre-splitting to avoid confusion. "Manual" could imply that users need to perform the splitting themselves, whereas TiDB actually calculates the split points based on user-specified rules and executes the splitting automatically.
|
|
||
| ## Manual Region pre-splitting | ||
|
|
||
| When adding an index with `ALTER TABLE ... ADD INDEX` or `CREATE INDEX`, you can specify `PRE_SPLIT_REGIONS` to choose split boundaries before index backfilling begins. The following manual forms are supported, and the equals sign (`=`) is optional: |
There was a problem hiding this comment.
| When adding an index with `ALTER TABLE ... ADD INDEX` or `CREATE INDEX`, you can specify `PRE_SPLIT_REGIONS` to choose split boundaries before index backfilling begins. The following manual forms are supported, and the equals sign (`=`) is optional: | |
| When adding an index with `ALTER TABLE ... ADD INDEX` or `CREATE INDEX`, you can use the `PRE_SPLIT_REGIONS` option to specify split boundaries before index backfilling begins. The option supports the following forms, and the equals sign (`=`) is optional: |
| PRE_SPLIT_REGIONS = (BETWEEN (0) AND (1000000) REGIONS 4); | ||
| ``` | ||
|
|
||
| These manual forms use encoded index keys to calculate split points rather than statistics. For more information about range and value-list splitting, see [Split Index Region](/sql-statements/sql-statement-split-region.md#split-index-region). The index option differs from the [`CREATE TABLE` table option](/sql-statements/sql-statement-split-region.md#pre_split_regions), which pre-splits table Regions into `2^N` Regions. |
There was a problem hiding this comment.
| These manual forms use encoded index keys to calculate split points rather than statistics. For more information about range and value-list splitting, see [Split Index Region](/sql-statements/sql-statement-split-region.md#split-index-region). The index option differs from the [`CREATE TABLE` table option](/sql-statements/sql-statement-split-region.md#pre_split_regions), which pre-splits table Regions into `2^N` Regions. | |
| TiDB calculates split points from your specified index values rather than column statistics. For more information about splitting index Regions by range or specific values, see [Split Index Region](/sql-statements/sql-statement-split-region.md#split-index-region). This index option is different from the [`CREATE TABLE` table option](/sql-statements/sql-statement-split-region.md#pre_split_regions), which pre-splits table Regions into `2^N` Regions. |
| - `PRE_SPLIT_REGIONS [=] N`: calculates evenly spaced split points across the index key range for `N` Regions. | ||
| - `PRE_SPLIT_REGIONS [=] (BETWEEN (lower_value) AND (upper_value) REGIONS N)`: calculates evenly spaced split points between the specified lower and upper index values for `N` Regions. | ||
| - `PRE_SPLIT_REGIONS [=] (BY (value_list) [, (value_list)] ...)`: uses the specified index values as split boundaries. |
There was a problem hiding this comment.
| - `PRE_SPLIT_REGIONS [=] N`: calculates evenly spaced split points across the index key range for `N` Regions. | |
| - `PRE_SPLIT_REGIONS [=] (BETWEEN (lower_value) AND (upper_value) REGIONS N)`: calculates evenly spaced split points between the specified lower and upper index values for `N` Regions. | |
| - `PRE_SPLIT_REGIONS [=] (BY (value_list) [, (value_list)] ...)`: uses the specified index values as split boundaries. | |
| - `PRE_SPLIT_REGIONS [=] N`: splits the index key range into `N` Regions by calculating evenly spaced split points. `N` specifies the number of Regions. | |
| - `PRE_SPLIT_REGIONS [=] (BETWEEN (lower_value) AND (upper_value) REGIONS N)`: splits the specified index key range into `N` Regions by calculating evenly spaced split points between the lower and upper index values. | |
| - `PRE_SPLIT_REGIONS [=] (BY (value_list) [, (value_list)] ...)`: uses the specified index values as split boundaries. |
| - `PRE_SPLIT_REGIONS [=] (BETWEEN (lower_value) AND (upper_value) REGIONS N)`: calculates evenly spaced split points between the specified lower and upper index values for `N` Regions. | ||
| - `PRE_SPLIT_REGIONS [=] (BY (value_list) [, (value_list)] ...)`: uses the specified index values as split boundaries. | ||
|
|
||
| For example, to pre-split the index range between `0` and `1000000` when adding `idx_a` to an existing table `t`: |
There was a problem hiding this comment.
| For example, to pre-split the index range between `0` and `1000000` when adding `idx_a` to an existing table `t`: | |
| For example, to pre-split the index range between `0` and `1000000` into 4 Regions when adding `idx_a` to an existing table `t`: |
|
|
||
| When adding an index to a large existing table, you can specify `PRE_SPLIT_REGIONS AUTO` to let TiDB derive Region split boundaries from existing column statistics. This can reduce initial write hotspots without requiring you to choose split boundaries manually. | ||
|
|
||
| The target Regions depend on the index backfilling mode, following the behavior of manual `PRE_SPLIT_REGIONS`: |
There was a problem hiding this comment.
| The target Regions depend on the index backfilling mode, following the behavior of manual `PRE_SPLIT_REGIONS`: | |
| The Regions that TiDB pre-splits depend on the index backfill mode: |
|
|
||
| These manual forms use encoded index keys to calculate split points rather than statistics. For more information about range and value-list splitting, see [Split Index Region](/sql-statements/sql-statement-split-region.md#split-index-region). The index option differs from the [`CREATE TABLE` table option](/sql-statements/sql-statement-split-region.md#pre_split_regions), which pre-splits table Regions into `2^N` Regions. | ||
|
|
||
| ## Automatic Region pre-splitting |
There was a problem hiding this comment.
| ## Automatic Region pre-splitting | |
| ### Automatic Region pre-splitting |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Thanks for the suggestions. I've incorporated the documentation updates in the latest commit, including the structure, terminology, compatibility notes, and shared timeout budget. I still need to confirm whether |
wjhuang2016
left a comment
There was a problem hiding this comment.
The prior leading-column statistics and v8.5 documentation findings remain resolved. Both examples still call out usable Version 2 statistics for the leading column and use ANALYZE TABLE ... ALL COLUMNS when needed. The v8.5.9 markers, affected-version checkbox, and release-8.5 cherry-pick label are in place.
One P2 remains for this revision. The timeout text makes an internal DDL worker setting look like a setting users can tune in the SQL session that submits ADD INDEX or CREATE INDEX. Please update the linked ADD INDEX paragraph at the same time.
The feature is present on release-nextgen-202609. The exact first Cloud patch release still needs confirmation for the CLOUD.202609.1 annotation.
| - Range: `[1, 2147483647]` | ||
| - Unit: Seconds | ||
| - This variable is used to set the timeout for executing the `SPLIT REGION` statement. If a statement is not executed completely within the specified time value, a timeout error is returned. | ||
| - This variable also contributes to the shared time budget for [`PRE_SPLIT_REGIONS AUTO`](/sql-statements/sql-statement-add-index.md#automatic-region-pre-splitting). All `AUTO` indexes in a DDL job share a total budget equal to this variable's value plus a fixed 30-second allowance for loading statistics. Statistics loading, Region splitting, and scattering all consume this budget. |
There was a problem hiding this comment.
[P2] Clarify which session supplies the AUTO timeout. A user can run SET SESSION tidb_wait_split_region_timeout = 1 before ADD INDEX ... PRE_SPLIT_REGIONS AUTO and reasonably expect a 31-second budget from this entry. The value stays in the submitting connection. The job scheduler creates the worker from its own session pool, and onCreateIndex passes w.sess.Context to preSplitIndexRegions. The worker therefore uses its default 300 seconds plus the 30-second statistics allowance in this case. This matters when operators plan how long pre-splitting may delay backfill. Please describe the 330-second worker budget in the ADD INDEX section and clarify the scope here. Worker session · ADD INDEX call site · Budget calculation.
There was a problem hiding this comment.
Thanks for catching this. Updated both the ADD INDEX section and system-variables.md in b8775b359. They now clarify that all AUTO indexes in a DDL job share a default 330-second budget: the DDL worker's 300-second timeout plus the fixed 30-second allowance for loading statistics. Changing tidb_wait_split_region_timeout in the session that submits ADD INDEX or CREATE INDEX does not affect this budget.
There was a problem hiding this comment.
Verified in b8775b359. Both pages now describe the shared 330-second default and explain that changing the submitting session's variable leaves that budget unchanged. This matches the scheduler creating a separate worker session and preSplitIndexRegions reading its timeout from that session. That resolves my P2.
wjhuang2016
left a comment
There was a problem hiding this comment.
The timeout issue is resolved in both the ADD INDEX guide and the system variable reference. The 330-second default matches the DDL worker's own 300-second timeout plus the 30-second statistics allowance. A SET SESSION in the submitting connection leaves the worker's budget unchanged. Both examples still require usable Version 2 statistics for the leading column, and the v8.5.9 introduction and backport label are in place. I found no new blocking issues in the full diff. The Vale, link and anchor checks passed at this commit.
The code verifies AUTO on the 202609 release branch. Please confirm that CLOUD.202609.1 is the first deployed patch before publishing the version annotation.
|
@wjhuang2016: adding LGTM is restricted to approvers and reviewers in OWNERS files. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
wjhuang2016
left a comment
There was a problem hiding this comment.
The previously reviewed fixes still hold in this revision. Both examples require usable Version 2 statistics on the leading column, the 8.5.9 documentation backport is marked, and the two pages still explain that the 330-second worker budget ignores the submitting session's timeout.
One P2 remains in the complete diff. The AUTO keyword entry omits a parser compatibility detail that can break existing role-management scripts after upgrade.
Non-blocking: nest Prerequisites and Usage examples under Automatic Region pre-splitting on the ADD INDEX page. The exact first deployed Cloud patch also remains to be confirmed.
| - ASCII | ||
| - ATTRIBUTE | ||
| - ATTRIBUTES | ||
| - AUTO |
There was a problem hiding this comment.
[P2] Document the role-name exception for AUTO. The keyword reference tells readers that non-reserved keywords can be used as identifiers without backticks. After this parser change, existing scripts that run CREATE ROLE auto or SET ROLE auto fail with a syntax error. The parser tests show that both statements work when the role name is quoted. Please put the exception in the keyword or role reference, or link to release notes that document it for the affected versions. CREATE ROLE test · SET ROLE test.
There was a problem hiding this comment.
Fixed in d9c482cf2. keywords.md now states that, starting from v8.5.9 and v9.0.0, AUTO must be enclosed in backticks when used as a role name, with quoted CREATE ROLE and SET ROLE examples.
There was a problem hiding this comment.
Verified in d9c482cf2. The keyword reference now puts the role-name exception next to the general rule for non-reserved keywords. The TiDB parser tests reject unquoted auto in both CREATE ROLE and SET ROLE and accept the backticked forms shown here. This resolves my P2.
wjhuang2016
left a comment
There was a problem hiding this comment.
The AUTO role-name compatibility finding is resolved. The keyword reference now explicitly requires backticks for role names and gives CREATE ROLE and SET ROLE examples that match the parser tests. The full diff still documents the leading-column Version 2 statistics requirement, the v8.5.9 backport, and the 330-second default budget in the DDL worker's session. The Vale, link, and anchor checks passed on this commit.
Non-blocking: nest Prerequisites and Usage examples under Automatic Region pre-splitting on the ADD INDEX page. Please confirm the first deployed Cloud patch before publishing the CLOUD.202609.1 annotation.
|
@wjhuang2016: adding LGTM is restricted to approvers and reviewers in OWNERS files. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
|
||
| ### Custom Region pre-splitting | ||
|
|
||
| <span class="version-mark">Supported in CLOUD.202510.1 and later for TiDB Cloud Premium, and in CLOUD.202603.1 and later for TiDB Cloud Essential</span> |
There was a problem hiding this comment.
| <span class="version-mark">Supported in CLOUD.202510.1 and later for TiDB Cloud Premium, and in CLOUD.202603.1 and later for TiDB Cloud Essential</span> | |
| <span class="version-mark">New in CLOUD.202510.1 and later for TiDB Cloud Premium, and in CLOUD.202603.1 and later for TiDB Cloud Essential</span> |
[LGTM Timeline notifier]Timeline:
|
First-time contributors' checklist
What is changed, added, or deleted? (Required)
Document the experimental
PRE_SPLIT_REGIONS AUTOoption for adding indexes to existing tables:ADD INDEXandCREATE INDEX, including per-index scope, Analyze V2 statistics requirements, and skip conditions.CREATE TABLEoption, and document MySQL compatibility and theAUTOkeyword changes, including role-name quoting and SQL digest changes.Validation: Markdown formatting, internal links, and link anchors passed.
Which TiDB version(s) do your changes apply to? (Required)
Tips for choosing the affected version(s):
By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.
For details, see tips for choosing the affected versions.
What is the related PR or file link(s)?
AI agent involvement
Do your changes match any of the following descriptions?
Summary by CodeRabbit
PRE_SPLIT_REGIONS AUTOsupport for index creation and index additions. It uses existing column statistics to choose split boundaries and is best-effort; index creation continues if statistics are unsuitable or splitting fails.CREATE TABLEoption.