Oracle 执行计划更改导致数据加工未完成

php中文网
发布: 2016-06-07 17:26:36
原创
1248人浏览过

使用use_hash hint或使用outlines稳固执行计划, 因为时间原因,最后采用了使用hint的方式。hash join 不仅解决了nested loops连

现象:job一直运行,抽取一直在运行,,通过过程中的日志记录定位到是因为抽取x系统数据一直卡着。但是查询正在执行的sql,没有任何结果,抽取这部分数据一直运行了一天,还未完。
 
因为定位不到是哪条sql在运行,于是停job,手动运行这部分的数据抽取,运行时间与正常抽取的时间相近,之前查看系统cpu,io均没有异常,怀疑是因为这部分sql的执行计划改变所致。
 调出系统中的执行计划与手动运行的sql的执行计划进行对比,一条sql的执行计划在月初由hash join 变为nested loops。
 --1.由于定位了sql,查找sql的sql_id
 select sql_id,address,plan_hash_value,hash_value,child_number,sql_text from v$sql                                         
 where sql_text like 'insert into xxx%'
 
--2.dba_hist_sql_plan视图显示了历史的执行计划,timestamp字段指该执行计划生成的时间
 select * from dba_hist_sql_plan h where sql_id='7sjn92j0k8csm';
 每个不同的plan_hash_value值代表一个不同的执行计划。这条对应两个执行计划,在月初的时候新生成了一个计划(连接方式是nested loops),oracle使用了最新的执行计划。
 
 --3.显示所有详细的执行计划
 select plan_table_output from table(dbms_xplan.display_awr('7xh0wcw1qt6d7'));
 
解决方法:使用use_hash hint或使用outlines稳固执行计划,  因为时间原因,最后采用了使用hint的方式。hash join 不仅解决了nested loops连接中大量随机读取的问题,还解决了排序合并连接中排序代价过大的问题。hash join不同于nested loop按照随机读取的方式进行连接,它需要提前将连接对象集中到一起,然后在内存中按照哈希读取的方式进行连接。排序合并连接可以参考:
 
查看计划的两种方式:
 dbms_xplan.display_awr(
    sql_id            in      varchar2,
    plan_hash_value  in      number default null,
    db_id            in      number default null,
    format            in      varchar2 default typical);
 
sql_id
 specifies the sql_id of the sql statement. you can retrieve the appropriate value for the sql statement of interest by querying the column sql_id in dba_hist_sqltext.
 
dbms_xplan.display_cursor(
    sql_id        in  varchar2  default  null,
    child_number  in  number    default  null,
    format        in  varchar2  default  'typical');
 
sql_id
 specifies the sql_id of the sql statement in the cursor cache. you can retrieve the appropriate value by querying the column sql_id in v$sql or v$sqlarea. alternatively, you could choose the column prev_sql_id for a specific session out of v$session. this parameter defaults to null in which case the plan of the last cursor executed by the session will be displayed.

linux

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号