Oracle FAQ Your Portal to the Oracle Knowledge Grid

Home -> Community -> Mailing Lists -> Oracle-L -> Does EXEC do a FETCH?

Does EXEC do a FETCH?

From: Henry Poras <>
Date: Fri, 13 Jul 2007 14:15:09 -0400
Message-ID: <000201c7c579$c17c1e00$>

I've been spending some time on my system trying to do time accounting by comparing output from sqlnet trace files and 10046 traces. While doing this, I've realized I don't understand what is going on with the EXEC and FETCH calls with simple SELECT statements. (this is on a db RedHat 2.6.9)

I ran a simple test case which returned a single record. From looking at the 10046 trace it appears as though the data is sent to the client before the FETCH call. Huh? Is the initial FETCH actually coupled with the EXEC and just broken out in the trace file at a later time?

PARSING IN CURSOR #2 len=53 dep=0 uid=40 oct=3 lid=40 tim=1156580450666631 hv=1459047207 ad='9ae399a8'
select /* fetch test */ ename
from emp
where rownum=1
EXEC #2:c=0,e=39,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=1156580450666729 WAIT #2: nam='SQL*Net message to client' ela= 4 driver id=1413697536
#bytes=1 p3=0 obj#=-1 tim=1156580450666769 <===
FETCH #2:c=0,e=59,p=0,cr=5,cu=0,mis=0,r=1,dep=0,og=1,tim=1156580450666858 <===
WAIT #2: nam='SQL*Net message from client' ela= 1253 driver id=1413697536
#bytes=1 p3=0 obj#=-1 tim=1156580450668168
FETCH #2:c=0,e=2,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=1156580450668205 WAIT #2: nam='SQL*Net message to client' ela= 1 driver id=1413697536
#bytes=1 p3=0 obj#=-1 tim=1156580450668226
*** 2007-07-13 10:53:12.998
WAIT #2: nam='SQL*Net message from client' ela= 11244427 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1156580461912676 STAT #2 id=1 cnt=1 pid=0 pos=1 obj=0 op='COUNT STOPKEY (cr=5 pr=0 pw=0 time=55 us)'
STAT #2 id=2 cnt=1 pid=1 pos=1 obj=48029 op='TABLE ACCESS FULL EMP (cr=5 pr=0 pw=0 time=43 us)'

So after the EXEC, a packet is sent to the client followed by a FETCH of one record (r=1). After getting confirmation back from the client (message from client wait), sqlplus does its final FETCH confirming no more data, and sends this to the client (message to client). The client then responds with the next sql to parse.

Looking at the sqlnet trace (level=SUPPORT), I see the following packets:

  1. nspsend of the SQL (after getting this, the PARSE should happen)
  2. nsprecv of the result set (header information [ENAME], and the data [SMITH]) This is connected to the 'SQL*Net message to client' wait immediately following the EXEC
  3. nspend (plen=21). I assume this is confirmation of receipt of the data packet
  4. nsprecv of packet containing ORA-01403 no data found
  5. nspsend of next SQL

So the data is sent from the server to the client prior to the initial FETCH. The second FETCH confirms no more data and that is sent to the client after the FETCH.

I am wondering if the initial EXEC actually does EXEC and FETCH, and the explicit FETCH call is just bookkeeping, not the real work. Maybe the Oracle kernal changed the way it does its work, but the 10046 display hasn't been adjusted accordingly.

Has anyone else seen this? Are there any other explanations?



Received on Fri Jul 13 2007 - 13:15:09 CDT

Original text of this message