mysql 5.6比5.5快,MySQL在5.5中长期运行的查询在5.6中非常快

I have a complex database schema.

I built a big query in MySQL 5.6 which joins 20 tables.

When I run the query on a local copy of MySQL 5.6 on my Mac I am getting 1-2 millisecond response times.

When I run the same query (with the same data via a mysql dump) on MySQL 5.5 on Ubuntu I am getting 60 second response times.

I ran profiling on the slow query and discovered that almost the full 60 seconds is being spent in the 'statistics' stage. The 'statistics' stage is apparently where MySQL is determining how best to perform all the joins.

How can MySQL 5.6 perform this in milliseconds and in 5.5 it is taking a full minute?

Any ideas as to what to address first?

解决方案

MySQL 5.6 (and MariaDB) optimizer does a better job with subqueries and joins. I guess that your query is not well optimized in 5.5. Run:

EXPLAIN SELECT ...

on both MySQL versions, to understand what MySQL should do, and what really does in 5.5. Then, try to FORCE the use of the index used by 5.6.

EDIT: if it is a subquery, you can rewrite it as a join. MySQL 5.6 does this internally in some cases.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值