oracle绑定变量测试及性能对比
1.创建测试数据
2.查看cursor_sharing的值
SQL> show parameter cursor_sharing; NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cursor_sharing string EXACT
3.打开SQL追踪
SQL> alter session set sql_trace=true; Session altered. SQL> select value from v$diag_info where name='Default Trace File'; VALUE
--------------------------------------------------------------------------------
/oracle/diag/rdbms/monkey/monkey/trace/monkey_ora_26356.trc
4.执行语句块(使用绑定变量)
SQL> begin
2 for x in 1..10000 loop
3 execute immediate 'select * from monkey.testtable where id=:x' using x;
4 end loop;
5 end;
6 /
5.关闭SQL追踪
SQL> alter session set sql_trace=false; Session altered.
6.格式化trace文件
$ cd /oracle/diag/rdbms/monkey/monkey/trace/
$ tkprof monkey_ora_26356.trc out.txt
$ more out.txt
7.结果
select *
from
monkey.testtable where id=:x call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 10000 0.03 0.03 0 1 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 10001 0.03 0.03 0 1 0 0 Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS (recursive depth: 1)
Number of plan statistics captured: 1 OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 3 0.00 0.01 0 0 0 0
Execute 4 0.16 0.16 0 0 0 1
Fetch 2 0.00 0.01 0 0 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 9 0.16 0.19 0 0 0 2 Misses in library cache during parse: 3
Misses in library cache during execute: 1 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 0 0 0
Execute 10001 0.03 0.03 0 1 0 0
Fetch 1 0.00 0.00 0 75 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 10004 0.03 0.03 0 76 0 1
從最後的整體統計可以看到,包括執行產生的遞歸和非遞歸類SQL,總共解析了5次,花費了0.22秒
8.执行语句块(不适用绑定变量)
SQL> begin
2 for x in 1..10000 loop
3 execute immediate 'select * from monkey.testtable where id ='||x;
4 end loop;
5 end;
6 /
9.结果
select *
from
monkey.testtable where id =1 call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 1 0 0 Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS (recursive depth: 1)
Number of plan statistics captured: 1 SQL ID: 2q3s22f8bw5wx Plan Hash: 2994338341 SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS IGNORE_WHERE_CLAUSE
NO_PARALLEL(SAMPLESUB) opt_param('parallel_execution_enabled', 'false')
NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE */ NVL(SUM(C1),0), NVL(SUM(C2),0)
FROM
(SELECT /*+ IGNORE_WHERE_CLAUSE NO_PARALLEL("TESTTABLE") FULL("TESTTABLE")
NO_PARALLEL_INDEX("TESTTABLE") */ 1 AS C1, CASE WHEN "TESTTABLE"."ID"=2
THEN 1 ELSE 0 END AS C2 FROM "monkey"."TESTTABLE" SAMPLE BLOCK (1.065089 ,
1) SEED (1) "TESTTABLE") SAMPLESUB call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 75 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 3 0.00 0.00 0 75 0 1 select *
from
monkey.testtable where id =2 call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 1 0 0 Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS (recursive depth: 1)
Number of plan statistics captured: 1 select *
from
monkey.testtable where id =3 call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 1 0 0 Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS (recursive depth: 1)
Number of plan statistics captured: 1 總這裡可以看到,每一個值都解析了一遍,並且每一個值都要對表進行採樣
..............................................
select *
from
monkey.testtable where id =10000 call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 1 0 0 Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: SYS (recursive depth: 1)
Number of plan statistics captured: 1 OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 0 0 0
Execute 3 0.69 0.70 0 0 0 1
Fetch 2 0.00 0.02 0 0 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 7 0.69 0.72 0 0 0 2 Misses in library cache during parse: 1
Misses in library cache during execute: 1 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 20000 9.86 9.91 0 10000 0 0
Execute 20000 0.19 0.16 0 0 0 0
Fetch 10000 10.60 10.60 0 750000 0 10000
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 50000 20.65 20.68 0 760000 0 10000
從最後的整體統計可以看到,包括執行產生的遞歸和非遞歸類SQL,總共解析了20002次,花費了21.4秒
oracle绑定变量测试及性能对比的更多相关文章
- SQL优化 | Oracle 绑定变量
之前整理过一篇有关绑定变量的文章,不太详细,重新补充一下. Oracle 绑定变量 http://www.cndba.cn/Dave/article/1275 一.绑定变量 bind variable ...
- ORACLE绑定变量隐式转换导致性能问题
年后一次系统升级后,监控数据库的工具DPA发现数据库的Total Wait时间突然飙增,如下截图所示,数据库的总体等待时间对比升级前飙增了非常多 另外就是发现出现了较多的等待事件,主要有latch: ...
- oracle 绑定变量
“绑定变量”这个词也许对于某些人来说看以来陌生,其实我们在很早的时候就已经开始运用它了. 在java中使用的PrepareStatement对象,大家一定会说这不是将sql语句做预编译操作嘛,被封装的 ...
- Oracle绑定变量
select * from table where id = ? 类似于上面这样的sql,如果不用绑定变量,每次执行时Oracle会认为是不同的sql,会在每次执行时生成一遍执行计划,而执行计划的生成 ...
- Oracle绑定变量在C#.NET中的应用及意义
一. 什么是绑定变量 绑定变量(bind variable) : select * from emp where empno=:empno; 是用户放入查询中的占位符,它会告诉Oracle“我会随后为 ...
- Oracle 绑定变量窥视
绑定变量窥视功能是数据库的一个特性,自ORACLE9i版本开始引入,默认是开启的. “绑定变量窥视”表示,查询优化器在第一次调用游标时,会观察用户定义的绑定变量的值,允许优化器来确认过滤条件的选择性, ...
- [转]ORACLE 绑定变量用法总结
转:http://blog.csdn.net/wanghai__/article/details/4778343 在oracle 中,对于一个提交的sql语句,存在两种可选的解析过程, 一种叫做硬解析 ...
- ORACLE 绑定变量用法总结 .
之前对ORACLE中的变量一直没个太清楚的认识,比如说使用:.&.&&.DEIFINE.VARIABLE……等等.今天正好闲下来,上网搜了搜相关的文章,汇总了一下,贴在这里,方 ...
- Oracle绑定变量优缺点
参考:http://f.dataguru.cn/thread-208881-1-1.html 参考:http://blog.sina.com.cn/s/blog_4d9ece9a0100caw8.ht ...
随机推荐
- 2020-2021-1 20209307 《Linux内核原理与分析》第九周作业
这个作业属于哪个课程 <2020-2021-1Linux内核原理与分析)> 这个作业要求在哪里 <2020-2021-1Linux内核原理与分析第九周作业> 这个作业的目标 & ...
- 利用302绕过http协议限制
360某处ssrf漏洞可探测内网信息(附内网6379探测脚本) http://xss.one/bug_detail.php?wybug_id=wooyun-2016-0229611
- sqli-labs 20-22 --cookie注入
异常处理 一开始打开这个题目的时候找不到cookie... 登录成功就是没有cookie cookie注入没有cookie... 第二天重新做的时候,同学讲自己设置cookie可以用 用插件EditT ...
- 如何从零开发一个NuGet软件包?
作者:依乐祝 首发地址:https://www.cnblogs.com/yilezhu/p/14175019.html 我想目前每个.net开发人员都应该知道nuget.org和NuGet软件包吧.但 ...
- 解决误删/bin/bash问题
出现原因:由于当时误操作把 /bin/bash 命令解释器二进制文件移到了/root 家目录里面,再重新登录系统之后,登陆进去什么也干干不了. 解决办法:让系统重启,以挂载光盘模式进入系统BIOS,选 ...
- 关于git中的merge和rebase
变基-git官网说明 变基 改变提交的基于分支 和merge不同 合并显示合并记录 变基合并更新后一起提交 不显示合并记录 变基 合并的结果是一致的
- 小团队产品研发管理V0.0.1
序言 之前做研发的时候非常鄙视管理,觉得管理的那些人就知道搞政治,后来做了开发主管,以及到部门经理之后,管的人多了发现管理真是门大学问,真的应该每个人都要学习一些基本管理知识,特别是刚入社会的打工人. ...
- 登录&单点登录介绍
COOKIE & SESSION & TOKEN 主要用来跟踪会话,识别用户所用.cookie 是客户端,session 是服务端的. 因为 http 是无状态协议,每一次的访问都不知 ...
- BOM主数据-用ECN实现可变BOM
用ECN变更号实现可变BOM:通过ECN变更号的参数类型来实现BOM的可变配置. 物料编号:2104 (1)首先BOM的父项物料主数据<基本数据1>必须设置栏位"参数有效值&qu ...
- 【目标检测】基于传统算法的目标检测方法总结概述 Viola-Jones | HOG+SVM | DPM | NMS
"目标检测"是当前计算机视觉和机器学习领域的研究热点.从Viola-Jones Detector.DPM等冷兵器时代的智慧到当今RCNN.YOLO等深度学习土壤孕育下的GPU暴力美 ...