我有一个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'
我想正确地索引此查询,以便它运行得更快。我建议在以下内容上添加一个索引: -
accounts
。Id
(这是主键),
items
。Id
(这是主键),
goods_received
。Id
(这是主键),
challan
。Account_Id
,
challan
。TempoId
,
challan
。Item_Id
,
goods_received
。AccountId
,
challan
。ItemGoodsReceivedId
请告诉我方法是否正确,或者我必须添加更多索引。