如何调整此查询?

时间:2016-03-29 11:37:51

标签: sql oracle performance oracle-apps

我正在计算资源成本:

        SELECT NVL(sum(WT.TRANSACTION_QUANTITY* WTA.RATE_OR_AMOUNT),0) 
        --    INTO l_resource_cost
        FROM APPS.WIP_TRANSACTION_ACCOUNTS WTA, APPS.WIP_TRANSACTIONS WT
        WHERE WTA.TRANSACTION_ID = WT.TRANSACTION_ID
        AND WTA.ORGANIZATION_ID = WT.ORGANIZATION_ID
        AND WTA.ACCOUNTING_LINE_TYPE =7
        AND WTA.WIP_ENTITY_ID = 1757957
        AND wt.operation_seq_num = 10;

这些表是Oracle ebs WIP表,数据是正确的,但这需要为数千条记录执行。

我该如何调整它?

我可以在这里附上解释计划吗?

1 个答案:

答案 0 :(得分:1)

首先,学会使用正确的显式JOIN语法。简单规则:从不FROM子句中使用逗号:

SELECT COALESCE(sum(WT.TRANSACTION_QUANTITY * WTA.RATE_OR_AMOUNT), 0) 
        --    INTO l_resource_cost
FROM APPS.WIP_TRANSACTION_ACCOUNTS WTA JOIN
     APPS.WIP_TRANSACTIONS WT
     ON WTA.TRANSACTION_ID = WT.TRANSACTION_ID AND
        WTA.ORGANIZATION_ID = WT.ORGANIZATION_ID
WHERE WTA.ACCOUNTING_LINE_TYPE = 7 AND WTA.WIP_ENTITY_ID = 1757957 AND
      wt.operation_seq_num = 10;

索引将有助于查询。我建议:

  • APPS.WIP_TRANSACTION_ACCOUNTS(ACCOUNTING_LINE_TYPE, WIP_ENTITY_ID, RATE_OR_AMOUNT)
  • APPS.WIP_TRANSACTIONS(TRANSACTION_ID, ORGANIZATION_ID, operation_seq_num, TRANSACTION_QUANTITY)