Oracle查询速度慢

时间:2017-09-18 04:49:08

标签: sql oracle

当我像查询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
********************************************************************************

1 个答案:

答案 0 :(得分:10)

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

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

QUERY

     

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

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

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

DISK

     

从磁盘上的数据文件中物理读取的所有分析,执行或提取调用的数据块总数