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 ...
随机推荐
- 学习笔记——JS语言精粹
JS作用域是基于词法作用域的顶级对象. JS是一门弱类型语言,强类型能在编译时检测错误. JS是唯一一门所有浏览器都能识别的语言. 块注释对于被注释的代码是不安全的,例如/* var rm=/a*/ ...
- 淘宝|蚂蚁|菜鸟|盒马|嘀嘀|饿了么面经(已拿多个offer)
上一篇的同学拿到了bigo和腾讯的offer,这一次的分享来自两位同学的面试综合,他们分别拿到了菜鸟.嘀嘀.盒马的多个offer,由于面试的时间跨度时间太长,且面试的部门太多,只能回忆到具体的面试题, ...
- AOP基本概念
连接点joinpoint(类中所有方法) 切入点pointcut(缺少共性代码的方法) 通知advice(被抽取的共性功能的代码逻辑,通知有位置区分,也就是从切入点方法中被抽取代码的前面还是后面抽象出 ...
- 痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU硬件那些事(2.5)- 串行NOR Flash下载算法(IAR EWARM篇)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是IAR开发环境下i.MXRT的串行NOR Flash下载算法设计. 在i.MXRT硬件那些事系列之<在串行NOR Flash XI ...
- css 09-CSS案例讲解:博雅互动
09-CSS案例讲解:博雅互动 #前言 CSS已经学了一些基础内容了,我们来讲解一个小案例吧.以博雅互动的官网首页举例. #版心 首页的版心如下: 这里我们要普及一个概念,叫"版心" ...
- 卡尔曼滤波学习笔记1-Matlab模拟温度例子--代码比较乱,还需优化
温度模拟参数选取 xk 系统状态 实际温度 A 系统矩阵 温度不变,为1 B.uk 状态的控制量 无控制量,为0 Zk 观测值 温度计读数 H 观测矩阵 直接读出,为1 wk 过程噪声 温度变化偏差, ...
- NET 5使用gRPC
gRPC 是一种与语言无关的高性能远程过程调用 (RPC) 框架. https://grpc.io/docs/guides/ https://github.com/grpc/grpc-dotnet h ...
- NET 5 使用RabbitMQ以及Kafka区别
区别 1.应用场景方面RabbitMQ:用于实时的,对可靠性要求较高的消息传递上.kafka:用于处于活跃的流式数据,大数据量的数据处理上.2.架构模型方面producer,broker,consum ...
- C# 7-zip 压缩和解压缩
using System; using System.Collections.Generic; using System.Text; using SevenZip; using System.IO; ...
- 看完这篇,保证让你真正明白:分布式系统的CAP理论、CAP如何三选二
引言 CAP 理论,相信很多人都听过,它是指: 一个分布式系统最多只能同时满足一致性(Consistency).可用性(Availability)和分区容错性(Partition tolerance) ...