Discovered a Strange Phenomenon That Might Be a Bug

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

Original topic: 发现一个奇怪的现象可能是bug

| username: MuFeng

When learning auto_random, I created a table rd in the experimental environment.

Create table statement

mysql> show create table rd \G
*************************** 1. row ***************************
       Table: rd
Create Table: CREATE TABLE `rd` (
  `id` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,
  `name` char(4) DEFAULT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_rand_base] AUTO_RANDOM_BASE=60001 */
1 row in set (0.00 sec)

Perform the following operations on the table in tidb-server

mysql> select tidb_row_id_sharding_info from information_schema.tables where table_name='rd' and table_schema='test';
+---------------------------+
| tidb_row_id_sharding_info |
+---------------------------+
| PK_AUTO_RANDOM_BITS=5     |
+---------------------------+
1 row in set (0.01 sec)

mysql> insert into rd(name) values ('Jac'),('Hua');
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> commit; 
Query OK, 0 rows affected (0.00 sec)

mysql> select * from rd;
+----+------+
| id | name |
+----+------+
|  1 | Jac  |
|  2 | Hua  |
+----+------+
2 rows in set (0.01 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

Connect to another tidb-server through a MySQL graphical client and insert the following two rows

insert into rd(name) values ('Vim'),('Tom');
commit;

Return to the original tidb-server

mysql> select * from rd;
+---------------------+------+
| id                  | name |
+---------------------+------+
|                   1 | Jac  |
|                   2 | Hua  |
| 6052837899185976625 | Vim  |
| 6052837899185976626 | Tom  |
+---------------------+------+
4 rows in set (0.00 sec)

mysql> insert into rd(name) values ('Coo'),('Jim');
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from rd;
+---------------------+------+
| id                  | name |
+---------------------+------+
|                   1 | Jac  |
|                   2 | Hua  |
| 5764607523034234883 | Coo  |
| 5764607523034234884 | Jim  |
| 6052837899185976625 | Vim  |
| 6052837899185976626 | Tom  |
+---------------------+------+
6 rows in set (0.00 sec)

Question

Why are the first two rows numbered 1 and 2???
Bug???

| username: h5n1 | Original post link

autorandom is composed of the sign bit + time hash + auto-increment value, which may result in relatively short values.

| username: CuteRay | Original post link

You can carefully read the documentation. The example in the documentation is the same as yours, and it doesn’t say it can’t be 1.

| username: tidb菜鸟一只 | Original post link

I tried both versions 5.4.3 and 6.5.0, and did not encounter situations 1 and 2. Both resulted in 19-digit numbers.
image
image

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.