bai_jimmy

导航

mysql--测试前缀索引能否用于order by 或者 group by

创建一个测试用表

mysql> desc two;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| pid   | int(11)     | YES  | MUL | NULL    |                |
| name  | varchar(10) | NO   | MUL | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

向里边插入10000条数据,不会写存储过程,只能用shell插入了

#!/bin/bash

#产生指定范围的随机数
function rand(){
        min=$1
        max=$(($2-$1+1))
        num=$(($RANDOM+100000000))
        echo $(($num%$max+$min))
}
for j in {1..100}
do
        sql='insert into two (pid,name) values ';
        for i in {1..100}
        do
                randnum=$(rand 1 10000)
                randstr=$(date +%s%N | md5sum | head -c 10)
                sql=$sql"('$randnum','$randstr'),"
        done
        sql=${sql%,*}
        /home/work/.jumbo/bin/mysql -u root -p123 -e "use test; $sql"
done

 

posted on 2015-05-17 00:09  bai_jimmy  阅读(837)  评论(0编辑  收藏  举报