mysql uuid是不是有序增加的??


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 -h10.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 -h10.13.52.100 -P3306 -uroot -ptest  -e "select * from test.song order by t_date;" > a.log
mysql -h10.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()是无序的




转载请注明源出处
QQ 273002188 欢迎一起学习
QQ 群 236941212
oracle,mysql,PG 相互交流

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25099483/viewspace-2122432/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/25099483/viewspace-2122432/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值