我有以下这些查询。您能否查看一下并让我知道逻辑是否需要进行任何修改以提高性能。还请根据逻辑建议索引(如果缺少索引将进行交叉验证并添加)
查询(1)
SELECT DT.classid,
SUM(IT.expectedamount) AS expAmt,
SUM(IT.debitamount) AS debAmt
FROM deptrans DT
inner join itemtotal IT
ON DT.id = IT.deposittransid
left outer join depreceipt DR
ON DR.deposittransid = DT.id
WHERE DT.bankaccountid IN ( ? )
AND (( ( DT.statecode IN ( ?, ?, ?, ?,
?, ?, ?, ? )
OR ( DT.statecode IN ( ? )
AND IT.statecode = ? ) )
AND DR.requesttime >= ?
AND DR.requesttime <= ? ))
GROUP BY DT.classid
ORDER BY DT.classid
查询(2)
SELECT Count(DISTINCT DT.id)
FROM deptrans DT
inner join itemtotal IT
ON DT.id = IT.deposittransid
left outer join depreceipt DR
ON DR.deposittransid = DT.id
WHERE DT.bankaccountid IN ( ? )
AND (( ( DT.statecode IN ( ?, ?, ?, ?,
?, ?, ?, ? )
OR ( DT.statecode IN ( ? )
AND IT.statecode = ? ) )
AND DR.requesttime >= ?
AND DR.requesttime <= ? ))
上述查询中3个表(ITEMTOTAL IT,DEPTRANS DT和DEPRECEIPT DR ... resp)的索引,
IX1_ITEMTOTAL ID
IX2_ITEMTOTAL DEPOSITTRANSID
IX3_ITEMTOTAL USERID
IX4_ITEMTOTAL USERID, STATECODE
IX1_DEPTRANS ID
IX2_DEPTRANS CUSTOMERID
IX3_DEPTRANS LOCATIONID
IX4_DEPTRANS BANKACCOUNTID
IX5_DEPTRANS STATECODE
IX6_DEPTRANS TIMEZONEID
IX7_DEPTRANS LASTMODIFYDATE, RESOURCENAME
IX8_DEPTRANS AUTOCLOSESTATE
I035451031300_DEPTRANS_CDT_DNO CREATEDATE, DEPOSITNUMBER
I035938031400_DEPTRANS_RCPTRNO RECEIPTREFNUMBER
IX1_DEPRECEIPT ID
IX2_DEPRECEIPT DEPOSITTRANSID
IX3_DEPRECEIPT USERID, REQUESTTIME, DEPOSITTRANSID
I035451031300_DEPRECP_PDATE POSTINGTIME