[Solved] How to tune this query?
Looking to automatically optimize YOUR SQL query? Start for free.

EverSQL Database Performance Knowledge Base

How to tune this query?

Database type:

I am calculating the resource cost:

        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;

The tables are Oracle ebs WIP tables, the data is correct but this is need to be executed for thousands of records.

How can I tune it?

can I attache the explain plan here?

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Create Optimal Indexes (modified query below): The recommended indexes are an integral part of this optimization effort and should be created before testing the execution duration of the optimized query.
Optimal indexes for this query:
CREATE INDEX wip_transactions_idx_operation_transactio_organizati ON WIP_TRANSACTIONS (operation_seq_num,TRANSACTION_ID,ORGANIZATION_ID);
CREATE INDEX wip_accounts_idx_account_wip_id_transac_organiz ON WIP_TRANSACTION_ACCOUNTS (ACCOUNTING_LINE_TYPE,WIP_ENTITY_ID,TRANSACTION_ID,ORGANIZATION_ID);
The optimized query:
SELECT
        NVL(sum(WT.TRANSACTION_QUANTITY * WTA.RATE_OR_AMOUNT),
        0) 
    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

Related Articles



* original question posted on StackOverflow here.