[20160202]dblink与父子游标.txt

[20160202]dblink与父子游标.txt

--昨天遇到1一个bug,在10g下,如果设置参数cursor_sharing=force的情况下,如果访问远程表带文字变量,转成带参后,出现大量子
--光标的问题。链接如下:
http://blog.itpub.net/267265/viewspace-1985215/

--今天看看这样的sql语句在本地的共享池情况。

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

CREATE PUBLIC DATABASE LINK loopback USING 'localhost:1521/book';

2.测试:

SCOTT@book> select * from dept@loopback where deptno=10;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK

SCOTT@book> @ &r/dpcz ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  d34tsffmd6tgv, child number 0

select * from dept@loopback where deptno=10

NOTE: cannot fetch plan for SQL_ID: d34tsffmd6tgv, CHILD_NUMBER: 0
      Please verify value of SQL_ID and CHILD_NUMBER;
      It could also be that the plan is no longer in cursor cache (check v$sql_plan)
8 rows selected.

--如果查询执行计划会出现如上的错误,实际远端执行如下。

SELECT "A1"."DEPTNO", "A1"."DNAME", "A1"."LOC"
  FROM "DEPT" "A1"
WHERE "A1"."DEPTNO" = 10;

3.观察父游标情况:

SYS@book> @ &r/sharepool/shp4 d34tsffmd6tgv

TEXT           KGLHDADR         KGLHDPAR         C40                                      KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16  N0_6_16        N20   KGLNAHSH KGLOBT03
-------------- ---------------- ---------------- ---------------------------------------- ---------------- ---------------- ---------- ---------- ---------- -------- ---------- ---------- -------------
子游标句柄地址 0000000066F47FC0 0000000066F48350 select * from dept@loopback where deptno 0000000062652750 0000000069D196B0       4488       8088       3076    15652      15652 2798872059 d34tsffmd6tgv
父游标句柄地址 0000000066F48350 0000000066F48350 select * from dept@loopback where deptno 0000000066E87EA0 00                     4736          0          0     4736       4736 2798872059 d34tsffmd6tgv

--父游标:
new   1: SELECT * FROM x$ksmsp WHERE TO_NUMBER ('0000000066F48350', 'xxxxxxxxxxxxxxxx') between TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx') and TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx')+KSMCHSIZ
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D33D7B8      58041          1          1          2 KGLHD            0000000066F48320        576 recr             80 00

--父游标堆0:
new   1: select a.*,dump(a.KSMCHCOM,16) c60 from x$ksmsp a where a.ksmchpar='0000000066E87EA0'
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR        
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D020F38      31891          1          1          3 KGLH0^a6d365fb   0000000069D18F40       4096 recr           4095 0000000066E87EA0

--父游标堆0的DS描述符:
new   1: SELECT * FROM x$ksmsp WHERE TO_NUMBER ('0000000066E87EA0', 'xxxxxxxxxxxxxxxx') between TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx') and TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx')+KSMCHSIZ
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D303D50      59585          1          1          2 KGLDA            0000000066E87E38        240 freeabl           0 00

4.观察子游标情况:
--子游标:
new   1: SELECT * FROM x$ksmsp WHERE TO_NUMBER ('0000000066F47FC0', 'xxxxxxxxxxxxxxxx') between TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx') and TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx')+KSMCHSIZ
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D33EE00      58022          1          1          2 KGLHD            0000000066F47F90        368 recr             80 00

--子游标堆0:
new   1: select a.*,dump(a.KSMCHCOM,16) c60 from x$ksmsp a where a.ksmchpar='0000000062652750'
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR        
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D020EE0      31892          1          1          3 KGLH0^a6d365fb   0000000069D17F40       4096 recr           4095 0000000062652750

--子游标堆0的DS描述符:
new   1: SELECT * FROM x$ksmsp WHERE TO_NUMBER ('0000000062652750', 'xxxxxxxxxxxxxxxx') between TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx') and TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx')+KSMCHSIZ
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D1FE6C8      44243          1          1          2 KGLDA            00000000626526E8        240 freeabl           0 00

--子游标堆6:
new   1: select a.*,dump(a.KSMCHCOM,16) c60 from x$ksmsp a where a.ksmchpar='0000000069D196B0'
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR        
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D1AA248      14401          1          1          4 SQLA^a6d365fb    00000000688D7CF0       4096 recr           4095 0000000069D196B0
00007FF13D1AA1F0      14402          1          1          4 SQLA^a6d365fb    00000000688D6CF0       4096 freeabl           0 0000000069D196B0

--可以发现比访问本地表少1个chunk。

--子游标堆6的DS描述符,可以发现在父游标堆0中。
new   1: SELECT * FROM x$ksmsp WHERE TO_NUMBER ('0000000069D196B0', 'xxxxxxxxxxxxxxxx') between TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx') and TO_NUMBER(KSMCHPTR, 'xxxxxxxxxxxxxxxx')+KSMCHSIZ
ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D020F38      31891          1          1          3 KGLH0^a6d365fb   0000000069D18F40       4096 recr           4095 0000000066E87EA0

--除了堆6少1个chunk,其他基本一样,估计就是少了执行计划。

select * from dept@loopback,dual where deptno=10;

sql_id=9bwxnfwkzrar2

SYS@book> @ &r/sharepool/shp4 9bwxnfwkzrar2
TEXT           KGLHDADR         KGLHDPAR         C40                                      KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16  N0_6_16        N20   KGLNAHSH KGLOBT03
-------------- ---------------- ---------------- ---------------------------------------- ---------------- ---------------- ---------- ---------- ---------- -------- ---------- ---------- -------------
子游标句柄地址 0000000064655F68 0000000066ED19D8 select * from dept@loopback,dual where d 00000000852BEBA8 0000000063721770       4504      12144       3081    19729      19729  637250274 9bwxnfwkzrar2
父游标句柄地址 0000000066ED19D8 0000000066ED19D8 select * from dept@loopback,dual where d 000000007C0810A0 00                     4736          0          0     4736       4736  637250274 9bwxnfwkzrar2

SYS@book> @ &r/sharepool/shp3 0000000063721770
select a.* from x$ksmsp a where a.ksmchptr='0000000063721770'
no rows selected

select a.* from x$ksmsp a where a.ksmchpar='0000000063721770'

ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR         C60
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ---------------- ------------------------------------------------------------
00007FF13CED99C0        446          1          1          4 SQLA^25fbaae2    000000007CA52738       4096 recr           4095 0000000063721770 Typ=1 Len=13: 53,51,4c,41,5e,32,35,66,62,61,61,65,32
00007FF13CE614A8       6351          1          1          4 SQLA^25fbaae2    000000006535E000       4096 freeabl           0 0000000063721770 Typ=1 Len=13: 53,51,4c,41,5e,32,35,66,62,61,61,65,32
00007FF13CE2E300       8287          1          1          4 SQLA^25fbaae2    0000000065BED000       4096 freeabl           0 0000000063721770 Typ=1 Len=13: 53,51,4c,41,5e,32,35,66,62,61,61,65,32

ADDR                   INDX    INST_ID   KSMCHIDX   KSMCHDUR KSMCHCOM         KSMCHPTR           KSMCHSIZ KSMCHCLS   KSMCHTYP KSMCHPAR
---------------- ---------- ---------- ---------- ---------- ---------------- ---------------- ---------- -------- ---------- ----------------
00007FF13D0C0D28      24220          1          1          3 KGLH0^25fbaae2   0000000063721000       4096 recr           4095 000000007C0810A0

--可以看出能看到执行计划的在堆6中多1个chunk,估计执行计划就在那个chunk中。

时间: 2024-10-22 10:50:37

[20160202]dblink与父子游标.txt的相关文章

20150213关于共享池4-SQL内存结构父子游标

[20150213]关于共享池4x-SQL内存结构父子游标.txt --这个主要和recr和freeabl类似. --1.节约内存 --2.减少检索链表的时间. --3.oracle的算法规定,sql语句必须至少是一父一子的情况.很多情况下都是一父多子.也就是说,每个游标,oracle都会为它设置个父游标 --  如果有sql文本相同,但无法共享执行计划的情况出现,那就会出现一父多子的情况. --注意除了sql对象,共享池中其它类型的对象都没有父子游标的概念. --自己按照的介绍,重复测试一遍,

20151223关于共享池4x-SQL内存结构父子游标

[20151223]关于共享池4x-SQL内存结构父子游标.txt --重复测试:http://blog.itpub.net/267265/viewspace-1436541/ --这个主要和recr和freeabl类似. --1.节约内存 --2.减少检索链表的时间. --3.oracle的算法规定,sql语句必须至少是一父一子的情况.很多情况下都是一父多子.也就是说,每个游标,oracle都会为它设置个父游标 --  如果有sql文本相同,但无法共享执行计划的情况出现,那就会出现一父多子的情

[20161228]sql语句父子游标的堆转储2.txt

[20161228]sql语句父子游标的堆转储2.txt --以前仅仅看了父游标堆0的堆转储,链接:http://blog.itpub.net/267265/viewspace-2076605/ --尽然当时没有做子游标堆0,6的堆转储,今天测试看看. 1.环境: SYS@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -----------

[20160407]sql语句父子游标的堆转储.txt

[20160407]sql语句父子游标的堆转储.txt --昨天晚上看一些文档,发现可以通过alter session set events 'immediate trace name heapdump_addr level 2,addr 0xXXXXXXXX'; --后面加堆地址,转储里面的内容.自己测试看看: --另外补充说明一下: 我看了jonathan lewis <oracle核心技术> 里面提到ds 应该是 data segment. 1.环境: SCOTT@book> @

[20160215]超长sql语句与父子光标.txt

[20160215]超长sql语句与父子光标.txt --看<oracle内核技术揭秘>提到sql语句不会进入保留池, 要进入保留池,chunk的大小必须大于_shared_pool_reserved_min_alloc. --而实际上许多sql语句一般最大4096字节.而且这些内存分配的原则是首先从共享池分配,不行并且大于 --shared_pool_reserved_min_alloc才会从保留池申请. --作者视乎忘记一种特殊情况就是超长sql语句,这样父游标保存sql的语句chunk可

1229关于共享池4-SQL内存结构父子游标补充3

[20151229]关于共享池4x-SQL内存结构父子游标 (补充3).txt -- 前几天的测试,还是有点问题,链接如下: -- http://blog.itpub.net/267265/viewspace-1942280/ -- 继续做1点补充: 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ ----------

1224关于共享池4SQL内存结构父子游标补充

[20151224]关于共享池4x-SQL内存结构父子游标 (补充).txt --昨天的测试存在一点小问题,补充说明一下: 1.环境: SYS@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- -------------------------------------------------------------

[20161230]查看父游标中sql语句.txt

[20161230]查看父游标中sql语句.txt --上午巡检完,无聊,测试使用oradebug下查看sql语句在父游标中的内容.sql语句在执行第一次硬解析时生成父子游标,其中父游标chunk --中保存sql语句,测试通过oradebug下如何查看: 1.环境: SCOTT@book> select * from dept where deptno=10;     DEPTNO DNAME          LOC ---------- -------------- -----------

[20171005]parsing.txt

[20171005]parsing.txt --//如果一条sql语句输入有错,会在sharepool存在记录.参考链接: --//jonathanlewis.wordpress.com/2017/10/03/parsing/ 1.环境: SCOTT@test01p> @ ver1 PORT_STRING                    VERSION        BANNER