java - Oracle select * from all_sequences 太慢了
问题描述
我的项目使用 Hibernate,我想增加启动时间(目前是 1.5 分钟),所以我检查了启动时发生的情况。在SessionFactory
初始化期间,发出的查询之一是:
select * from all_sequences;
需要将近一分钟!来自 Oracle SQL Developer 的相同查询需要相似的时间。返回的记录总数为 102。
还有其他正常运行的查询(一位数毫秒的响应时间)
为什么这么慢?
解决方案
收集数据字典和固定对象的优化器统计信息:
begin
dbms_stats.gather_dictionary_stats;
dbms_stats.gather_fixed_objects_stats;
end;
/
Oracle 需要良好的对象统计信息才能构建良好的执行计划。有很多机制可以为我们的自定义对象收集统计信息,但有时我们也需要为系统对象收集统计信息。(虽然我很惊讶这是开箱即用的必要条件。通常这些问题只发生在极端变化之后,比如创建一百万个新序列。)
如果收集优化器统计信息没有帮助,请尝试使用以下步骤生成执行计划,并将结果发布到问题中。
--Run the query:
select /*+ gather_plan_statistics */ * from all_sequences;
--Find the SQL_ID:
select * from gv$sql where sql_text like '%gather_plan_statistics%';
--Generate the execution plan, with estimated and actual results.
select *
from table(dbms_xplan.display_cursor(sql_id => '9wgbmhhrf0bwr', format=>'ALLSTATS LAST'));
推荐阅读
- php - 无法将图像上传变量设置为 NULL
- php - Laravel Livewire - 如何让@push 工作?
- python - 在 Python 中查找元组对的最小值的索引
- input - gatsbyjs 渐进式网络应用程序上 iphone 用户的输入问题
- angular - 从后端服务测试一个可观察的主题
- caching - 如何更改-P模式运行的cmake文件中的CACHE变量
- python - 用 kivy 播放视频:模块 'ffmpeg' 没有属性 'FFVideo'
- cordova - 创建项目后构建和模拟有什么区别
- json - Beautifulsoup find 方法返回不可下标的对象
- python - 尝试从 DotNet Core MVC 项目执行 python 进程时权限被拒绝