我有大约 53 个代码字符串的查询,我需要对其进行优化。我有 PL/SQL Developer 7.0 工具,我应该如何使用它进行优化?
我尝试使用解释计划,但它什么也没告诉我。我还添加了时间和时间戳列,但没有什么有趣的,第一个是空的,第二个总是相同的时间。
我尝试使用测试窗口,但有一个过程需要变量插入,并且当我的查询选择许多行时,我无法使用它。
所以问题是如何使用 PL/SQL Developer 优化 sql 查询?我应该在哪里寻找每个子查询的查询执行时间?也许有一些指南,但现在我只找到了文档,但它对我没有用?就我目前的知识而言,如果没有任何工具,似乎不可能优化如此大的查询。
查询,需要优化:
select count(PRODUCT_NUMBER)
from
(select W.SUID,
I.SUID,
W.PRODUCT_NUMBER,
MI.ML_NUMBER,
I.TITLE_TRANSLIT,
I.COUNTRIES,
QTY.REMAINS,
QTY.ACQ_PRICE_USD,
QTY.REMAINS * QTY.ACQ_PRICE_USD as TOTAL
from (select UID_WARE,
QTY as REMAINS,
ACQ_PRICE_USD
from (select UID_WARE,
PRODUCT_NUMBER,
NVL(sum(QTY_ON_STOCK), 0) - NVL(sum(ADD_IN_QTY), 0) + NVL(sum(ADD_OUT_QTY), 0) as QTY,
ACQ_PRICE_USD as ACQ_PRICE_USD
from (select SI.UID_WARE,
W.PRODUCT_NUMBER,
count(distinct STK.SUID) as QTY_ON_STOCK,
sum(case
when 1 = 1 then
DECODE('' , SM.UID_SOURCE_LOCATION, SM.QTY, 0)
else 0
end) as ADD_OUT_QTY,
sum(case
when 1 = 1 then
DECODE('' , SM.UID_DEST_LOCATION, SM.QTY, 0)
else 0
end) as ADD_IN_QTY,
ROUND(ACQ.PRICE_USD, 2) as ACQ_PRICE_USD
from STOCK_MOVEMENTS SM
join STOCK_ITEMS SI on SM.UID_STOCK_ITEM = SI.SUID
left outer join (select PR.UID_STOCK_ITEM,
DECODE(NVL(CR.RATE, 0), 0, 0, PR.PRICE / CR.RATE) as PRICE_USD
from MV_STOCK_ACQ_PRICES PR,
CURRENCY_RATES CR
where PR.PRICE_DATE = CR.RATE_DATE
and PR.UID_CURRENCY = CR.UID_CURRENCY) ACQ on ACQ.UID_STOCK_ITEM = SI.SUID
join WARES W on W.SUID = SI.UID_WARE
left outer join (select distinct STK.SUID,
STK.QTY_REMAINS
from STOCK_ITEMS STK
where STK.UID_STOCK_LOCATION != 'MS-STL-SALED'
) STK on STK.SUID = SI.SUID
where 1 = 1
group by SI.UID_WARE,
W.PRODUCT_NUMBER,
ACQ.PRICE_USD
) T
group by T.UID_WARE,
T.PRODUCT_NUMBER,
ACQ_PRICE_USD)) QTY
join WARES W on W.SUID = QTY.UID_WARE
join INVENTORY I on I.SUID = W.UID_ISSUE
join MAP_INFO MI on MI.SUID = I.SUID
where REMAINS != 0
and w.UID_SECTION in ('MS-SEC-BOOKS', 'MS-SEC-MAPS'))