简体   繁体   English

Oracle 在程序和 sql 开发人员中的行为不同

[英]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.我有一个 spring 批处理程序,用于检查文件中的数据是否存在于 oracle 数据库中。 By recommended step from tuning in SQL Developer, I added 2 indexes for the table a and table b.通过在 SQL Developer 中调整的推荐步骤,我为表 a 和表 b 添加了 2 个索引。 From SQL Developer, without the indexes, it took 0.5sec to load and with indexes only 0.03 sec.从 SQL Developer 开始,没有索引,加载需要 0.5 秒,而索引只有 0.03 秒。 However, when running through the program, the query took 0.5 sec to load.但是,在运行程序时,查询需要 0.5 秒才能加载。 I try added hint, using hash join and index hint but no difference.我尝试添加提示,使用hash joinindex hint ,但没有区别。 It seems like the oracle does not pick the indexes. oracle 似乎没有选择索引。 Can you help me with this?你能帮我解决这个问题吗?

SQL: 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_a.internal_trace_number
  • table_b.tabla_a_id table_b.tabla_a_id

After creating these indexes, check the explain plan and the running time of the SQL statement.创建这些索引后,查看SQL语句的解释计划和运行时间。

Drop your three existing indexes.删除您现有的三个索引。

Run the following SQL statements:运行以下 SQL 语句:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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