PolarDB-X 1.0 sequences generate globally unique numeric values of the MySQL BIGINT type (signed 64-bit integers). Use sequences to populate primary key columns and unique index columns across distributed nodes.
Choose a sequence type
PolarDB-X 1.0 supports four sequence types. Choose based on whether your workload requires consecutive values, cross-instance uniqueness, or maximum performance.
| Type | Globally unique | Consecutive | Monotonically increasing | Monotonically increasing in the same session | Non-single point | Data type | Readability | Unitization |
|---|---|---|---|---|---|---|---|---|
| Group sequence (GROUP) | Yes | No | No | Yes | Yes | All integer types | High | No |
| Unit group sequence (GROUP) | Yes | No | No | Yes | Yes | All integer types | High | Yes |
| Time-based sequence (TIME) | Yes | No | Macro-level only | Yes | Yes | BIGINT only | Low | No |
| Simple sequence (SIMPLE) | Yes | Yes | Yes | Yes | No | All integer types | High | No |
Pick the type that matches your requirement:
Most workloads — use a group sequence. It is the default type, delivers the best performance, and eliminates single points of failure (SPOFs). Values are globally unique but may contain gaps.
Cross-instance or cross-database uniqueness — use a unit group sequence. It extends the group sequence with unitization capability, so values remain unique across multiple instances or databases.
High-throughput inserts without consecutive IDs — use a time-based sequence. Values are never read from or written to the database, so there is no write overhead. The sequence is monotonically increasing at the macro level but not at the micro level.
Strictly consecutive values — use a simple sequence only when your workload requires gapless, monotonically increasing IDs. Simple sequences write every generated value to persistent storage, which creates a bottleneck and a SPOF risk. Use them only when consecutive IDs are a hard requirement.
Key concepts
Understanding these terms helps you interpret the comparison table above.
Consecutive: If the current value is *n*, the next value must be *n + 1*.
Monotonically increasing: If the current value is *n*, the next value must be greater than *n*.
Monotonically increasing at the macro level, non-monotonically at the micro level: The overall trend is increasing, but individual values may arrive out of order. For example:
1, 3, 2, 4, 5, 7, 6, 8, ...Single point: A single point of failure (SPOF) risk exists.
Unitization capability: The ability to generate numeric sequences that are unique across multiple instances or multiple databases.
How each sequence type works
Group sequence (default)
A group sequence distributes value generation across multiple DRDS nodes. Each node retrieves a segment of values from the database at a time, then assigns values from that segment locally. When a network disconnection occurs or a connection closes before the segment is exhausted, the remaining values in that segment are skipped — which is why group sequence values are nonconsecutive.
Advantages: No SPOF, excellent performance, all integer data types supported.
Limitations: Values are nonconsecutive. The actual start value is always greater than the value specified in START WITH. Values cannot be cyclical.
Example: With START WITH 100000, a group sequence might generate 200001, 200002, 200003, 200004, 100001, 100002, 100003.... The values between 200004 and 100001 are missing because they were in an abandoned segment.
Unit group sequence
A unit group sequence works the same way as a group sequence, extended with unitization capability. Configure unit indexes and a unit count to partition the global sequence space across instances or databases. Each unit occupies a non-overlapping subset of the space, so PolarDB-X never generates the same value for two different units.
Requirements for consistent behavior:
All unit group sequences sharing the same sequence space must have the same unit count.
Each sequence must have a distinct unit index.
If you configure only one unit, the behavior is identical to a group sequence.
Advantages: All group sequence advantages, plus uniqueness across multiple instances or databases.
Limitations: Values are nonconsecutive. The actual start value is always greater than START WITH. Values cannot be cyclical.
Unit group sequences are available in DRDS V5.2.7-1606682 and later (released April 27, 2018) and V5.3.3-1670435 and later (released August 15, 2018).
Time-based sequence
A time-based sequence composes each value from a timestamp, a node ID, and a serial number. The system never reads from or writes to the database when generating values — only the sequence name and type are stored. This makes time-based sequences the highest-throughput option.
Values are globally unique and auto-incremental at the macro level. At the micro level, values from concurrent nodes may arrive slightly out of order.
Advantages: No SPOF, excellent performance, no database writes during value generation.
Limitations: Values are nonconsecutive. The START WITH, INCREMENT BY, MAXVALUE, and CYCLE/NOCYCLE parameters are not supported. When used for an AUTO_INCREMENT column, the column must be of the BIGINT type.
Example values: 776668092129345536, 776668098018148352, 776668111578333184, 776668114812141568…
Time-based sequences are available in DRDS V5.2.8-15432885 and later (released December 27, 2018) and V5.3.6-15439241 and later (released December 29, 2018).
Simple sequence
A simple sequence writes every generated value to persistent storage in the database. This guarantees that values are globally unique, consecutive, and monotonically increasing — even after a restart caused by a SPOF, generation resumes from the last persisted value.
Simple sequences are the only type that supports INCREMENT BY, MAXVALUE, and CYCLE/NOCYCLE.
Advantages: Consecutive, monotonically increasing values. Supports maximum value, step size, and cyclical generation.
Limitations: Prone to SPOFs, low performance, and bottlenecks due to the persistent write on every value generation. Use only when consecutive IDs are a hard requirement.
Example: With START WITH 100000 and a step size of 1, a simple sequence generates 100000, 100001, 100002, 100003, 100004, ..., 200000, 200001, ... — gapless even across restarts.
Usage modes
Regardless of type, sequences can be used in two modes.
Explicit sequence: Create and manage a sequence with DDL syntax. Use
SELECT seq.nextvalto retrieve the next value, whereseqis the sequence name. Explicit sequences can be queried and modified independently.Implicit sequence: Add the
AUTO_INCREMENTattribute to a primary key column. PolarDB-X 1.0 creates and manages the underlying sequence automatically.