Why does mysql show 2 different results on 2 different servers for the same query

送分小仙女□ 提交于 2019-12-11 10:57:32

问题


I have the same MySQL SQL statement running on 2 different databases (my local machine and my production machine). The one on my local machine runs faster while the one on production is slow. Here are the EXPLAIN results on each.

Local Machine

Production Machine

I'd rather not post the exact query if I don't have to.

The only difference I can tell between the 2 is that my local machine is running version 5.6 while the production server is running 5.5. Also, the data on my server is 3 days old which isn't many records. Specifically, I'm looking at row 2 of the explain where one type reads "ref" and the other reads "ALL" and there's a difference of over 28k rows being read. The only difference between the 2 structures is the TimeModified field which isn't being used by the query


回答1:


In MySQL 5.5 and earlier, a derived table never had indexes. The only way a derived table would be accessed was by a full scan. (That's the ALL you see in the EXPLAIN output from the 5.5 server.)

With MySQL 5.6.3, MySQL has the ability to add an index to a derived table, which can improve performance. (Note the name of the index: <auto_key1> in the EXPLAIN output from the 5.6 server).

Reference: https://dev.mysql.com/doc/refman/5.6/en/subquery-optimization.html




回答2:


I did put this as a comment first, but I think it also is the answer :-)

Your table structures might be identical, but your data probably isn't.

The number of rows in your tables will influence the execution plan.



来源:https://stackoverflow.com/questions/23206444/why-does-mysql-show-2-different-results-on-2-different-servers-for-the-same-quer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!