【问题标题】:Oracle slow queryoracle慢查询
【发布时间】:2017-09-18 04:49:07
【问题描述】:

当我像select * from mytable 一样查询我的表时,有时(我在 PLSQL 开发人员或 SQL 导航器中查询表)查询会快速返回结果,有时需要 25-26 秒。当然,这不会影响业务事务的性能。 我跟踪了这​​两种状态,结果如下:

快速:

select *
from
 mytable


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      0.64       1.14          0     169184          0         100
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      0.64       1.14          0     169184          0         100

Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: SYS

Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  SQL*Net message to client                       2        0.00          0.00
  SQL*Net more data to client                    40        0.00          0.00
  SQL*Net message from client                     2        0.00          0.00
********************************************************************************

慢节奏:

select *
from
 mytable


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch        1      2.91      23.74     169076     169184          0         100
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        3      2.91      23.74     169076     169184          0         100

Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: SYS

Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  SQL*Net message to client                       2        0.00          0.00
  SQL*Net more data to client                    40        0.00          0.00
  SQL*Net message from client                     2        0.00          0.00
  db file scattered read                      **10686**        0.29         20.20
  db file sequential read                         6        0.00          0.01
  latch: object queue header operation            1        0.00          0.00
********************************************************************************

【问题讨论】:

标签: sql oracle


【解决方案1】:

第一次找到缓冲区缓存中的所有行(见query部分),内存IO比磁盘IO快。

query      
---------- 
0          
0         
169076     
-------  

查询

在一致模式下为所有解析、执行或获取调用检索的缓冲区总数。通常,缓冲区以一致的模式检索以进行查询

第二次,所需的行不再可用,可能由于老化或某些其他查询所需的空间而被刷新,因此 Oracle 进程必须从磁盘中提取所有行(参见 disk 部分)比内存IO慢。当然,由于查询中引用的表上缺少索引,第二次查询将大部分时间花在db file scattered read 上。

disk      
---------- 
0          
0         
169076     
------- 

磁盘

为所有解析、执行或获取调用从磁盘上的数据文件物理读取的数据块总数

【讨论】:

  • 这种波动在查询之间频繁发生重复。我的意思是在打开会话后(例如plsql开发人员的sql窗口)我运行查询并立即完成,我在该会话中再次运行查询但是这次查询需要 25 秒才能完成。数据库有足够的缓存,我认为这次不会有表块超出缓存。
  • @mohsen.b 您可以使用段统计信息来确定分散读取发生在哪个对象上。
  • 我的问题:为什么我的查询 1 次从缓存中读取数据,而下一次从磁盘读取数据等等。我有足够的缓存。
  • 如果您要每次都从表中获取所有行并且表不是太大,请考虑将其固定到缓冲区缓存:1-为keep_cache设置适当的大小:alter system set db_keep_cache_size = 50m scope=both / 2- 将表放入keep cache:alter table mytable storage(buffer_pool keep) /
  • Slow Time 查询的解释计划是什么?该表是否在同一架构中具有索引? OPTIMIZER_INDEX_COST_ADJ 和 DB_FILE_MULTIBLOCK_READ_COUNT 的值是多少?
猜你喜欢
  • 2020-09-05
  • 1970-01-01
  • 2014-10-20
  • 1970-01-01
  • 1970-01-01
  • 2013-10-02
  • 2015-10-04
  • 1970-01-01
  • 2011-04-28
相关资源
最近更新 更多