[Solved] Oracle: hugely improve query performance

How to optimize this SQL query?

In case you have your own slow SQL query, you can optimize it automatically here.

For the query above, the following recommendations will be helpful as part of the 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. Avoid Calling Functions With Indexed Columns (query line: 31): When a function is used directly on an indexed column, the database's optimizer won’t be able to use the index. For example, if the column `sysdate` is indexed, the index won’t be used as it’s wrapped with the function `last_day`. If you can’t find an alternative condition that won’t use a function call, a possible solution is to store the required value in a new indexed column.
The optimized query:
SELECT
        atx.journal_id,
        ab.c_date 
    FROM
        acct_batch ab 
    JOIN
        acct_tx atx 
            ON ab.acct_id = atx.acct_id 
            AND ab.batch_id = atx.batch_id 
    JOIN
        journal j 
            ON j.journal_id = atx.journal_id 
            AND j.journal_type_id = 6 
    JOIN
        acct a 
            ON a.acct_id = atx.acct_id 
            AND a.acct_type_id = 32 
    JOIN
        payments p 
            ON p.payment_id = j.payment_id 
    JOIN
        routing r 
            ON r.route_id = p.route_id 
            AND r.acq_code = 'RZ_NS' 
    JOIN
        acq_acct aa 
            ON aa.acq_code = r.acq_code 
            AND aa.acq_acct_code = r.acq_acct_code 
            AND aa.slc = 'MXM' 
    WHERE
        ab.c_date BETWEEN to_date(to_char('01-JUL-2015')) AND last_day(sysdate)

Related Articles



* original question posted on StackOverflow here.