zoukankan      html  css  js  c++  java
  • MySQL自增长的bug?

    实验环境:

    mysql> status
    --------------
    mysql Ver 14.14 Distrib 5.7.14, for Linux (x86_64) using EditLine wrapper

    ……

    mysql> show variables like 'auto_increment%';
    +--------------------------+-------+
    | Variable_name            | Value |
    +--------------------------+-------+
    | auto_increment_increment | 1     |
    | auto_increment_offset    | 1     |
    +--------------------------+-------+
    2 rows in set (0.03 sec)
    auto_increment_offset:默认自增长起始点值;
    auto_increment_increment:默认自增长增量值;

    截图取材于标准MySQL5.7官方文档--没有盗版

    mysql> create table t1(id int not null primary key auto_increment);
    Query OK, 0 rows affected (0.21 sec)
    
    mysql> insert into t1 values(null),(null),(null);
    Query OK, 3 rows affected (0.06 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    
    mysql> select * from t1;
    +----+
    | id |
    +----+
    |  1 |
    |  2 |
    |  3 |
    +----+
    3 rows in set (0.00 sec) 

    1、修改自增长变量值

    mysql> set @@auto_increment_offset=10;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> set @@auto_increment_increment=5;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> show variables like 'auto_increment%';
    +--------------------------+-------+
    | Variable_name            | Value |
    +--------------------------+-------+
    | auto_increment_increment | 5     |
    | auto_increment_offset    | 10    |
    +--------------------------+-------+
    2 rows in set (0.02 sec)

     通过变量的修改,现在的自增长起始值是10,增量是5

    2、建表插值

    mysql> create table t2(id int not null primary key auto_increment);
    Query OK, 0 rows affected (0.11 sec)
    
    mysql> insert into t2 values(null),(null),(null);
    Query OK, 3 rows affected (0.04 sec)
    Records: 3  Duplicates: 0  Warnings: 0

    因为自增长起始值是10,增量是5;猜想结果值是10,15,20

    3、查询结果

    mysql> select * from t2;
    +----+
    | id |
    +----+
    |  4 |
    |  9 |
    | 10 |
    +----+
    3 rows in set (0.01 sec)

    结果却非我们所猜想的???

    继续插入值

    mysql> insert into t2 values(null),(null),(null);
    Query OK, 3 rows affected (0.05 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    
    mysql> select * from t2;
    +----+
    | id |
    +----+
    |  4 |
    |  9 |
    | 10 |
    | 30 |
    | 35 |
    | 40 |
    +----+
    6 rows in set (0.00 sec)

    经过多组测试,结果依旧(试验其他值都是正常的,唯独上述有问题)

    那么,

      问题来了auto_increment_offset=10和auto_increment_increment=5这一组数值算是MySQL自增长里的一个bug吗

  • 相关阅读:
    JID 2.0 RC4 发布,高性能的 Java 序列化库
    FBReaderJ 1.6.3 发布,Android 电子书阅读器
    Arquillian 1.0.3.Final 发布,单元测试框架
    JavaScript 的宏扩展 Sweet.js
    Hypertable 0.9.6.5 发布,分布式数据库
    JRuby 1.7.0 发布,默认使用 Ruby 1.9 模式
    httppp 1.4.0 发布,HTTP响应时间监控
    Redis 2.6.0 正式版发布,高性能K/V服务器
    OfficeFloor 2.5.0 发布,IoC 框架
    XWiki 4.3 首个里程碑发布
  • 原文地址:https://www.cnblogs.com/geaozhang/p/6837546.html
Copyright © 2011-2022 走看看