tidb无法获取自增值

Server version
5.7.25-TiDB-v4.0.9 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
MySQL [test]> show create table ti1\G
*************************** 1. row ***************************
       Table: ti1
Create Table: CREATE TABLE `ti1` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin/*!90000 SHARD_ROW_ID_BITS=4 */
1 row in set (0.00 sec)

MySQL [test]> insert into ti1 values();
Query OK, 1 row affected (0.08 sec)

MySQL [test]> select * from ti1;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)

MySQL [test]> insert into ti1 values();
Query OK, 1 row affected (0.03 sec)


MySQL [test]> insert into ti1 values(8935141660703095009);
ERROR 1467 (HY000): Failed to read auto-increment value from storage engine
MySQL [test]> select id from ti1;
+----+
| id |
+----+
|  1 |
|  3 |
+----+
2 rows in set (0.00 sec)

MySQL [test]> insert into ti1 values(5);
ERROR 1467 (HY000): Failed to read auto-increment value from storage engine
MySQL [test]> insert into ti1(id) values(5);
ERROR 1467 (HY000): Failed to read auto-increment value from storage engine

MySQL [test]> insert into ti1(id) values(8935141660703125011);
ERROR 1467 (HY000): Failed to read auto-increment value from storage engine
MySQL [test]> 


MySQL [test]> show create table ti2\G
*************************** 1. row ***************************
       Table: ti2
Create Table: CREATE TABLE `ti2` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=48338
1 row in set (0.00 sec)

MySQL [test]> insert into ti2 values(8935141660703155012);
Query OK, 1 row affected (0.08 sec)

MySQL [test]> select * from ti2;
+---------------------+
| id                  |
+---------------------+
|                   1 |
|                   2 |
| 8935141660703155012 |
+---------------------+
3 rows in set (0.00 sec)

MySQL [test]> insert into ti2 values();
Query OK, 1 row affected (0.03 sec)

MySQL [test]> 

1333 // OverflowShardBits checks whether the recordID overflow `1<<(typeBitsLength-shardRowIDBits-1) -1`.
1334 func OverflowShardBits(recordID int64, shardRowIDBits uint64, typeBitsLength uint64, reservedSignBit bool) bool {
1335     var signBit uint64
1336     if reservedSignBit {
1337         signBit = 1
1338     }
1339     mask := (1<<shardRowIDBits - 1) << (typeBitsLength - shardRowIDBits - signBit)
1340     return recordID&int64(mask) > 0
1341 }

看代码,你给的值溢出了

1 个赞

ok 看代码的话后面遇到这种问题要:
alter table ti1 SHARD_ROW_ID_BITS=0;

此话题已在最后回复的 1 分钟后被自动关闭。不再允许新回复。