通常我们知道,db2的package在统计信息或依赖对象发生变化后需要做下重新绑定,否则db2优化器会采用效率较差或者错误的执行计划运
通常我们知道,db2的package在统计信息或依赖对象发生变化后需要做下重新绑定,否则db2优化器会采用效率较差或者错误的执行计划运行该package,造成执行性能严重下降或者sp一直会处于卡死状态。所以定期对sp进行重新绑定操作,对数据库整体性能和效率都有较大的提升,但是查一查,关于db2的sp重新绑定,提供了三个命令:db2rbind、rebind和bind,很多人都分不清这三者区别,如何使用的问题,所以本文就重点对着三个命令用法进行分析。
其实三者都是提供sp重新绑定,不过传入参数不一样,bind需要带入.bnd的文件,缺陷情况下,c或嵌入式sql编写的sp在precompile时,都会创建一个以.bnd的结尾的文件,数据库中使用程序包和应用程序编译的原因相同,即就是提高性能和压缩,在程序包构建过程而不是执行过程中,sp中的相关语法语义都得到分析,并且程序包中存储的是被解释效率更高的操作字符组,在服务器管理器调用预编译生生成的代码,只需要提供相应的输入变量就可以执行执行,提高了效率。并且预编译仅仅适用静态sql,而不适合如prepare execute和execute immediate 动态sql。这些动态sql还是需要重新进行编译解释。db2提供绑定文件描述工具db2bfd工具可以查看bnd文件。其用法如下:
c:\program files (x86)\ibm\sqllib\bnd>db2bfd
usage: db2bfd [ [-b] [-h] [-s] [-v] ]
where: is at least a v7 bind file
options: -b = display bind file header
-h = display this information
-s = display sql statements
-v = display host variable declarations
c:\program files (x86)\ibm\sqllib\bnd>db2bfd -b db2sampl_sql.bnd
db2sampl_sql.bnd: header contents
header fields:
field value
----- -----
releasenum 0x800
endian 0x4c
numhvars 16
maxsect 14
numstmt 26
optinternalcnt 4
optcount 10
name value
------------------ -----
isolation level cursor stability
creator nullid
app name sqle6h02
timestamp aaaaabiu:2004/08/01 00:00:00:00
cnulreqd yes
sql error no package
block block all
validate bind
date default/local
time default/local
*** all other options are using default settings as specified by the server ***
c:\program files (x86)\ibm\sqllib\bnd>db2bfd -s db2sampl_sql.bnd
db2sampl_sql.bnd: sql statements = 26
line sec typ var len sql statement text
---- --- --- --- --- ---------------------------------------------------------
55 0 5 0 21 begin declare section
76 0 2 0 19 end declare section
275 0 14 0 32 whenever sqlerror goto endofproc
3366 1 9 1 26 execute immediate :h00001
3416 2 0 1 40 values current sqlid into :h00008
3418 3 0 1 32 set current sqlid = :h00009
3437 4 0 1 34 set current sqlid = :h00008
3459 5 0 1 40 values current sqlid into :h00008
3461 6 0 1 32 set current sqlid = :h00009
3547 7 11 1 24 prepare s1 from :h00001
3582 7 11 1 24 prepare s1 from :h00001
3598 8 0 1 34 set current sqlid = :h00008
3616 0 5 0 21 begin declare section
3619 0 2 0 19 end declare section
3652 7 9 4 56 execute s1 using :h00004 , :h00015, :h00005, :h00006
3674 7 9 4 56 execute s1 using :h00004 , :h00016, :h00005, :h00006
3720 9 0 1 41 values current schema into :h00008
3774 10 0 1 33 set current schema = :h00009
3977 11 11 1 32 prepare blobupdate from :h00001
4005 12 11 1 32 prepare clobupdate from :h00001
4248 13 0 1 86 select num_db_storage_paths into :h00014 fr
om table(snap_get_db('', -1))
4416 14 0 1 35 set current schema = :h00008
4475 11 9 3 58 execute blobupdate using :h00010 , :h00005, :h00012
4492 11 9 3 58 execute blobupdate using :h00010 , :h00005, :h00012
4551 12 9 3 59 execute clobupdate using :h00011 , :h00005, :h00013
4573 12 9 3 59 execute clobupdate using :h00011 , :h00005, :h00013
确切来说package都是用如c等嵌入式语言开发编译而来,,所以在执行绑定操作,我们通常需要使用bind,因为bind命令需要传入bnd参数文件名称,如:
c:\program files (x86)\ibm\sqllib\bnd>db2 bind db2sampl_sql.bnd
