In MySQL, auto-increment values are local to each node. In PolarDB-X, AUTO_INCREMENT generates globally unique values across all compute nodes — a critical difference for distributed databases where multiple nodes handle inserts concurrently.
How it works
When you define a column with AUTO_INCREMENT, PolarDB-X creates a sequence and links it to that column. Each time a row is inserted, the sequence generates the next globally unique value and writes it to the column.
The sequence type PolarDB-X creates depends on the partitioning mode of the database:
AUTO mode — NEW sequence
DRDS mode — GROUP sequence
To use a different sequence type, see Associate a sequence with the auto-increment column in a table.
INSERT behavior
| Scenario | Behavior |
|---|---|
No value, 0, or NULL specified | PolarDB-X generates a globally unique value automatically |
| Explicit value specified | PolarDB-X uses the specified value for the current row, then generates subsequent values greater than it |
Sequence properties by database mode
The two sequence types differ in how they guarantee uniqueness, ordering, and MySQL compatibility.
| Property | NEW sequence (AUTO mode) | GROUP sequence (DRDS mode) |
|---|---|---|
| Uniqueness | Globally unique | Globally unique |
| Monotonicity | Globally monotonically increasing | Monotonically increasing per compute node; not guaranteed across nodes |
| Value continuity | Consecutive (gaps may appear after exceptions or restarts) | Consecutive within a compute node connection session and within the cache duration (gaps may appear after exceptions or restarts) |
| MySQL compatibility | Full — all MySQL auto-increment properties | Partial — uniqueness only; other MySQL auto-increment behaviors are not supported |