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
@@ -72,10 +76,14 @@ SELECT * FROM tables WHERE table_schema='mysql' AND table_name='user'\G
72
76
CHECK_TIME: NULL
73
77
TABLE_COLLATION: utf8mb4_bin
74
78
CHECKSUM: NULL
75
-
CREATE_OPTIONS:
76
-
TABLE_COMMENT:
79
+
CREATE_OPTIONS:
80
+
TABLE_COMMENT:
77
81
TIDB_TABLE_ID: 5
78
82
TIDB_ROW_ID_SHARDING_INFO: NULL
83
+
TIDB_PK_TYPE: CLUSTERED
84
+
TIDB_PLACEMENT_POLICY_NAME: NULL
85
+
TIDB_TABLE_MODE: Normal
86
+
TIDB_AFFINITY: NULL
79
87
1 row inset (0.00 sec)
80
88
```
81
89
@@ -115,12 +123,16 @@ The description of columns in the `TABLES` table is as follows:
115
123
*`CREATE_OPTIONS`: Creates options.
116
124
*`TABLE_COMMENT`: The comments and notes of the table.
117
125
118
-
Most of the information in the table is the same as MySQL. Only two columns are newly defined by TiDB:
126
+
Most of the information in the table is the same as MySQL. The following columns are newly defined by TiDB:
119
127
120
128
*`TIDB_TABLE_ID`: to indicate the internal ID of a table. This ID is unique in a TiDB cluster.
121
129
*`TIDB_ROW_ID_SHARDING_INFO`: to indicate the sharding type of a table. The possible values are as follows:
122
130
-`"NOT_SHARDED"`: the table is not sharded.
123
131
-`"NOT_SHARDED(PK_IS_HANDLE)"`: the table that defines an integer Primary Key as its row id is not sharded.
124
132
-`"PK_AUTO_RANDOM_BITS={bit_number}"`: the table that defines an integer Primary Key as its row id is sharded because the Primary Key is assigned with `AUTO_RANDOM` attribute.
125
133
-`"SHARD_BITS={bit_number}"`: the table is sharded using `SHARD_ROW_ID_BITS={bit_number}`.
126
-
- NULL: the table is a system table or view, and thus cannot be sharded.
134
+
-`NULL`: the table is a system table or view, and thus cannot be sharded.
135
+
*`TIDB_PK_TYPE`: the primary key type of the table. Possible values include `CLUSTERED` (clustered primary key) and `NONCLUSTERED` (non-clustered primary key).
136
+
*`TIDB_PLACEMENT_POLICY_NAME`: the name of the placement policy applied to the table.
137
+
*`TIDB_TABLE_MODE`: the mode of the table, for example, `Normal`, `Import`, or `Restore`.
138
+
*`TIDB_AFFINITY`: the affinity level of the table. It is `table` for non-partitioned tables, `partition` for partitioned tables, and `NULL` when affinity is not enabled.
Copy file name to clipboardExpand all lines: pd-configuration-file.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,6 +292,13 @@ Configuration items related to scheduling
292
292
+ Specifies the upper limit of the `Region Merge` key. When the Region key is greater than the specified value, the PD does not merge the Region with its adjacent Regions.
293
293
+ Default value: `540000`. Before v8.4.0, the default value is `200000`. Starting from v8.4.0, the default value is `540000`.
294
294
295
+
### `max-affinity-merge-region-size` <span class="version-mark">New in v8.5.5</span>
296
+
297
+
+ Controls the threshold for automatically merging small adjacent Regions that belong to the same [affinity](/table-affinity.md) group. When a Region belongs to an affinity group and its size is smaller than this threshold, PD attempts to merge this Region with other small adjacent Regions in the same affinity group to reduce the number of Regions and maintain the affinity effect.
298
+
+ Setting it to `0` disables the automatic merging of small adjacent Regions within an affinity group.
299
+
+ Default value: `256`
300
+
+ Unit: MiB
301
+
295
302
### `patrol-region-interval`
296
303
297
304
+ Controls the running frequency at which the checker inspects the health state of a Region. The smaller this value is, the faster the checker runs. Normally, you do not need to adjust this configuration.
@@ -372,6 +379,11 @@ Configuration items related to scheduling
372
379
+ The number of the `Region Merge` scheduling tasks performed at the same time. Set this parameter to `0` to disable `Region Merge`.
373
380
+ Default value: `8`
374
381
382
+
### `affinity-schedule-limit` <span class="version-mark">New in v8.5.5</span>
383
+
384
+
+ Controls the number of [affinity](/table-affinity.md) scheduling tasks that can be performed concurrently. Setting it to `0` disables affinity scheduling.
385
+
+ Default value: `0`
386
+
375
387
### `high-space-ratio`
376
388
377
389
+ The threshold ratio below which the capacity of the store is sufficient. If the space occupancy ratio of the store is smaller than this threshold value, PD ignores the remaining space of the store when performing scheduling, and balances load mainly based on the Region size. This configuration takes effect only when `region-score-formula-version` is set to `v1`.
Copy file name to clipboardExpand all lines: sql-statements/sql-statement-alter-table.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,6 +54,7 @@ AlterTableSpec ::=
54
54
| TTLEnable EqOpt ( 'ON' | 'OFF' )
55
55
| TTLJobInterval EqOpt stringLit
56
56
)
57
+
| 'AFFINITY' EqOpt stringLit
57
58
| PlacementPolicyOption
58
59
59
60
PlacementPolicyOption ::=
@@ -181,6 +182,8 @@ The following major restrictions apply to `ALTER TABLE` in TiDB:
181
182
182
183
- Changes of some data types (for example, some TIME, Bit, Set, Enum, and JSON types) are not supported due to the compatibility issues of the `CAST` function's behavior between TiDB and MySQL.
183
184
185
+
- The `AFFINITY` option is a TiDB extension syntax. After `AFFINITY` is enabled for a table, you cannot modify the partition scheme of that table, such as adding, dropping, reorganizing, or swapping partitions. To modify the partition scheme, you must first remove `AFFINITY`.
186
+
184
187
- Spatial data types are not supported.
185
188
186
189
-`ALTER TABLE t CACHE | NOCACHE` is a TiDB extension to MySQL syntax. For details, see [Cached Tables](/cached-tables.md).
@@ -168,21 +169,25 @@ The following *table_options* are supported. Other options such as `AVG_ROW_LENG
168
169
|`AUTO_ID_CACHE`| To set the auto ID cache size in a TiDB instance. By default, TiDB automatically changes this size according to allocation speed of auto ID |`AUTO_ID_CACHE` = 200 |
169
170
|`AUTO_RANDOM_BASE`| To set the initial incremental part value of auto_random. This option can be considered as a part of the internal interface. Users can ignore this parameter |`AUTO_RANDOM_BASE` = 0|
170
171
|`CHARACTER SET`| To specify the [character set](/character-set-and-collation.md) for the table |`CHARACTER SET` = 'utf8mb4' |
172
+
|`COLLATE`| To specify the character set collation for the table |`COLLATE` = 'utf8mb4_bin' |
171
173
|`COMMENT`| The comment information |`COMMENT` = 'comment info' |
174
+
|`AFFINITY`| To enable affinity scheduling for a table or partition. It can be set to `'table'` for non-partitioned tables and `'partition'` for partitioned tables. Setting it to `'none'` or leaving it empty disables affinity scheduling. |`AFFINITY` = 'table' |
172
175
173
176
<CustomContentplatform="tidb">
174
177
175
178
> **Note:**
176
179
>
177
-
> The `split-table` configuration option is enabled by default. When it is enabled, a separate Region is created for each newly created table. For details, see [TiDB configuration file](/tidb-configuration-file.md).
180
+
> - The `split-table` configuration option is enabled by default. When it is enabled, a separate Region is created for each newly created table. For details, see [TiDB configuration file](/tidb-configuration-file.md).
181
+
> - Before using `AFFINITY`, note that modifying the partitioning scheme (such as adding, dropping, reorganizing, or swapping partitions) of a table with affinity enabled is not supported, and configuring `AFFINITY` on temporary tables or views is not supported.
178
182
179
183
</CustomContent>
180
184
181
185
<CustomContentplatform="tidb-cloud">
182
186
183
187
> **Note:**
184
188
>
185
-
> TiDB creates a separate Region for each newly created table.
189
+
> - TiDB creates a separate Region for each newly created table.
190
+
> - Before using `AFFINITY`, note that modifying the partitioning scheme (such as adding, dropping, reorganizing, or swapping partitions) of a table with affinity enabled is not supported, and configuring `AFFINITY` on temporary tables or views is not supported.
summary: An overview of the usage of SHOW AFFINITY for the TiDB database.
4
+
---
5
+
6
+
# SHOW AFFINITY <spanclass="version-mark">New in v8.5.5</span>
7
+
8
+
The `SHOW AFFINITY` statement shows [affinity](/table-affinity.md) scheduling information for tables configured with the `AFFINITY` option, as well as the target replica distribution currently recorded by PD.
9
+
10
+
## Synopsis
11
+
12
+
```ebnf+diagram
13
+
ShowAffinityStmt ::=
14
+
"SHOW" "AFFINITY" ShowLikeOrWhereOpt
15
+
```
16
+
17
+
`SHOW AFFINITY` supports filtering table names using `LIKE` or `WHERE` clauses.
18
+
19
+
## Examples
20
+
21
+
The following examples create two tables with affinity scheduling enabled and show how to view their scheduling information:
22
+
23
+
```sql
24
+
CREATETABLEt1 (a INT) AFFINITY ='table';
25
+
CREATETABLEtp1 (a INT) AFFINITY ='partition' PARTITION BY HASH(a) PARTITIONS 2;
-`Leader_store_id`, `Voter_store_ids`: the IDs of TiKV stores recorded by PD, indicating which stores host the target Leader and Voter replicas for the table or partitions. If the target replica locations for the affinity group are not determined, or if [`schedule.affinity-schedule-limit`](/pd-configuration-file.md#affinity-schedule-limit-new-in-v855) is set to `0`, the value is displayed as `NULL`.
45
+
-`Status`: indicates the current status of affinity scheduling. Possible values are:
46
+
-`Pending`: PD has not started affinity scheduling for the table or partition, such as when Leaders or Voters are not yet determined.
47
+
-`Preparing`: PD is scheduling Regions to meet affinity requirements.
48
+
-`Stable`: all Regions have reached the target distribution.
49
+
-`Region_count`: the current number of Regions in the affinity group.
50
+
-`Affinity_region_count`: the number of Regions that currently meet the affinity replica distribution requirements.
51
+
- When `Affinity_region_count` is less than `Region_count`, it indicates that some Regions have not yet completed replica scheduling based on affinity.
52
+
- When `Affinity_region_count` equals `Region_count`, it indicates that replica scheduling based on affinity is complete, meaning the distribution of all related Regions meets the affinity requirements. However, this does not indicate that related Region merge operations are complete.
53
+
54
+
## MySQL compatibility
55
+
56
+
This statement is a TiDB extension to MySQL syntax.
0 commit comments