如何正确索引多个左连接

时间:2016-04-11 03:25:52

标签: mysql

我有一个SQL查询: -

SELECT `challan` . * , `accounts`.`Name` AS `Account` , 
`accounts`.`AddLine1` , `accounts`.`AddLine2` , `accounts`.`TIN` , 
`accounts`.`PAN` , `accounts2`.`Name` AS `TempoName` , `items`.`Name` AS 
`Item` , `items`.`Units` , `items`.`SecondaryUnits` , 
`goods_received`.`Type` , `accounts3`.`Name` AS `Party`
FROM `challan`
LEFT JOIN `accounts` ON `challan`.`Account_Id` = `accounts`.`Id`
LEFT JOIN `accounts` AS `accounts2` ON `challan`.`TempoId` =`accounts2`.`Id`
LEFT JOIN `items` ON `challan`.`Item_Id` = `items`.`Id`
LEFT JOIN `goods_received` ON `challan`.`ItemGoodsReceivedId` = `goods_received`.`Id`
LEFT JOIN `accounts` AS `accounts3` ON `goods_received`.`AccountId` = `accounts3`.`Id`
WHERE `Challan_Id` = 'EBpzQD'

我想正确地索引此查询,以便它运行得更快。我建议在以下内容上添加一个索引: -
accountsId(这是主键),
itemsId(这是主键),
goods_receivedId(这是主键),
challanAccount_Id
challanTempoId
challanItem_Id
goods_receivedAccountId
challanItemGoodsReceivedId
请告诉我方法是否正确,或者我必须添加更多索引。

0 个答案:

没有答案