我有以下查询:
select
`gasr`.`RID`,
`gasr`.`ID`,
`gr`.`RID`,
`gr`.`TID`
...
from
(((((((((((( `gasr`
left join `gasro` ON ((`gasr`.`ID` = `gasro`.`ARID`)))
left join `gro` ON ((`gro`.`RID` = `gasr`.`RID`)))
left join `p` ON ((`p`.`ID` = `gasr`.`ID`)))
left join `l` ON ((`l`.`ID` = `p`.`LID`)))
left join `k` ON ((`k`.`ID` = `p`.`KID`)))
left join `s` ON ((`s`.`ID` = `p`.`TID`)))
left join `ad` ON ((`ad`.`ID` = `p`.`DID`)))
left join `ae` ON ((`ae`.`ID` = `p`.`EID`)))
left join `gr` ON ((`gasr`.`RID` = `gr`.`ID`)))
left join `gs` ON ((`gs`.`ID` = `gr`.`SID`)))
left join `ka` ON ((`ka`.`ID` = `gs`.`KID`)))
left join `m` ON ((`m`.`ID` = `ka`.`MID`)))
ORDER BY gs.ID, gr.RID
如上所述使用时确实需要一些时间(大约 5 秒)ORDER BY
。如果我不使用ORDER BY
它真的很快(0.08 秒)。
解释告诉我将创建一个临时表:
零件的两个字段上order by
都有一个普通索引 (asc)。
这是问题吗?我怎样才能避免这种情况?
TIA 马特