次の SQL ステートメントのロードに時間がかかる理由を知っている人はいますか ???
select LE_ACNT_STKG.ID_PRD_RP
from
TR_LTM_PHY_CNT
inner join AS_ITM_STK ON (AS_ITM_STK.ID_STR_RT = TR_LTM_PHY_CNT.ID_STR_RT
and AS_ITM_STK.ID_ITM = TR_LTM_PHY_CNT.ID_ITM)
inner join LE_ACNT_STKG ON (LE_ACNT_STKG.ID_STR_RT = TR_LTM_PHY_CNT.ID_STR_RT
and LE_ACNT_STKG.ID_ITM = TR_LTM_PHY_CNT.ID_ITM)
inner JOIN AS_ITM ON (AS_ITM.ID_ITM = AS_ITM_STK.ID_ITM and AS_ITM.ID_STR_RT = AS_ITM_STK.ID_STR_RT)
inner join LO_LCN ON (LE_ACNT_STKG.ID_LCN = LO_LCN.ID_LCN)
INNER JOIN DO_CNT_PHY on TR_LTM_PHY_CNT.ID_DCM_PHY_CNT = DO_CNT_PHY.ID_DCM_PHY_CNT
INNER JOIN CO_EV on (DO_CNT_PHY.ID_STR_RT = CO_EV.ID_STR_RT
and DO_CNT_PHY.ID_EV = CO_EV.ID_EV)
where
LE_ACNT_STKG.ID_PRD_RP >= 4792
AND LE_ACNT_STKG.ID_PRD_RP <= 6693
AND LE_ACNT_STKG.ID_PRD_RP IN (
SELECT TOP 1 LE_ACNT_STKG.ID_PRD_RP
FROM LE_ACNT_STKG
INNER JOIN CA_PRD_RP ON (LE_ACNT_STKG.ID_PRD_RP = CA_PRD_RP.ID_PRD_RP)
WHERE
CA_PRD_RP.TY_PRD_RP = 'CD' AND
LE_ACNT_STKG.ID_STR_RT = TR_LTM_PHY_CNT.ID_STR_RT AND
LE_ACNT_STKG.ID_ITM = TR_LTM_PHY_CNT.ID_ITM AND
(
(CA_PRD_RP.TS_PRD_RP_STRT <= CO_EV.TS_EV_ACT_EF AND CA_PRD_RP.TS_PRD_RP_END >= CO_EV.TS_EV_ACT_EF)
OR --If we're in the latest period, which is still open
(CA_PRD_RP.TS_PRD_RP_STRT <= CO_EV.TS_EV_ACT_EF AND CA_PRD_RP.TS_PRD_RP_END IS NULL)
OR --if there isn't one for the current period, get the previous one
(CA_PRD_RP.TS_PRD_RP_END < CO_EV.TS_EV_ACT_EF)
)
ORDER BY
LE_ACNT_STKG.ID_PRD_RP DESC)
IN()
サブクエリのせいだと思います。そのステートメントを取り出すと、ロードがずっと速くなります。その場合、どうすればいいですか?に置き換えIN
てみましEXISTS
たが、返される結果がまったく異なります。