简体   繁体   中英

Oracle behave differently in program and sql developer

I have a spring batch program that checks if the data from the file exist or not in the oracle database. By recommended step from tuning in SQL Developer, I added 2 indexes for the table a and table b. From SQL Developer, without the indexes, it took 0.5sec to load and with indexes only 0.03 sec. However, when running through the program, the query took 0.5 sec to load. I try added hint, using hash join and index hint but no difference. It seems like the oracle does not pick the indexes. Can you help me with this?

SQL:

SELECT 
    pi.PAYMENT_INSTRUCTION_ID,
    cft.CFT_FILE_DETAIL_ID
FROM
    table_a pi
LEFT JOIN 
    table_b cft ON pi.id = cft.tabla_a_id
WHERE 
    pi.internal_trace_number = :traceNumber
    AND cft.payer_account_no like :payerAccountNo
    AND cft.transaction_amount = :amount;

Hint

SELECT /*+ use_hash */
--     /*+ INDEX(pi IDX$$_0A0F0001) INDEX(cft DX$$_0A0F0002)*/
pi.PAYMENT_INSTRUCTION_ID
     , cft.CFT_FILE_DETAIL_ID
FROM table_a pi
         LEFT JOIN table_b cft
                   ON pi.id = cft.tabla_a_id
WHERE pi.internal_trace_number = :traceNumber
  AND cft.payer_account_no like :payerAccountNo
  AND cft.transaction_amount = :amount;
  • UPDATE
  • queries use for indexes
create index TABLE_A_ID on
    TABLE_A (TO_NUMBER("INTERNAL_TRACE_NUMBER"), "CFT_FILE_DETAIL_ID",
"PAYMENT_INSTRUCTION_ID");


create index TABLE_B_ID on
    TABLE_B ("PAYER_ACCOUNT_NO", "TRANSACTION_AMOUNT", "CFT_FILE_DETAIL_ID");


create bitmap index join_pi_cft
    on TABLE_A(CFT_FILE_DETAIL_ID)
    from TABLE_A PI, TABLE_B_ID CFT
        WHERE PI.CFT_FILE_DETAIL_ID = CFT.CFT_FILE_DETAIL_ID;

Try to create indexes for:

  • table_a.internal_trace_number
  • table_b.tabla_a_id

After creating these indexes, check the explain plan and the running time of the SQL statement.

Drop your three existing indexes.

Run the following SQL statements:

create index table_a_i1 on table_a (internal_trace_number);
create index table_b_i1 on table_b (table_a_id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM