总结,arraysize<=SDU size, CTAS方式创建的测试表执行select前后:
logical reads从4537->4541,共4次,其中2次用于读取segment header,1次用于读取表里的第一行,1次用于读取block里的剩余行
SQL*Net message to client从139->142,共3次,其中1次用于将表里的第一行数据从buffer cache复制到PGA前,Server process通知client准备接收服务器端返回的第一行数据;1次用于将表中block里除第一行外的剩余行从buffer cache复制到PGA前,Server process通知client准备接收服务器端返回的剩余行数据;另1次的用途未知;读取segment header时不会产生"SQL*Net message to client"事件,因为客户端请求访问的永远是表里的数据而不是段头信息。
SQL*Net message from client从138->141,共3次,其中1次用于client向server发送命令,1次在用于Server process将PGA里的第一行数据返回给client后client给server process的确认响应,1次用于Server process将PGA里该block里的剩余数据返回给client后client给server process的确认响应。
上述场景使用的测试表scott.t1里的记录是在CTAS建表的同时插入进来的,实践发现与CTAS创建完空表后再用insert into插入记录所形成的测试表其在SQL*Net事件的等待次数上有所差异
(2) arraysize<=SDU size, CTAS方式创建空表,之后使用insert into语句往这张空表插入记录
---session 1: 创建测试表
create tablespace ts0111 datafile '/oradata06/testaaaaa/ts0111.dbf' size 32m segment space management auto;
create table scott.t11 tablespace ts0111 as select * from all_users where 1=2;
insert into scott.t11 select * from all_users;
SQL> select header_file,header_block from dba_segments where segment_name='T11' and owner='SCOTT';
HEADER_FILE HEADER_BLOCK
----------- ------------
5 154 <---segment header
SELECT distinct DBMS_ROWID.rowid_block_number(rowid),DBMS_ROWID.rowid_relative_fno(rowid) from scott.t11 ;
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID)
------------------------------------ ------------------------------------
159 5 <---真正存放数据的块仅一个
---session 2: 获取session基本信息,确认所有行的长度和<SDU_SIZE,SDU_SIZE默认情况下是8192字节
select sum(length(user_id)+length(username)+length(created)) from scott.t1 ; <---确保所有记录总长<默认的SDU值8192字节,否则会出现SQL*NET more data to client事件,后面会有专针对于SQL*NET more data to client的讨论
SUM(LENGTH(USER_ID)+LENGTH(USERNAME)+LENGTH(CREATED))
-----------------------------------------------------
550
SQL> select p.spid,s.sid,s.serial# from v$session s,v$process p where s.sid=sys_context('userenv','sid') and s.paddr=p.addr;
SPID SID SERIAL#
------------------------ ---------- ----------
5374224 467 3927
---session 3:记录session 2的执行前的SQL*NET等待事件和logical reads次数,x$bh中的touch count,并且执行flush buffer_cache
set linesize 120
col event format a40
select sid,event,total_waits,time_waited from v$session_event where sid=467 and event in ('SQL*Net message to client','SQL*Net message from client','SQL*Net more data to client');
SID EVENT TOTAL_WAITS TIME_WAITED
---------- ---------------------------------------- ----------- -----------
467 SQL*Net message to client 42 0
467 SQL*Net message from client 41 108403