Офисная база, задание на расчет ССР
Расчет выполняется несколько дней, завершается успешно.
Процесс висит на запросе
Код:
INSERT INTO ttsaleratedocs
(article, createdat, isreturn, quantity)
SELECT s.article, d.createdat, DECODE (d.locationto, 60, '1', '0'),
SUM (s.quantity)
FROM smdocuments d, smspec s
WHERE 60 IN (d.locationfrom, d.locationto)
AND d.docstate = 3
AND ( (d.doctype = 'WI' AND d.opcode = 15)
OR (d.doctype = 'WO' AND d.opcode = 14)
OR (d.doctype = 'WI' AND d.opcode = 11)
OR (d.doctype = 'WO' AND d.opcode = 10)
OR (d.doctype = 'WI' AND d.opcode = 3)
OR (d.doctype = 'CR' AND d.opcode = 3)
OR (d.doctype = 'WO' AND d.opcode = 1)
OR (d.doctype = 'CS' AND d.opcode = 1)
)
AND s.doctype = d.doctype
AND s.docid = d.ID
AND s.article IN (
SELECT r.article
FROM ttsalerate r
WHERE r.storeloc = 60
AND d.createdat BETWEEN r.datefrom AND r.dateto
AND r.idoperswhere = 1
AND SUBSTR (r.includedays,
TO_NUMBER (TO_CHAR (d.createdat, 'D')),
1
) = '1'
AND NOT EXISTS (
SELECT 1
FROM ttexcludedays e
WHERE e.article = s.article
AND e.storeloc = 60
AND d.createdat BETWEEN e.datefrom AND e.dateto
AND r.calcalg IN (2, 3, 4, 5)))
GROUP BY s.article, d.createdat, DECODE (d.locationto, 60, '1', '0')
в ожидании db scateret read.
Сильно грузит проц.
Что он делает столько времени и как это побороть?!