Oracle从all_sequences中选择*太慢

问题描述 投票:2回答:1

我的项目使用Hibernate,我想增加启动时间(目前为1.5分钟),所以我检查了启动时发生的情况。在SessionFactory初始化期间,发出的查询之一是:

select * from all_sequences;

需要近一分钟!来自Oracle SQL Developer的相同查询花费的时间相似。返回的总记录为102。

还有其他正常运行的查询(一位数毫秒的响应时间)

为什么这么慢?

java oracle hibernate
1个回答
0
投票

收集数据字典和固定对象的优化器统计信息:

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'));
© www.soinside.com 2019 - 2024. All rights reserved.