[20170308]直接路径读特例.txt

简介: [20170308]直接路径读特例.txt --//昨天测试一些sql语句时,无意中发现出现直接路径读的一种特殊情况,就是使用rowid访问数据块(使用between).

[20170308]直接路径读特例.txt

--//昨天测试一些sql语句时,无意中发现出现直接路径读的一种特殊情况,就是使用rowid访问数据块(使用between).而且还发现一些我无
--//法解析的情况.通过例子说明:

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SCOTT@book> select rowid,dept.* from dept;
ROWID                    DEPTNO DNAME          LOC
------------------ ------------ -------------- -------------
AAAVRCAAEAAAACHAAA           10 ACCOUNTING     NEW YORK
AAAVRCAAEAAAACHAAB           20 RESEARCH       DALLAS
AAAVRCAAEAAAACHAAC           30 SALES          CHICAGO
AAAVRCAAEAAAACHAAD           40 OPERATIONS     BOSTON

SCOTT@book> @ &r/rowid AAAVRCAAEAAAACHAAA
      OBJECT         FILE        BLOCK          ROW ROWID_DBA            DBA                  TEXT
------------ ------------ ------------ ------------ -------------------- -------------------- ----------------------------------------
       87106            4          135            0  0x1000087           4,135                alter system dump datafile 4 block 135 ;

SCOTT@book> alter session set statistics_level=all;
Session altered.

SCOTT@book> select rowid,dept.* from dept where rowid between 'AAAVRCAAEAAAACHAAA' and 'AAAVRCAAEAAAACHAAB';
ROWID                    DEPTNO DNAME          LOC
------------------ ------------ -------------- -------------
AAAVRCAAEAAAACHAAA           10 ACCOUNTING     NEW YORK
AAAVRCAAEAAAACHAAB           20 RESEARCH       DALLAS

SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  5pang9x5by7p5, child number 0
-------------------------------------
select rowid,dept.* from dept where rowid between 'AAAVRCAAEAAAACHAAA' and 'AAAVRCAAEAAAACHAAB'
Plan hash value: 4056682038
------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                   | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers |
------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |      |      1 |        |       |     3 (100)|          |      2 |00:00:00.01 |       3 |
|*  1 |  TABLE ACCESS BY ROWID RANGE| DEPT |      1 |      1 |    20 |     3   (0)| 00:00:01 |      2 |00:00:00.01 |       3 |
------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / DEPT@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access(ROWID>='AAAVRCAAEAAAACHAAA' AND ROWID<='AAAVRCAAEAAAACHAAB')

--//当前3个逻辑读是正确的,我不知道为什么?安装我的理解应该是2.但是如果该块不再数据缓存.就会出现物理读的情况.

2.测试:
--//首先刷新数据缓存.
SCOTT@book> alter system flush buffer_cache;
System altered.

SCOTT@book> alter system flush buffer_cache;
System altered.

SCOTT@book> select rowid,dept.* from dept where rowid between 'AAAVRCAAEAAAACHAAA' and 'AAAVRCAAEAAAACHAAB';
ROWID                    DEPTNO DNAME          LOC
------------------ ------------ -------------- -------------
AAAVRCAAEAAAACHAAA           10 ACCOUNTING     NEW YORK
AAAVRCAAEAAAACHAAB           20 RESEARCH       DALLAS

SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  5pang9x5by7p5, child number 0
-------------------------------------
select rowid,dept.* from dept where rowid between 'AAAVRCAAEAAAACHAAA'
and 'AAAVRCAAEAAAACHAAB'
Plan hash value: 4056682038
---------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                   | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers | Reads  |
---------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |      |      1 |        |       |     3 (100)|          |      2 |00:00:00.01 |       3 |      2 |
|*  1 |  TABLE ACCESS BY ROWID RANGE| DEPT |      1 |      1 |    20 |     3   (0)| 00:00:01 |      2 |00:00:00.01 |       3 |      2 |
---------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / DEPT@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - access(ROWID>='AAAVRCAAEAAAACHAAA' AND ROWID<='AAAVRCAAEAAAACHAAB')
--//reads=2

--//以后再次执行,都会存在一个物理读(除非该块进入数据缓存).
Plan hash value: 4056682038
---------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                   | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers | Reads  |
---------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |      |      1 |        |       |     3 (100)|          |      2 |00:00:00.01 |       3 |      1 |
|*  1 |  TABLE ACCESS BY ROWID RANGE| DEPT |      1 |      1 |    20 |     3   (0)| 00:00:01 |      2 |00:00:00.01 |       3 |      1 |
---------------------------------------------------------------------------------------------------------------------------------------

SYS@book> @ &r/bh 4 135

HLADDR              DBARFIL     DBABLK      CLASS CLASS_TYPE         STATE             TCH CR_SCN_BAS CR_SCN_WRP CR_UBA_FIL CR_UBA_BLK CR_UBA_SEQ BA               OBJECT_NAME
---------------- ---------- ---------- ---------- ------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------------- --------------------
0000000084A58490          4        135          1 data block         free                0          0          0          0          0          0 000000006C16A000 DEPT
0000000084A58490          4        135          1 data block         free                0          0          0          0          0          0 0000000066FB8000 DEPT
--//当前没有缓存.

3.跟踪分析:
SCOTT@book> @ &r/10046on 12
Session altered.

SCOTT@book> select rowid,dept.* from dept where rowid between 'AAAVRCAAEAAAACHAAA' and 'AAAVRCAAEAAAACHAAB';
ROWID                    DEPTNO DNAME          LOC
------------------ ------------ -------------- -------------
AAAVRCAAEAAAACHAAA           10 ACCOUNTING     NEW YORK
AAAVRCAAEAAAACHAAB           20 RESEARCH       DALLAS

SCOTT@book> @ &r/10046off
Session altered.

--//查看跟踪
=====================
PARSING IN CURSOR #140416991265296 len=95 dep=0 uid=83 oct=3 lid=83 tim=1488934054181670 hv=1254039205 ad='7d9cd7b8' sqlid='5pang9x5by7p5'
select rowid,dept.* from dept where rowid between 'AAAVRCAAEAAAACHAAA' and 'AAAVRCAAEAAAACHAAB'
END OF STMT
PARSE #140416991265296:c=0,e=27,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=4056682038,tim=1488934054181668
EXEC #140416991265296:c=0,e=30,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=4056682038,tim=1488934054181800
WAIT #140416991265296: nam='SQL*Net message to client' ela= 2 driver id=1650815232 #bytes=1 p3=0 obj#=87106 tim=1488934054181878
WAIT #140416991265296: nam='direct path read' ela= 18 file number=4 first dba=135 block cnt=1 obj#=87106 tim=1488934054182309
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FETCH #140416991265296:c=1000,e=484,p=1,cr=2,cu=0,mis=0,r=1,dep=0,og=1,plh=4056682038,tim=1488934054182446
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=> 不明白为什么cr=2
WAIT #140416991265296: nam='SQL*Net message from client' ela= 325 driver id=1650815232 #bytes=1 p3=0 obj#=87106 tim=1488934054182847
WAIT #140416991265296: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=87106 tim=1488934054182919
FETCH #140416991265296:c=0,e=57,p=0,cr=1,cu=0,mis=0,r=1,dep=0,og=1,plh=4056682038,tim=1488934054182960
STAT #140416991265296 id=1 cnt=2 pid=0 pos=1 obj=87106 op='TABLE ACCESS BY ROWID RANGE DEPT (cr=3 pr=1 pw=0 time=490 us cost=3 size=20 card=1)'
*** 2017-03-08 08:47:36.854
WAIT #140416991265296: nam='SQL*Net message from client' ela= 2671223 driver id=1650815232 #bytes=1 p3=0 obj#=87106 tim=1488934056854277
CLOSE #140416991265296:c=0,e=15,dep=0,type=3,tim=1488934056854384
=====================

4.最后1点:
--//一直不明白为什么逻辑读是3,哪位知道???
--//使用rowid='AAAVRCAAEAAAACHAAA'就没有这种情况.

目录
相关文章
|
7月前
|
C++
C++学习系列---读取文件名存入txt和从txt读取每行信息
C++学习系列---读取文件名存入txt和从txt读取每行信息
|
Shell Perl
将当前目录下大于 10K 的文件转移到 /tmp 目录,再按照文件大小顺序,从大到小输出文件名。
将当前目录下大于 10K 的文件转移到 /tmp 目录,再按照文件大小顺序,从大到小输出文件名。
122 2
|
Java
IO案例,集合到文件数据排序、复制单级和多级文件夹及复制文件的异常处理
IO案例,集合到文件数据排序、复制单级和多级文件夹及复制文件的异常处理的简单示例
77 1
IO案例,集合到文件数据排序、复制单级和多级文件夹及复制文件的异常处理
|
Linux Windows
路径中,连续多个目录分隔符不影响,仍按照一个处理
路径中,连续多个目录分隔符不影响,仍按照一个处理
102 0
编写一个程序,如果名为Exercise12_15.txt的文件不存在,则创建该文件。使用文本I/O将随机产生的100个整数写入文件,文件中的整数由空格分开。从文件中读回数据并以升序显示数据。
编写一个程序,如果名为Exercise12_15.txt的文件不存在,则创建该文件。使用文本I/O将随机产生的100个整数写入文件,文件中的整数由空格分开。从文件中读回数据并以升序显示数据。
291 0
读取文件结束的判定的概念,使用方法和文件缓冲区的位置
读取文件结束的判定的概念,使用方法和文件缓冲区的位置
137 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
|
SQL Oracle 关系型数据库
[20180319]直接路径读特例12c.txt
[20180319]直接路径读特例12c.txt --//昨天的测试突然想起以前遇到的直接路径读特例,在12c重复测试看看. 1.环境: SCOTT@test01p> @ ver1 PORT_STRING                    VERSION...
981 0
|
缓存 网络协议 关系型数据库
[20180316]共享服务模式和直接路径读.txt
[20180316]共享服务模式和直接路径读.txt --//在共享服务器模式下,执行计划不会选择直接路径读,通过例子证明. 1.环境: SYS@book> @ &r/ver1 PORT_STRING          VERSION    BANNER...
873 0