0
SELECT NVL(SUM(TRN.ACCRUALPTS), 0) AS ACCRUALPTS
  FROM TrsanctionTable REQ INNER JOIN 
       TRSANCTIONTABLEREQ TRN ON TRN.TRNREQID = REQ.TRNREQID INNER JOIN 
       CARDTABLE CARD ON CARD.CARDID = TRN.CARDID
 WHERE TRN.CUSTOMERID = 4082
   AND TRN.STATUSCODE = '2220'
   AND REQ.STATUSCODE = '00'
   AND TRN.BATCHID IS NULL;

Above Query which is taking much time to execute, Could you suggest me that how I can rewrite or change this query to run faster. My team suggest to Add composite index on this query.

Is their anything else that can work to reduce the cost of this QUERY

COST OF THIS QUERY IS 102K

NOTE: Indexing Already Apply on Single columns.

enter image description here

enter image description here

9
  • 2
    Hi Ziyad. Can you please post whole explain plan with object names and access methods?
    – ekochergin
    Apr 14, 2021 at 7:30
  • What is the purpose of including the table CARDTABLE when it is not being used anywhere?
    – NickW
    Apr 14, 2021 at 7:36
  • The join on CARDTABLE looks unneeded. unless you need it to exclude records with an invalid TRN.CARDID?
    – ysth
    Apr 14, 2021 at 7:38
  • 1
    Please, execute your query with /*+GATHER_PLAN_STATISTICS*/ hint and paste a textual output from select * from table(dbms_xplan.display_cursor(format => 'BASIC +PREDICATE ALLSTATS LAST')) which should be executed just after your query.
    – astentx
    Apr 14, 2021 at 7:48
  • @NickW there is a join on CARDTABLE the card which done transaction is valid one or not
    – Ziyad Beg
    Apr 14, 2021 at 8:02

1 Answer 1

0
SELECT NVL(SUM(TRN.ACCRUALPTS), 0) AS ACCRUALPTS
FROM TrsanctionTable REQ INNER JOIN 
     TRSANCTIONTABLEREQ TRN 
     ON TRN.TRNREQID = REQ.TRNREQID INNER JOIN 
     CARDTABLE CARD
     ON CARD.CARDID = TRN.CARDID
 WHERE TRN.CUSTOMERID = 4082 AND
       TRN.STATUSCODE = '2220' AND
       REQ.STATUSCODE = '00' AND
       TRN.BATCHID IS NULL;

Multi-column indexes will definitely help. It is not 100% clear what the best approach is without knowing the sizes of the tables and how selecting the filters are. But I am guessing this would help a lot:

  • TRSANCTIONTABLEREQ(CUSTOMERID, STATUSCODE, BATCHID, STATUSCODE, ACCRUALPTS)
  • TrsanctionTable(TRNREQID, STATUSCODE, CARDID)
  • CARDTABLE(CARDID)
1
  • Yes i have apply Multi-column indexes. But not much different in Query Running Time
    – Ziyad Beg
    Apr 14, 2021 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.