1 奇怪 update join 2表不同的写法执行时间差很远update aa a , bb b set aa.isHis='Y' where a.aid=b.bid
发现
比起
update aa a set aa.isHis='Y' where a.aid in (select id from bb)
要慢 下面明显要快2 同样的java代码 +mysql , db链接在a机器(mysql)上跑很快 , db链接在b机器上(mysql)发现很慢。
不知道如何分析原因 ,观察配置也没有发现太大问题 ??
发现
比起
update aa a set aa.isHis='Y' where a.aid in (select id from bb)
要慢 下面明显要快2 同样的java代码 +mysql , db链接在a机器(mysql)上跑很快 , db链接在b机器上(mysql)发现很慢。
不知道如何分析原因 ,观察配置也没有发现太大问题 ??
解决方案 »
- mysql调用存储过程出现Illegal mix of collations错误
- 续论坛单日最高帖HQL语句
- SQL语句出错了CreateTable
- source H:\HI_IMAGE-ACCESS\HIWorkstation_Mysql20080921120105.sql命令的问题
- 求关于MYSQL中自增长字段的问题
- 插入mysql 繁体字时,程序报错,急,急
- left join 联查两张表里有重名字段的问题
- mysql的默认密码怎么改呢?
- 在线等,mysql模糊查找!!!
- 求把Oracle语句改为Mysql的,大侠帮忙啊
- 每个用户每个月最后一次生成的记录,sql如何实现
- MYSQL临时表能在两个存储过程中通用吗
explain select * from aa a where a.aid in (select id from bb)
+----+-------------+-------+------+------------------------+------------------------+---------+-------------------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+------------------------+------------------------+---------+-------------------+--------+-------------+
| 1 | SIMPLE | n | ALL | idx_heap_id | NULL | NULL | NULL | 220000 | |
| 1 | SIMPLE | m | ref | idx_EP_eventId_history | idx_EP_eventId_history | 8 | oddsmatrixdb.n.id | 12 | Using where |
+----+-------------+-------+------+------------------------+------------------------+---------+-------------------+--------+-------------+
2 rows in setexplain select * from aa a where a.aid in (select id from bb)
+----+--------------------+-------+----------------+---------------+-------------+---------+------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------+----------------+---------------+-------------+---------+------+---------+-------------+
| 1 | PRIMARY | m | ALL | NULL | NULL | NULL | NULL | 1333711 | Using where |
| 2 | DEPENDENT SUBQUERY | n | index_subquery | idx_heap_id | idx_heap_id | 5 | func | 21 | |
+----+--------------------+-------+----------------+---------------+-------------+---------+------+---------+-------------+
2 rows in set奇怪后面的速度好快的 。 前面慢得不得了。bb是 memory表 ,后面的能走hash索引导致飞快
主要是后者保证走hash索引 避免全表
根据1年多的mysql调优经验 总结