简体   繁体   English

mysql错误解释加入大表

[英]mysql wrong explain join large table

I have a 4Gb table and when I try to select row from it with left join on another table it creates very large temporary table on disc. 我有一个4Gb表,当我尝试从另一个表上的左连接中选择行时,它会在光盘上创建非常大的临时表。 My sql is: 我的sql是:

 select * 
   from ads 
   left join theme 
     ON ads.theme_id = theme.id 
  ORDER BY ads.id DESC 
  limit 1

table ads has 4Gb of data but table theme is very small. 表格ads有4Gb的数据,但表格theme非常小。 When I try explain this query mysql doesn't shows me that temporary table will be created but it does. 当我尝试解释这个查询时,mysql没有向我显示临时表将被创建,但确实如此。 And when I use sql 而当我使用SQL时

SELECT * 
  from ads, 
       theme 
 where ads.theme_id = theme.id 
 ORDER BY ads.id DESC 
 LIMIT 1

mysql runs very fast however this query has same explanation by mysql. mysql运行速度非常快,但是mysql对此查询有相同的解释。

I use innodb engine and I have only primary indexes. 我使用innodb引擎,我只有主索引。

Add an index on ads.theme_id . ads.theme_id上添加索引。 Otherwise, it has to scan the entire ads table to check this column against theme.id . 否则,它必须扫描整个ads表以针对theme.id检查此列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM