# Self-Increasing Id 

+ `AUTO_INCREMENT` Basic use
```
CREATE TABLE t(id int PRIMARY KEY AUTO_INCREMENT, c int);
INSERT INTO t(c) VALUES (1);
INSERT INTO t(c) VALUES (2);
INSERT INTO t(c) VALUES (3), (4), (5);
INSERT INTO t(id, c) VALUES (8, 6), (9, 7);

SELECT * FROM t;

+----+---+
| id | c |
+----+---+
| 1  | 1 |
| 2  | 2 |
| 3  | 3 |
| 4  | 4 |
| 5  | 5 |
| 8  | 6 |
| 9  | 7 |
+—--—+---+
```
------------------------------------------------------------
TiDB auto increment ID
The auto increment ID attribute of the Schema is a very important Schema property. By automatically populating the value of the default column, the data inserted into the Table is guaranteed to increase in trend.
Because TiDB regions Region stored in a range situation, using self-incrementing IDs can cause very detailed write hot issues in the scenario of large-scale data insertion. This can easily cause the performance of a single TiKV node to spike, making it impossible to effectively use the performance of each TiKV node to improve system throughput
AUTO_INCREMENT
- Basic use
```
CREATE TABLE t(id int PRIMARY KEY AUTO_INCREMENT, c int);
INSERT INTO t(c) VALUES (1);
INSERT INTO t(c) VALUES (2);
INSERT INTO t(c) VALUES (3), (4), (5);
INSERT INTO t(id, c) VALUES (8, 6), (9, 7);
SELECT * FROM t;
+----+---+
| id | c |
+----+---+
| 1  | 1 |
| 2  | 2 |
| 3  | 3 |
| 4  | 4 |
| 5  | 5 |
| 8  | 6 |
| 9  | 7 |
+——+---+
```

- Principle implement
  - Each self-incrementing column uses a globally visible key-value pair to record the highest ID currently assigned
  - This globally visible key-value pair is uniformly assigned by the PD
  - In order to reduce the network overhead of distributing self-incrementing IDs in distributed systems, each TiDB node caches a distinct ID segment;
  - The currently pre-allocated ID segment is used up, or TiDB is restart. will request a new ID segment from PD again
