Hola, una consulta, tengo esta sentencia con inner Join y me demora aprox. 7 minutos
SELECT a.MdaAlmCod,
a.MddTipDoc,
a.CDTNroDoc,
a.CDTFchTrn,
a.MdcCcoCod,
b.DDTCodSec,
b.DDPNroPda,
b.DDTTpoPda,
Left(b.DDTItmCod, 1 ) As PrdProd,
SubString(b.DDTItmCod, 2, 1) As FamProd,
--Case When b.DDTCodSec = 'H' Then SubString(b.DDTItmCod, 3, 6) Else SubString(b.DDTItmCod, 3, 6) End DesProd,
SubString(b.DDTItmCod, 3, 6) DesProd,
SubString(b.DDTItmCod, 9, 2) As VrnProd,
a.CDTRefDoc,
SUM(b.DDTCntKgs) KgsDsp,
SUM((Case When DDTCldPar = '1' Or DDTCldPar = ' ' Or DDTCldPar = '0' Then b.DDTCntUnd Else 0 End)) Und1era,
SUM((Case When DDTCldPar = '2' Then b.DDTCntUnd Else 0 End)) Und2das
FROM CT3T004 a
INNER Join CT3T005 b On
b.MdaAlmCod = a.MdaAlmCod And
b.MddTipDoc = a.MddTipDoc And
b.CDTNroDoc = a.CDTNroDoc
WHERE A.MDAALMCOD = 'CTL'
AND a.MddTipDoc = 'NS'
And a.CDTFchTrn Between pFechaIni And pFechaFin
And b.DDTCodSec = vCodSec
--And a.MdcCcoCod = DECODE(ALLTRIM(vCCsCod),NULL,a.MdcCcoCod, vCCsCod)
--And b.DDTTPOPDA = DECODE(ALLTRIM(vTpoPda),NULL,b.DDTTPOPDA,vTpoPda)
GROUP BY A.MdaAlmCod,
A.MddTipDoc,
A.CDTNroDoc,
CDTFchTrn,
MdcCcoCod,
DDTCodSec,
DDPNroPda,
DDTTpoPda,
b.DDTItmCod,
CDTRefDoc;
con esta sentencia me demora 2 segundos ¿por qué?
SELECT /*+ INDEX (b SYS_C009606) */
a.mdaalmcod, a.mddtipdoc, a.cdtnrodoc, a.cdtfchtrn, a.mdcccocod,
b.ddtcodsec, b.ddpnropda, b.ddttpopda,
LEFT (b.ddtitmcod, 1) AS prdprod,
substring (b.ddtitmcod, 2, 1) AS famprod,
substring (b.ddtitmcod, 3, 6) desprod,
substring (b.ddtitmcod, 9, 2) AS vrnprod, a.cdtrefdoc,
SUM (b.ddtcntkgs) kgsdsp,
SUM ((CASE
WHEN b.ddtcldpar = '1'
OR b.ddtcldpar = ' '
OR b.ddtcldpar = '0'
THEN b.ddtcntund
ELSE 0
END
)
) und1era,
SUM ((CASE
WHEN b.ddtcldpar = '2'
THEN b.ddtcntund
ELSE 0
END)) und2das
FROM ct3t005 b, ct3t004 a
WHERE a.mdaalmcod = 'CTL'
AND a.mddtipdoc = 'NS'
AND a.cdtfchtrn BETWEEN pFechaIni
AND pFechaFin
AND b.ddtcodsec = vCodSec
And a.MdcCcoCod = DECODE(ALLTRIM(vCCsCod),NULL,a.MdcCcoCod, vCCsCod)
And b.DDTTPOPDA = DECODE(ALLTRIM(vTpoPda),NULL,b.DDTTPOPDA,vTpoPda)
AND b.mdaalmcod = a.mdaalmcod
AND b.mddtipdoc = a.mddtipdoc
AND b.cdtnrodoc = a.cdtnrodoc
GROUP BY a.mdaalmcod,
a.mddtipdoc,
a.cdtnrodoc,
a.cdtfchtrn,
a.mdcccocod,
b.ddtcodsec,
b.ddpnropda,
b.ddttpopda,
b.ddtitmcod,
a.cdtrefdoc;