• ADADADADAD

    mysql uuid是不是有序增加的[ mysql数据库 ]

    mysql数据库 时间:2024-11-28 13:00:27

    作者:文/会员上传

    简介:

    A UUID is designed as a number that is globally unique in space and time. Two calls to UUID() areexpected to generate two different values, even if these calls

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。


    A UUID is designed as a number that is globally unique in space and time. Two calls to UUID() are
    expected to generate two different values, even if these calls are performed on two separate computers
    that are not connected to each other.
    uuid是世界上唯一的,就算两个没有任何关系的计算机uuid也是不同的

    但是文档上却没有说到他是不是有序的,网上都说uuid是无序,我想一个场景试一下:

    场景解释:
    建一个表,里面有两个字段 uuid和时间。
    每一秒向这个表里插入一条数据,分别是 uuid()和now()

    插入一段时间之后,如果按id排序和按t_date排序得到的结果是一样的,那么应该可以证明uuid是有序的,如果排序结果不一样,那么是无序的。

    我这里两个进程同时插入,并且跑了两个小时

    模拟过程:
    在mysql 5.6上测试
    mysql> create table song( id char(36), t_date datetime);
    Query OK, 0 rows affected (0.00 sec)


    cat insert.sh
    #!/bin/bash
    while true; do
    mysql -h20.13.52.100 -P3306 -uroot -ptest -e "insert into test.song select uuid(),now();"
    sleep 1
    done


    nohup sh insert.sh &
    nohup sh insert.sh &

    两个一起插入

    运行大概两个小时,停掉insert.sh后:

    mysql -h20.13.52.100 -P3306 -uroot -ptest -e "select * from test.song order by t_date;" > a.log
    mysql -h20.13.52.100 -P3306 -uroot -ptest -e "select * from test.song order by id;" > b.log
    diff a.log b.log -y > c.log

    [root@10-13-59-213 ~]# vim c.log
    id t_date id t_date
    b6af9995-50d2-11e6-9d61-5254005ae15d 2016-07-23 20:41:01 | 0019655a-50d5-11e6-9d61-5254005ae15d 2016-07-23 20:57:24
    cc161c32-50d2-11e6-9d61-5254005ae15d 2016-07-23 20:41:37 | 001968e2-50d5-11e6-9d61-5254005ae15d 2016-07-23 20:57:24
    ccafd852-50d2-11e6-9d61-5254005ae15d 2016-07-23 20:41:38 <
    cd495dc1-50d2-11e6-9d61-5254005ae15d 2016-07-23 20:41:39 <

    从c.log中可以看到a.log和b.log的不同。 那么 uuid()是无序的

    mysql uuid是不是有序增加的.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: mysqluuid