Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle slow query

Tags:

sql

oracle

When I query my table just like this select * from mytable, sometimes (I query the table in PLSQL developer or SQL navigator) query returns results fast and sometimes it takes 25-26 seconds. Of course, this doesn't affect the performance of business transactions. I traced both status and it gave below results:

Fast Time:

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
********************************************************************************

Slow Time:

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
********************************************************************************
like image 491
mohsen.b Avatar asked Dec 24 '22 14:12

mohsen.b


1 Answers

At the first time, it finds all the rows in the buffer cache(see query section), memory IO is faster than disk IO.

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

QUERY

Total number of buffers retrieved in consistent mode for all parse, execute, or fetch calls. Usually, buffers are retrieved in consistent mode for queries

The second time, the required rows are no longer available, might have flushed due to aging or space required by some other queries, hence the Oracle process has to pull all the rows from disk(see under disk section) which is slower than memory IO. And of course, the second time the query has spent most of the time on db file scattered read due to missing index on the table referenced in the query.

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

DISK

Total number of data blocks physically read from the datafiles on disk for all parse, execute, or fetch calls

like image 199
atokpas Avatar answered Dec 31 '22 18:12

atokpas