第二个虚表(临时表)是不能使用索引的,我推测你的 sql 应该还有 where 条件,我实际测试下来计划如下
``` 1,PRIMARY,t,const,PRIMARY,PRIMARY,4,const,1,Using index 1,PRIMARY,<derived2>,ref,<auto_key0>,<auto_key0>,8,"const,const",10, 2,DERIVED,t_comment,ALL,,,,,301841,
```
haozxuan001
2020-07-06 16:08:52 +08:00
对于简单查询或者频率较低时,影响不大。高频扫全表,DB 压力会很大; PS: sql explain select t.id, tc.description, tc.who_said from t_ticket t left join (select ticket_id, description, who_said from t_comment) tc on t.id = tc.ticket_id where t.id = 42498 and tc.who_said = 2;