Is the TSO obtained by the TiDB server always continuous? Will there be any jumps, similar to MySQL's auto_increment?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TiDB server获取的TSO一定是连续的吗?是否会有跳增的情况,类似于MySQL的自增auto_increment?

| username: alfred

【TiDB Usage Environment】Production\Testing Environment\POC
【TiDB Version】
【Encountered Issues】
【Reproduction Path】What operations were performed that led to the issue
【Issue Phenomenon and Impact】
【Attachments】

  • Relevant logs, configuration files, Grafana monitoring (https://metricstool.pingcap.com/)
  • TiUP Cluster Display information
  • TiUP Cluster Edit config information
  • TiDB-Overview monitoring
  • Corresponding module’s Grafana monitoring (if any, such as BR, TiDB-binlog, TiCDC, etc.)
  • Corresponding module logs (including logs from 1 hour before and after the issue)

If the question is related to performance optimization or troubleshooting, please download the script and run it. Please select all and copy-paste the terminal output results for upload.

| username: xfworld | Original post link

TiDB can ensure the monotonicity of auto-increment values, but it cannot guarantee their continuity. Refer to the following example:

CREATE TABLE t (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, a VARCHAR(10), cnt INT NOT NULL DEFAULT 1, UNIQUE KEY (a));
INSERT INTO t (a) VALUES ('A'), ('B');
SELECT * FROM t;
INSERT INTO t (a) VALUES ('A'), ('C') ON DUPLICATE KEY UPDATE cnt = cnt + 1;
SELECT * FROM t;

+----+------+-----+
| id | a    | cnt |
+----+------+-----+
|  1 | A    |   1 |
|  2 | B    |   1 |
+----+------+-----+
2 rows in set (0.00 sec)

Query OK, 3 rows affected (0.00 sec)
Records: 2  Duplicates: 1  Warnings: 0

+----+------+-----+
| id | a    | cnt |
+----+------+-----+
|  1 | A    |   2 |
|  2 | B    |   1 |
|  4 | C    |   1 |
+----+------+-----+
3 rows in set (0.00 sec)
| username: HACK | Original post link

TSO is a monotonically increasing timestamp. You can check out this article:

| username: h5n1 | Original post link

It does not guarantee strict continuity. For example, when the PD leader switches, TSO pre-allocates a 3-second time window each time and then allocates from this window.

| username: 履霜知冰 | Original post link

It is not necessarily continuous. The documentation states that TiDB can ensure the monotonicity of auto-increment values, but it cannot guarantee their continuity. You can refer to the official documentation on the AUTO_INCREMENT feature for more details: AUTO_INCREMENT | PingCAP 文档中心

| username: alfred | Original post link

Under normal circumstances, the TSOs obtained within 3 seconds are continuous, right?

| username: h5n1 | Original post link

There are other conditions to advance, you can check out this article

| username: system | Original post link

This topic will be automatically closed 60 days after the last reply. No new replies are allowed.