MySQL 更新走全表和索引的评估记录数
2016-06-08 21:06
405 查看
#!/usr/bin/perl use DBI; $db_name='scan'; $ip='127.0.0.1'; $user="root"; $passwd="1234567"; $dbh = DBI->connect("dbi:mysql:database=$db_name;host=$ip;port=3306",$user,$passwd,{ RaiseError => 1, AutoCommit => 0 }) or die "can't connect to database ". DBI-errstr; for ($i = 1;$i <= 10;$i++){ eval{ $dbh->do("insert into t2(id,info) values('$i','a$i')") ; $dbh->commit();}; if( $@ ) { #warn "Database error: $DBI::errstr\n"; $dbh->rollback(); #just die if rollback is failing }; }; $dbh->disconnect; mysql> show create table t2; +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | t2 | CREATE TABLE `t2` ( `sn` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) DEFAULT NULL, `info` varchar(40) DEFAULT NULL, PRIMARY KEY (`sn`) ) ENGINE=InnoDB AUTO_INCREMENT=8222 DEFAULT CHARSET=utf8 | +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> select id,count(*) from t2 group by id; +------+----------+ | id | count(*) | +------+----------+ | 1 | 10 | | 2 | 10 | | 3 | 10 | | 4 | 10 | | 5 | 10 | | 6 | 10 | | 7 | 1280 | | 8 | 1280 | | 9 | 1280 | | 10 | 1280 | +------+----------+ 10 rows in set (0.00 sec) Session 1: mysql> explain update t2 set id=100 where id=1; +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ | 1 | SIMPLE | t2 | index | NULL | PRIMARY | 4 | NULL | 5180 | Using where | +----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+ 1 row in set (0.00 sec) Session 2; Database changed mysql> insert into t2(id,info) values(11,'a11'); ---HANG /*继续测试2**************************** Session1: mysql> create index t2_idx1 on t2(id); Query OK, 0 rows affected (0.08 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> explain update t2 set id=100 where id=1; +----+-------------+-------+-------+---------------+---------+---------+-------+------+------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+---------------+---------+---------+-------+------+------------------------------+ | 1 | SIMPLE | t2 | range | t2_idx1 | t2_idx1 | 5 | const | 10 | Using where; Using temporary | +----+-------------+-------+-------+---------------+---------+---------+-------+------+------------------------------+ 1 row in set (0.00 sec) Session2: mysql> insert into t2(id,info) values(11,'a11'); Query OK, 1 row affected (0.01 sec)
相关文章推荐
- MySQL 更新走全表和索引的评估记录数
- 《高性能MySQL》笔记(2)
- 解决MySql Error Code:2006–MySQL服务器已离线错误
- MYSQL 定时器调用存储过程 以及开启事件
- mysql导入导出.sql
- 160608、mysql距离函数st_distance
- msyql优化案例
- MySQL各版本的区别
- mysql表添加联合唯一索引
- mysql group by的用法 注意
- mysql高级排序&高级匹配查询示例
- MySQL无法存储Emoji表情问题
- MySQL 语句优化
- Mysql 5.7.12解压版的安装及配置系统编码
- MySQL 数据库还原语句
- mysql 多实例应用配置部署指南
- mysql命令行查看表结构,字段等信息
- 【mysql函数】FIND_IN_SET函数用法
- Mysql命令
- MySQL数据库优化(四)——MySQL索引优化