Home » RDBMS Server » Performance Tuning » Query Hanging with Sequential Read or Latch free Waits (Oracle 9.2.0.6.0 on HP-UX)
Query Hanging with Sequential Read or Latch free Waits [message #502568] Thu, 07 April 2011 06:27 Go to next message
OraKaran
Messages: 183
Registered: March 2008
Location: United Kingdom
Senior Member
Hello

Following query is hanging either with 'Sequential access read' or 'Latch Free' wait event

Important thing is the table which is self joined in subquery here does not have any index at all

While it was hanged I tried to get trace of it and terminated twice. As such haven't got 'row source generataion'

The table has only 120000 records and it shall update 34000 records


UPDATE invoice_header inv
   SET inv.modified_due_date =
          (SELECT inv1.btn_due_date
             FROM invoice_header inv1
            WHERE inv.dct_code = inv1.dct_code AND inv1.release = 'A5')
 WHERE inv.release = 'A5' AND inv.btn_due_date >= TRUNC (SYSDATE)

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1   1267.73    1242.37          0   42312921      16852           0
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2   1267.73    1242.37          0   42312921      16852           0


During 'sequential read' using p1,p2 values tried to get what the session is reading and found that it is using the table itself.

During lath free I found following

SELECT name, 'Child '||child#, gets, misses, sleeps 
  FROM v$latch_children
 WHERE addr= (select p1raw from v$session_wait where sid=18)
UNION
 SELECT name, null, gets, misses, sleeps
  FROM v$latch
 WHERE addr= (select p1raw from v$session_wait where sid=18)

NAME	'CHILD'||CHILD#	GETS	MISSES	SLEEPS
cache buffer handles		3532981370	139895301	17452


However instead of self join when I creaed global temporary table as
create global temporary table t as select * from invoice_header where release='A5' 

And used it in the update as
 UPDATE invoice_header inv
   SET inv.modified_due_date =
          (SELECT t.btn_due_date
             FROM t
            WHERE inv.dct_code = t.dct_code AND t.release = 'A5')
 WHERE inv.release = 'A5' AND inv.btn_due_date >= TRUNC (SYSDATE)


It updated the records in a second!!

Questions are
1) why it is producing 'sequential read' wait event when there is no index access or else why it is doing single block access when FTS is required?
2) Why is the 'latch free' wait event here and what it indicates here with 'cache buffer handles'?
Is it because we are reading and updating the same segment?

Please let me know in case DDL of table is required. It has all nullable columns and no index at all.

Since it is 9i I am unable to use MERGE effectively in this case

Regards,
OraKaran

[Updated on: Thu, 07 April 2011 06:31]

Report message to a moderator

Re: Query Hanging with Sequential Read or Latch free Waits [message #502579 is a reply to message #502568] Thu, 07 April 2011 07:06 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Please read http://www.orafaq.com/forum/mv/msg/84315/433888/102589/#msg_433888 and post the required information.

Regards
Michel

Re: Query Hanging with Sequential Read or Latch free Waits [message #502584 is a reply to message #502568] Thu, 07 April 2011 07:52 Go to previous messageGo to next message
OraKaran
Messages: 183
Registered: March 2008
Location: United Kingdom
Senior Member
Hello Michel

I knew you will ask for Explain plan etc.

However I failed to get the plan in trace as well as using dbms_xplan

see below

SQL> !ls -ltr $ORACLE_HOME/rdbms/admin/utlxplan.sql
-rw-r--r--   1 oracle     dba           2073 Mar  8  2002 /opt/oracle/product/920/rdbms/admin/utlxplan.sql

SQL> drop table plan_table;
drop table plan_table
           *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> @/opt/oracle/product/920/rdbms/admin/utlxplan.sql

Table created.

SQL> explain plan for UPDATE invoice_header la_inv
   SET inv.modified_due_date =
          (SELECT inv1.btn_due_date
             FROM invoice_header inv1
            WHERE inv.dct_code = inv1.dct_code AND inv1.release = 'A5')
 WHERE inv.release = 'A5' AND inv.btn_due_date >= TRUNC (SYSDATE);

Explained.

SQL>  select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
An uncaught error happened in fetching the records : ORA-30929: ORDER SIBLINGS B
Y clause not allowed here

ORA-30929: ORDER SIBLINGS BY clause not allowed here


I can't do Autotrace at it will execute the statement straightway

I have restarted the update in another session and tracing it.
If I get the plan in the trace I will share it here

Else if permitted by you I will try to send the dump file of the table in case I get direct mail id. The size of the dump file is 22Mb in uncompressed state

Regards,
OraKaran

Re: Query Hanging with Sequential Read or Latch free Waits [message #502589 is a reply to message #502568] Thu, 07 April 2011 09:15 Go to previous messageGo to next message
OraKaran
Messages: 183
Registered: March 2008
Location: United Kingdom
Senior Member
Hello

And here is the trace

UPDATE invoice_header inv
   SET inv.modified_due_date =
          (SELECT inv1.btn_due_date
             FROM invoice_header inv1
            WHERE inv.dct_code = inv1.dct_code AND inv1.release = 'A5')
 WHERE inv.release = 'A5' AND inv.btn_due_date >= TRUNC (SYSDATE);


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1   2730.16    2678.69       4653   92694692      36671       34810
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        2   2730.16    2678.69       4653   92694692      36671       34810

Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 11871

Rows     Row Source Operation
-------  ---------------------------------------------------
      0  UPDATE
  34810   TABLE ACCESS FULL INVOICE_HEADER
  34810   TABLE ACCESS FULL INVOICE_HEADER


Elapsed times include waiting on following events:
  Event waited on                             Times   Max. Wait  Total Waited
  ----------------------------------------   Waited  ----------  ------------
  db file scattered read                        732        0.03          0.59
  db file sequential read                      1621        0.01          0.28
  latch free                                     35        0.02          0.02
  log file switch completion                      1        0.00          0.00
  SQL*Net message to client                       1        0.00          0.00
  SQL*Net message from client                     1      683.08        683.08




Is it full scanning inv1 for each row of inv?

What could be cause of 'sequential read' and 'latch free' waits in this case?

Regards,
OraKaran
Re: Query Hanging with Sequential Read or Latch free Waits [message #502590 is a reply to message #502589] Thu, 07 April 2011 09:23 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SELECT count(*) FROM invoice_header inv1;
SELECT count(*) FROM invoice_header inv1 WHERE inv1.release = 'A5';

post results from SQL above
Re: Query Hanging with Sequential Read or Latch free Waits [message #502596 is a reply to message #502568] Thu, 07 April 2011 09:37 Go to previous messageGo to next message
OraKaran
Messages: 183
Registered: March 2008
Location: United Kingdom
Senior Member
Hello BlackSwan

Thanks for the reply

Please find the results of the queries

SELECT count(*) FROM invoice_header inv1;
  COUNT(*)
----------
    120347


SELECT count(*) FROM invoice_header inv1 WHERE inv1.release = 'A5';
  COUNT(*)
----------
     55405



Thanks and Regards,
OraKaran
Re: Query Hanging with Sequential Read or Latch free Waits [message #502598 is a reply to message #502596] Thu, 07 April 2011 09:42 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
I would not expect the CBO to use the index in this situation; based upon number of rows returned.
There other part of the WHERE clause does not eliminate any additional rows; since selecting from same table.
Re: Query Hanging with Sequential Read or Latch free Waits [message #502600 is a reply to message #502568] Thu, 07 April 2011 09:47 Go to previous messageGo to next message
OraKaran
Messages: 183
Registered: March 2008
Location: United Kingdom
Senior Member
Hello BlackSwan

Quote:

I would not expect the CBO to use the index in this situation; based upon number of rows returned

Exactly

And there are no indexes

My questions are :
1) Is it full scanning inv1 for each row of inv?

2) What could be cause of 'sequential read' and 'latch free (cache buffer handles)' waits in this case which literally stalls the query?

Is the latch free because we are reading and writing to same segment?

Regards,
OraKaran
Re: Query Hanging with Sequential Read or Latch free Waits [message #502601 is a reply to message #502600] Thu, 07 April 2011 09:50 Go to previous messageGo to next message
cookiemonster
Messages: 13959
Registered: September 2008
Location: Rainy Manchester
Senior Member
OraKaran wrote on Thu, 07 April 2011 15:47
2) What could be cause of 'sequential read' and 'latch free (cache buffer handles)' waits in this case which literally stalls the query?

Unless that trace file is lying those waits aren't stalling anything - look at the total wait times.
Got any triggers on that table?
Re: Query Hanging with Sequential Read or Latch free Waits [message #502603 is a reply to message #502600] Thu, 07 April 2011 09:55 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Is the latch free because we are reading and writing to same segment?
Time is NOT spent on any "wait" event.
Time is spent on CPU!
Due to sampling error trace reports CPU Time > Elapsed Time!
Re: Query Hanging with Sequential Read or Latch free Waits [message #502612 is a reply to message #502568] Thu, 07 April 2011 10:16 Go to previous messageGo to next message
OraKaran
Messages: 183
Registered: March 2008
Location: United Kingdom
Senior Member
Hello BlackSwan and Cookiemonster

True that there are no waits and CPU has eaten up the time

There are no constraints or triggers on this table

Regards,
OraKaran
Re: Query Hanging with Sequential Read or Latch free Waits [message #502625 is a reply to message #502568] Thu, 07 April 2011 11:10 Go to previous messageGo to next message
OraKaran
Messages: 183
Registered: March 2008
Location: United Kingdom
Senior Member
Hello

In case you are interested I am attaching the trace file (saved as txt)

I am surprised by the section where it is difficult to know what 'ela' is representing. The elapsed time for the particular wait and time taken does not match

WAIT #3: nam='db file sequential read' ela= 878 p1=58 p2=66161 p3=1
*** 2011-04-07 13:50:17.780
WAIT #3: nam='latch free' ela= 2 p1=-4611686006009171952 p2=98 p3=0
*** 2011-04-07 13:51:03.181
WAIT #3: nam='latch free' ela= 3 p1=-4611686006013005480 p2=98 p3=0
*** 2011-04-07 13:53:01.108
WAIT #3: nam='latch free' ela= 302 p1=-4611686005523260160 p2=99 p3=0
*** 2011-04-07 13:54:19.363
WAIT #3: nam='latch free' ela= 33 p1=-4611686005523260160 p2=99 p3=0
*** 2011-04-07 13:55:23.132
WAIT #3: nam='latch free' ela= 1258 p1=-4611686005523260160 p2=99 p3=0
*** 2011-04-07 13:56:07.069
WAIT #3: nam='db file sequential read' ela= 75 p1=58 p2=66060 p3=1


I knew the wait event is 'latch free', I knew the corresponding Sql statement and session but there was hardly anything I could do.

There are many links, docs to 'Identify the type of Latch Wait' but very few which covers how to deal with it

Same puzzle is in the message 450352 dated 06-04-2010 in this forum

Regards,
OraKaran
Re: Query Hanging with Sequential Read or Latch free Waits [message #502627 is a reply to message #502625] Thu, 07 April 2011 11:18 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:409308200346402947
is session "spinning" while "waiting"?
Re: Query Hanging with Sequential Read or Latch free Waits [message #502703 is a reply to message #502568] Fri, 08 April 2011 04:04 Go to previous messageGo to next message
OraKaran
Messages: 183
Registered: March 2008
Location: United Kingdom
Senior Member
Hello BlackSwan

Thanks for the link

As mentioned in the link following seemed to happen in my case

Quote:

if the process cannot get a latch immediately, we will stay on the CPU and try again immediately rather than just going to sleep, giving up the CPU, and trying later when we¿ll have to get scheduled back on the CPU
..

.
Our system will appear to be very busy (with much CPU being consumed), but not much work is getting done.



May be my undrstanding is not much clear but when I think 'which latch' the process is trying in my case? and why?
I can think of reading / writing the blocks for the same segment

Since I can't send you the data I am facing issue with, I will try to simulate it in a test case and shall share it here

Thanks for your help

Regards,
OraKaran
Re: Query Hanging with Sequential Read or Latch free Waits [message #503325 is a reply to message #502703] Thu, 14 April 2011 09:09 Go to previous message
S.Rajaram
Messages: 1027
Registered: October 2006
Location: United Kingdom
Senior Member
Check this link and how to resolve/identify the bottlenecks.

http://tech.e2sn.com/oracle-scripts-and-tools/session-snapper

http://tech.e2sn.com/oracle/troubleshooting/latch-contention-troubleshooting

Hope it helps.

Regards

Raj
Previous Topic: subquery optimization (6 threads merged by bb)
Next Topic: Oracle : Client version < Database version.
Goto Forum:
  


Current Time: Thu Nov 28 13:00:34 CST 2024