12
返回列表 发新帖
楼主: kewin

SQL 已经使用了绑定变量,为啥parse call还这么高

[复制链接]
论坛徽章:
75
生肖徽章:猪
日期:2014-09-05 10:25:05指数菠菜纪念章
日期:2016-10-17 16:12:49生肖徽章:兔
日期:2015-02-05 16:49:02生肖徽章:鼠
日期:2015-02-05 16:49:02生肖徽章:鼠
日期:2015-02-05 16:49:02生肖徽章:马
日期:2015-02-05 16:49:02生肖徽章:羊
日期:2015-02-06 08:40:35生肖徽章:羊
日期:2015-02-06 08:40:34股神
日期:2015-01-05 08:27:16菲尼克斯太阳
日期:2014-12-29 13:11:51
11#
 楼主| 发表于 2011-8-18 10:21 | 只看该作者
写了while 循环来测试:

declare
i int;
begin
i := 1;
while i < 100 loop
execute immediate 'select count(*) from test';
i := i + 1;
end loop;
end ;



SQL> select executions, parse_calls, sql_text from  v$sql where sql_text like 'select count(*) from test';
;
EXECUTIONS PARSE_CALLS
---------- -----------
SQL_TEXT
--------------------------------------------------------------------------------
       203           7
select count(*) from test


SQL> declare
  2  i int;
begin
i := 1;
while i < 100 loop
execute immediate 'select count(*) from test';
i := i + 1;
end loop;
end ;
  3    4    5    6    7    8    9   10  
11  /

PL/SQL procedure successfully completed.

SQL> select executions, parse_calls, sql_text from  v$sql where sql_text like 'select count(*) from test';

EXECUTIONS PARSE_CALLS
---------- -----------
SQL_TEXT
--------------------------------------------------------------------------------
       302           8
select count(*) from test

在while循环中,parse 增加一次,execute 为99次。
no parse 发生在同一个 transaction 中; 在sqlplus 中,单独的去执行语句,oracle认为是不同的transaction ,所以每次都会增加soft parse .

使用道具 举报

回复
论坛徽章:
75
生肖徽章:猪
日期:2014-09-05 10:25:05指数菠菜纪念章
日期:2016-10-17 16:12:49生肖徽章:兔
日期:2015-02-05 16:49:02生肖徽章:鼠
日期:2015-02-05 16:49:02生肖徽章:鼠
日期:2015-02-05 16:49:02生肖徽章:马
日期:2015-02-05 16:49:02生肖徽章:羊
日期:2015-02-06 08:40:35生肖徽章:羊
日期:2015-02-06 08:40:34股神
日期:2015-01-05 08:27:16菲尼克斯太阳
日期:2014-12-29 13:11:51
12#
 楼主| 发表于 2011-8-18 10:27 | 只看该作者
而no parse受到 一个参数的影响 session_cached_cursors   
系统当前的 session_cached_cursors    为100.
SQL> show parameter cursor

NAME                                 TYPE
------------------------------------ ---------------------------------
VALUE
------------------------------
cursor_sharing                       string
EXACT
cursor_space_for_time                boolean
FALSE
open_cursors                         integer
1024
session_cached_cursors               integer
100      

在session 级别关闭  no parse 的选项:
SQL> alter session set session_cached_cursors= 0;

Session altered.

SQL> select executions, parse_calls, sql_text from  v$sql where sql_text like 'select count(*) from test';

EXECUTIONS PARSE_CALLS
---------- -----------
SQL_TEXT
--------------------------------------------------------------------------------
       302           8
select count(*) from test

再次执行一个匿名package:
SQL> declare
  2  i int;
begin
i := 1;
while i < 100 loop
execute immediate 'select count(*) from test';
i := i + 1;
end loop;
end ;
  3    4    5    6    7    8    9   10  
11  /

PL/SQL procedure successfully completed.

SQL> select executions, parse_calls, sql_text from  v$sql where sql_text like 'select count(*) from test';

EXECUTIONS PARSE_CALLS
---------- -----------
SQL_TEXT
--------------------------------------------------------------------------------
       302           8
select count(*) from test

        99          99
select count(*) from test  

看到oracle因为编译环境的变化,认为是个新的sql, 重新分配sql area 。 看到由于session_cache_cursor 的关系,导致产生了98 次soft  parse + 1次 hard parse。

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
13#
发表于 2011-8-19 01:14 | 只看该作者
Thanks for the test. Some of your wording may need to be changed.

> 在while循环中,parse 增加一次,execute 为99次。
> no parse 发生在同一个 transaction 中; 在sqlplus 中,单独的去执行语句,oracle认为是不同的transaction ,所以每次都会增加soft parse .

It's not transaction. It's the execution context, SQL vs. PL/SQL. Inside a PL/SQL block, the cursor is internally kept open in the session's private memory (UGA), as long as you didn't disable session cursor cache.

> 看到oracle因为编译环境的变化,认为是个新的sql, 重新分配sql area 。 看到由于session_cache_cursor 的关系,
> 导致产生了98 次soft  parse + 1次 hard parse。

I tested your code. A new cursor is created and v$sql_shared_cursor indicates the reason is TOP_LEVEL_RPI_CURSOR, which I don't fully understand. RPI is short for "Recursive Program Interface", basically a software layer for recursive calls. Disabling session cursor cache causes a new type of recursive call? Maybe. But I don't know the details.

Yong Huang

使用道具 举报

回复
论坛徽章:
75
生肖徽章:猪
日期:2014-09-05 10:25:05指数菠菜纪念章
日期:2016-10-17 16:12:49生肖徽章:兔
日期:2015-02-05 16:49:02生肖徽章:鼠
日期:2015-02-05 16:49:02生肖徽章:鼠
日期:2015-02-05 16:49:02生肖徽章:马
日期:2015-02-05 16:49:02生肖徽章:羊
日期:2015-02-06 08:40:35生肖徽章:羊
日期:2015-02-06 08:40:34股神
日期:2015-01-05 08:27:16菲尼克斯太阳
日期:2014-12-29 13:11:51
14#
 楼主| 发表于 2011-8-19 09:04 | 只看该作者
原帖由 Yong Huang 于 2011-8-19 01:14 发表
Thanks for the test. Some of your wording may need to be changed.

> 在while循环中,parse 增加一次,execute 为99次。
> no parse 发生在同一个 transaction 中; 在sqlplus 中,单独的去执行语句,oracle认为是不同的transaction ,所以每次都会增加soft parse .

It's not transaction. It's the execution context, SQL vs. PL/SQL. Inside a PL/SQL block, the cursor is internally kept open in the session's private memory (UGA), as long as you didn't disable session cursor cache.

> 看到oracle因为编译环境的变化,认为是个新的sql, 重新分配sql area 。 看到由于session_cache_cursor 的关系,
> 导致产生了98 次soft  parse + 1次 hard parse。

I tested your code. A new cursor is created and v$sql_shared_cursor indicates the reason is TOP_LEVEL_RPI_CURSOR, which I don't fully understand. RPI is short for "Recursive Program Interface", basically a software layer for recursive calls. Disabling session cursor cache causes a new type of recursive call? Maybe. But I don't know the details.

Yong Huang


Thanks your comment. I thought about sql area but didn't  look at related view.
I will do advanced test if I am avaiable today.
Thanks again.

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表