[20171115]关于逻辑读的疑问.txt

简介: [20171115]关于逻辑读的疑问.txt --//有网友指出[20150209]为什么少1个逻辑读.txt,链接:http://blog.itpub.net/267265/viewspace-1430902/ --//如何验证是这样操作的.

[20171115]关于逻辑读的疑问.txt

--//有网友指出[20150209]为什么少1个逻辑读.txt,链接:http://blog.itpub.net/267265/viewspace-1430902/
--//如何验证是这样操作的.

1.环境:

SCOTT@test> @ver1

PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.3.0     Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

SCOTT@test> create table t3 as select rownum id,'test' data from dual connect by level<=100;
Table created.

SCOTT@test> alter table t3 minimize records_per_block;
Table altered.

--这样就实现每块100条记录.

SCOTT@test> insert into t3  select 100+rownum id,'test' data from dual connect by level<=400;
400 rows created.

SCOTT@test> commit ;
Commit complete.

--这样总共插入100条记录. 正好占满一个1个extents.(我使用assm,前面有L1,L2,以及段头),剩下仅仅5块.

SCOTT@test> select * from dba_extents where owner=user and segment_name='T3';
OWNER  SEGMENT_NAME  SEGMENT_TYPE  TABLESPACE_NAME  EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
------ ------------- ------------- ---------------- --------- ---------- ---------- ---------- ---------- ------------
SCOTT  T3            TABLE         USERS                    0          4        536      65536          8            4

--//分析表略.
--//首先说明为什么这样?
1.首先提取1条作为1个逻辑读,我感觉像是形成输出模板.
2.逻辑读不会跨块,我在源链接没有说明这点,vage的书上有说明.

--如果我设置array=98呢?
--读1,98,1 ,98,2, 96,4, 94,6, 92,8,这样在加上块头1个逻辑读(我使用11g的版本),应该是12个逻辑读.

--//以上计算存在错误,应该是:(感谢网友指正)
--//读1,98,1 ,97,3, 95,5, 93,7, 91,9,这样在加上块头1个逻辑读,应该是12个逻辑读.

2.验证问题:
SCOTT@book> alter session set statistics_level=all ;
Session altered.

select * from t3;
SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  8xs59s0kcpn57, child number 1
-------------------------------------
select * from t3
Plan hash value: 4161002650
--------------------------------------------------------------------------------------------------------------------
| Id  | Operation         | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers |
--------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |      1 |        |       |     4 (100)|          |    500 |00:00:00.01 |      12 |
|   1 |  TABLE ACCESS FULL| T3   |      1 |    500 |  4500 |     4   (0)| 00:00:01 |    500 |00:00:00.01 |      12 |
--------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / T3@SEL$1

--//网友另外的问题是如何验证确实是这样的情况呢? 使用10046跟踪,仅仅看到fetch的数量.
set array 98
@ &r/10046on 12
select * from t3;
@ &r/10046off

--//查看跟踪文件:
=====================
PARSING IN CURSOR #139637584924536 len=17 dep=0 uid=83 oct=3 lid=83 tim=1510707143940419 hv=539881914 ad='7c3af540' sqlid='7pm8xmnh2vwdu'
select * from t3
END OF STMT
PARSE #139637584924536:c=4000,e=4035,p=0,cr=8,cu=0,mis=1,r=0,dep=0,og=1,plh=4161002650,tim=1510707143940418
EXEC #139637584924536:c=0,e=24,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=4161002650,tim=1510707143940533
WAIT #139637584924536: nam='SQL*Net message to client' ela= 2 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143940613
FETCH #139637584924536:c=999,e=46,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=1,plh=4161002650,tim=1510707143940707
WAIT #139637584924536: nam='SQL*Net message from client' ela= 312 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143941086
WAIT #139637584924536: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143941153
FETCH #139637584924536:c=0,e=76,p=0,cr=1,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143941213
WAIT #139637584924536: nam='SQL*Net message from client' ela= 2462 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143943711
WAIT #139637584924536: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143943830
FETCH #139637584924536:c=0,e=78,p=0,cr=2,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143943895
WAIT #139637584924536: nam='SQL*Net message from client' ela= 2395 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143946326
WAIT #139637584924536: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143946395
FETCH #139637584924536:c=0,e=76,p=0,cr=2,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143946459
WAIT #139637584924536: nam='SQL*Net message from client' ela= 3601 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143950095
WAIT #139637584924536: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143950157
FETCH #139637584924536:c=0,e=73,p=0,cr=2,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143950218
WAIT #139637584924536: nam='SQL*Net message from client' ela= 3598 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143953880
WAIT #139637584924536: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143953940
FETCH #139637584924536:c=1000,e=72,p=0,cr=2,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143954000
WAIT #139637584924536: nam='SQL*Net message from client' ela= 3607 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143957641
WAIT #139637584924536: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707143957701
FETCH #139637584924536:c=0,e=55,p=0,cr=1,cu=0,mis=0,r=9,dep=0,og=1,plh=4161002650,tim=1510707143957744
STAT #139637584924536 id=1 cnt=500 pid=0 pos=1 obj=90670 op='TABLE ACCESS FULL T3 (cr=13 pr=0 pw=0 time=36 us cost=4 size=9500 card=500)'

*** 2017-11-15 08:52:31.840
WAIT #139637584924536: nam='SQL*Net message from client' ela= 7882935 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1510707151840765
CLOSE #139637584924536:c=0,e=21,dep=0,type=0,tim=1510707151840950
=====================

$ grep "FETCH #139637584924536" /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_63061.trc
FETCH #139637584924536:c=999,e=46,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=1,plh=4161002650,tim=1510707143940707
                                                      ~~~
FETCH #139637584924536:c=0,e=76,p=0,cr=1,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143941213
FETCH #139637584924536:c=0,e=78,p=0,cr=2,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143943895
FETCH #139637584924536:c=0,e=76,p=0,cr=2,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143946459
FETCH #139637584924536:c=0,e=73,p=0,cr=2,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143950218
FETCH #139637584924536:c=1000,e=72,p=0,cr=2,cu=0,mis=0,r=98,dep=0,og=1,plh=4161002650,tim=1510707143954000
FETCH #139637584924536:c=0,e=55,p=0,cr=1,cu=0,mis=0,r=9,dep=0,og=1,plh=4161002650,tim=1510707143957744

--//注意看r=..,从这里仅仅看出第一次提取1行(看下划线)

SCOTT@book> set autot traceonly
SCOTT@book> select * from t3;
500 rows selected.
Execution Plan
---------------------------
Plan hash value: 4161002650
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |   500 |  4500 |     4   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| T3   |   500 |  4500 |     4   (0)| 00:00:01 |
--------------------------------------------------------------------------
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         12  consistent gets
          0  physical reads
          0  redo size
       8458  bytes sent via SQL*Net to client
        574  bytes received via SQL*Net from client
          7  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
        500  rows processed

--//从SQL*Net roundtrips to/from client=7  仅仅看出网络往返的次数.与fetch的次数对应的.

--//如何查看呢?我仅仅知道10200事件,可以做到.其它不是很清楚.做一个验证看看:

$ oerr ora 10200
10200, 00000, "consistent read buffer status"
// *Cause:
// *Action:

set array 98
ALTER SESSION SET EVENTS '10200 TRACE NAME CONTEXT FOREVER, LEVEL 1';
select  *  from t3;
ALTER SESSION SET EVENTS '10200 TRACE NAME CONTEXT OFF';


SCOTT@book> @ &r/pp
TRACEFILE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/book/book/trace/book_ora_63220.trc

$ grep "started" /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_63220.trc
ktrget2(): started for block  <0x0004 : 0x01000223> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000223> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000223> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000224> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000224> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000225> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000225> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000226> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000226> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000227> objd: 0x0001622e
ktrget2(): started for block  <0x0004 : 0x01000227> objd: 0x0001622e
--//读1,98,1 ,97,3, 95,5, 93,7, 91,9,这样在加上块头1个逻辑读,应该是12个逻辑读.
--//但是仅仅看出读取块的顺序.

--//实际上还有1个简单的算法:
记录数量/array_size+block的数量.

SCOTT@book> set array 50
SCOTT@book> set autot traceonly
500 rows selected.
Execution Plan
---------------------------
Plan hash value: 4161002650
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |   500 |  4500 |     4   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| T3   |   500 |  4500 |     4   (0)| 00:00:01 |
--------------------------------------------------------------------------
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
         16  consistent gets
          0  physical reads
          0  redo size
       9202  bytes sent via SQL*Net to client
        618  bytes received via SQL*Net from client
         11  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
        500  rows processed
SCOTT@book> set autot off

--// 500/50+8 = 18 (与实际16相差2),块数量越多结果越接近.

目录
相关文章
文件IO操作的一些练习小案例
文件IO操作的一些练习小案例
148 0
|
C# 开发者
《编写高质量C#代码的50条有效方法》| 每日读本书
想成为一名高级的的.NET开发者需要深度理解C#编程语言所必需的Effective影印版系列书籍之一。此外本书的在代码编写上切实有效的建议以及代码设计都是非常有价值的。每日搜罗最具权威专业书籍,更多图书请关注“每日读本书”。
691 0
|
索引
[20180425]为什么走索引逻辑读反而高.txt
[20180425]为什么走索引逻辑读反而高.txt --//别人问的问题,自己测试看看,开始以为array设置太小.还是通过例子说明问题. 1.环境: SCOTT@book> @ ver1 PORT_STRING                    VE...
1039 0
|
关系型数据库 Oracle Linux
[20180410]为什么2个逻辑读不一样.txt
[20180410]为什么2个逻辑读不一样.txt --//昨天做测试时,发现一个小问题,链接http://blog.itpub.net/267265/viewspace-2152693/ --//发现2个逻辑读不一样,做一些简单探究.
935 0
|
XML C# 数据格式
读C#开发实战1200例子记录-2017年8月14日10:03:55
C# 语言基础应用,注释 "///"标记不仅仅可以为代码段添加说明,它还有一项更重要的工作,就是用于生成自动文档。自动文档一般用于描述项目,是项目更加清晰直观。在VisualStudio2015中可以通过设置项目属性来生成自动文档。
865 0
|
Linux C++
关于文件写入的原子性讨论
​   文件的写入是否是原子的?多个线程写入同一个文件是否会写错乱?多个进程写入同一个文件是否会写错乱?想必这些问题多多少少会对我们产生一定的困扰,即使知道结果,很多时候也很难将这其中的原理清晰的表达给提问者,侯捷曾说过,**源码面前,了无秘密**,那么本文也希望从源代码的角度分析上述问题。在开始之前我们需要补充一下Linux 文件相关的一些基础原理,便于更好的看懂Linux源
5638 0
|
SQL Oracle 关系型数据库
[20160528]快速提交的一个疑问2.txt
[20160528]快速提交的一个疑问2.txt --链接 http://blog.itpub.net/267265/viewspace-2108017/ --在上一次链接里面提到在快速提交时,itl槽的_ktbitun.
965 0
|
测试技术
[20160529]快速提交的一个疑问3.txt
[20160529]快速提交的一个疑问3.txt --链接 http://blog.itpub.net/267265/viewspace-2108017/ --在上一次链接里面提到在快速提交时,itl槽的_ktbitun.
886 0