??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久亚洲AV无码麻豆,久久亚洲高清综合,99久久超碰中文字幕伊人http://www.shnenglu.com/prayer/category/7986.html在一般中L卓越zh-cnMon, 24 Jun 2019 10:41:26 GMTMon, 24 Jun 2019 10:41:26 GMT60DB2 ~冲池调优Bufferpoolshttp://www.shnenglu.com/prayer/archive/2019/06/24/216446.htmlPrayerPrayerMon, 24 Jun 2019 02:09:00 GMThttp://www.shnenglu.com/prayer/archive/2019/06/24/216446.htmlhttp://www.shnenglu.com/prayer/comments/216446.htmlhttp://www.shnenglu.com/prayer/archive/2019/06/24/216446.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/216446.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/216446.htmlhttps://blog.csdn.net/liujinwei2005/article/details/8547190

DB2 ~冲池调优Bufferpools


背景知识
~冲池是内存中的一块存储区域,用于临时d和更?a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #4ea1db; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;">数据?/span>(包含表行或烦引项Q。缓冲池的用途是Z提高数据库系l的性能。从内存讉K数据要比从磁盘访问数据快得多。因此,数据?a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #4ea1db; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;">器需要从盘d或写入磁盘的ơ数少Q性能p好。对一个或多个~冲池进行配|之所以是调优的最重要斚wQ是因ؓq接x据库的应用程序的大多数数据(不包括大对象和长字段数据Q操作都在缓冲池中进行?/div>
~省情况下,应用E序使用~冲?IBMDEFAULTBPQ它是在创徏数据库时创徏的。当 SYSCAT.BUFFERPOOLS 目录表中该缓冲池?NPAGES gؓ -1 ӞDB2 数据库配|参?BUFFPAGE 控制着~冲池的大小。否则会忽略 BUFFPAGE 参数Qƈ且用 NPAGES 参数所指定的页数创建缓冲池?/div>
对于仅用一个缓冲池的应用程序,?NPAGES 更改?-1Q这?BUFFPAGE 可以控制该~冲池的大小。这使得更新和报告缓冲池大小以及其它 DB2 数据库配|参数变得更加方ѝ?/div>
保可以使用数据库配|中?BUFFPAGE 参数来控制缓冲池大小之后Q将该参数设|成合适的倹{根据数据库的大和应用E序的性质该参数讄成一个合理的大|q种做法很安全。通常Q该参数的缺省值非常小Q可能满不了要求。请考虑下列情况Q?/div>
一开始,如果您的机器上有_大的内存Q请?BUFFPAGE 讄?40000 个页Q?60 MBQ,或者等于机器d存的 10%?nbsp;
对于大型 OLTP 数据库,在保持系l稳定的同时为缓冲池留出可能多的内存。一开始,先尝试?1.6 GB 的内存,然后试用更多内存?nbsp;
如何更改该参?/div>
q行下面q个脚本Q以便: 
验证目录?nbsp;
启用数据库配|参?BUFFPAGE 
更新所有数据库?BUFFPAGE 倹{?nbsp;
db2 -v connect to DB_NAME
db2 -v select * from syscat.bufferpools
db2 -v alter bufferpool IBMDEFAULTBP size -1
db2 -v connect reset
db2 -v update db cfg for dbname using BUFFPAGE bigger_value
db2 -v terminate
研究步骤
要确定数据库的缓冲池大小是否?BUFFPAGE 参数所军_Q请q行Q?/div>
db2 -v connect to DB_NAME
db2 -v SELECT * from SYSCAT.BUFFERPOOLS
db2 -v connect reset
db2 -v terminate
查结果。如果每个缓冲池都有一个ؓ“-1”?NPAGES |那么~冲池大是由数据库配置中的 BUFFPAGE 参数控制的?/div>
要确定缓冲池大小是否_大,请在q行应用E序时收集数据库和/或缓冲池的快照。类g下面的脚本ؓ您提供这些所需的信息:
db2 -v update monitor switches using bufferpool on
db2 -v get monitor switches
db2 -v reset monitor all
-- run your application --
db2 -v get snapshot for all databases > snap.out
db2 -v get snapshot for dbm >> snap.out
db2 -v get snapshot for all bufferpools >> snap.out
db2 -v reset monitor all
db2 -v terminate
L保您在断开数据库连接之前发?#8220;db2 -v get snapshot”。当最后一个应用程序与数据库断开q接Ӟ该数据库停止q行Q同时所有快照统计信息将会丢失。要保一直存在数据库处于正常运行状态的q接Q请使用下列Ҏ之一Q?/div>
在收集快照的H口中保持一个单独的q接?nbsp;
使用 DB2 ACTIVATE DATABASE 命o?/div>
在数据库快照或缓冲池快照的快照输ZQ查找下?#8220;logical reads”?#8220;physical reads”Q这样就可以计算出缓冲池命中率,它可以帮助您调优~冲池:
-- Related lines from a sample of bufferpool snapshots --
Buffer pool data logical reads = 702033
Buffer pool data physical reads = 0
Buffer pool data writes = 414
Buffer pool index logical reads = 168255
Buffer pool index physical reads = 0
~冲池命中率表明数据库管理器不需要从盘装入(卌已l在~冲池中Q就能处理页h的时间百分比。缓冲池的命中率高Q用磁?I/O 的频率就低。按如下计算~冲池命中率Q?/div>
(1 - ((buffer pool data physical reads + buffer pool index physical reads) /
(buffer pool data logical reads + pool index logical reads))
) * 100%
q个计算考虑了缓冲池高速缓存的所有页Q烦引和数据Q。理x况下Q该比率应当过 95%Qƈ可能接q?100%。要提高~冲池命中率Q请试下面q些ҎQ?/div>
增加~冲池大?nbsp;
考虑分配多个~冲池,如果可能的话Qؓ每个l常被访问的大表所属的表空间分配一个缓冲池Qؓ一l小表分配一个缓冲池Q然后尝试一下用不同大的~冲池以查看哪种l合会提供最x能?nbsp;
如果已分配的内存不能帮助提高性能Q那么请避免l缓冲池分配q多的内存。应当根据取自测试环境的快照信息来决定缓冲池的大?/div>

~冲池命中率

q个比率说明了ؓ面h提供服务Ӟ数据库管理器不需从磁盘装入页Q即该页已经在缓冲池中)p处理请求的旉癑ֈ比?/p>

计算Q?/p>

BPHR = (1 - ((~冲池数据物理读 + ~冲池烦引物理读) /

(~冲池数据逻辑?+ ~冲池烦引逻辑? ) ) * 100%

索引命中?/p>

q个比率表明了可以在~冲池中扑ֈ的页面能够满的对烦引页的所有读h所占的癑ֈ比?/p>

计算Q?/p>

IHR = (1 - (~冲池烦引物理读 / ~冲池烦引逻辑? ) ) * 100%

数据命中?/p>

q个比率说明了可以在~冲池中扑ֈ的页面能够满的Ҏ据页的所有读h所占的癑ֈ比?/p>

计算Q?/p>

DHR = (1 - (~冲池数据物理读 / ~冲池数据逻辑? ) ) * 100%

l论

~冲池命中率大于 80% 被认为是理想的。对?OLTP pȝ来说Q该值的理想情况是尽可能接近?100% Q烦引命中率更是如此Q?/p>

要提高缓冲池的命中率Q可以增加缓冲池的大,也可以考虑分配多个~冲池,可以为每个经常访问的h自己的表I间的大型表使用一个缓冲池Q也可以Zl小型表使用一个缓冲池?/p>

Prayer 2019-06-24 10:09 发表评论
]]>
db2 查看 修改 端口?/title><link>http://www.shnenglu.com/prayer/archive/2019/03/25/216311.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Mon, 25 Mar 2019 03:41:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2019/03/25/216311.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/216311.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2019/03/25/216311.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/216311.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/216311.html</trackback:ping><description><![CDATA[<p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">db2安装完成后,tcp/ipq接端口默认?0000Q可通过下面的方法确认:</span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"> </p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">1、用命?db2 get dbm cfg |find "SVCENAME" 查找到TCP/IP 服务?/span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"> </p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">2、到pȝ配置文g里找到service name 对应?port number<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" /><a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #6795b5; text-decoration: none; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;">windows</a>Q查?c:\windows\system32\drivers\etc\<a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #6795b5; text-decoration: none; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;">services</a>                                                </span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">aixQ?nbsp;        查看 /etc/services</span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">如下Q?/span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">DB2_DB2              60000/tcp<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />DB2_DB2_1          60001/tcp<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />DB2_DB2_2          60002/tcp<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />DB2_DB2_END      60003/tcp</span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">db2c_DB2             50000/tcp</span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"> </p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">3、?netstat -an 命o查找tcp/ip 服务的端?/span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;"> <br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />4、修改端口号<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />   直接修改services文g中当前服务名对应的端口号<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />如:db2c_DB2 50000/tcp<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />然后重启数据库即OK  db2stop  db2start<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" /></span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">5、另外附上一个关?a target="_blank" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #6795b5; text-decoration: none; cursor: pointer; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;">linuxpȝ</a>下的查找ҎQ摘抄帖子)Q?/span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">In JDBC configurations for WPA, you have to specify the port that DB2 is listening on. I usually look for /etc/services or try one of 50000/50001 and it usually works. In SUSE Linux, both the solutions did not work and there was another process (Multithreaded routing toolkit aka mrt) was listening on port 50000.</span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">So how do we find out the DB2 port in a reliable way? Read on...<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />Step 1: Set the DB2 environment.<br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ . ~db2inst1/sqllib/db2profile</span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">Step 2: Find the service name for DB2 instance. It basically involves running "db2 get dbm cfg" command and finding a line containing SVCENAME. <br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" />$ svc=`db2 get dbm cfg | grep SVCENAME | cut -d= -f2 | awk '{print $1}'`</span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">Step 3: Find the service name that you got from Step 2 in /etc/services or %SYSTEMROOT%\system32\drivers\etc\services. That is the port DB2 is listening on. $ grep $svc /etc/services</span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"> </p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;">Hope you find this useful.<br /><br /><br /><br /><br /></span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">用sqoop做测试,发现端口?0000被占用了Q所以就更改了一下DB2的端口号?/span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><br style="-webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;" /></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">W一步,dDB2数据库的实例用户Q我q里是db2inst1</span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all; font-weight: bold;">db2 get dbm cfg|grep SVCENAME</span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">可以看到对应的SVCENAME的名U是什么?/span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><img src="https://blog.51cto.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif" style="-webkit-font-smoothing: antialiased; margin: 0px 0px 15px; padding: 0px; border: none; max-width: 100%; word-break: break-all; cursor: pointer;" alt="" /><img src="https://s1.51cto.com/images/20171205/1512443775679086.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=" title="1512443775679086.png" alt="clipboard.png" style="-webkit-font-smoothing: antialiased; margin: 0px 0px 15px; padding: 0px; border: none; max-width: 100%; word-break: break-all; cursor: pointer;" /></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;"><br style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;" /></span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all; color: #00b0f0;">q里Ҏ出现一个问题。按照网上有的,会将SVCENAME改ؓ端口P那个是错误的。一定要这个名U和services中的名称l一?/span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;"><br style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;" /></span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">W二步,退回到root用户Q?/span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;"><span style="-webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all; font-weight: bold;">vim /etc/services</span>Q找到对应的SVCENAME的名U所对应的端口号?/span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">我这里直接编辑成50001</span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;"><img src="https://s1.51cto.com/images/20171205/1512443868871361.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=" title="1512443868871361.png" alt="clipboard.png" style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 15px; padding: 0px; border: none; max-width: 100%; word-break: break-all; cursor: pointer;" /></span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><img src="https://blog.51cto.com/static/js/ueditor1.4.3/themes/default/images/spacer.gif" style="-webkit-font-smoothing: antialiased; margin: 0px 0px 15px; padding: 0px; border: none; max-width: 100%; word-break: break-all; cursor: pointer;" alt="" /></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">W三步,先关数据库,再开可以了?/span></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><strong style="-webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">db2stop</span></strong></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><strong style="-webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">db2start</span></strong></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><strong style="-webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;"><br style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;" /></span></strong></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;"><span style="font-family: 微Y雅黑, 'Microsoft YaHei'; -webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;">实际上没有复杂的步骤Q只是好多h写的比较的ؕQ还不加解释说明Q所以坑了些?/span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;"><br /><br /></span></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff; text-align: justify;">可以通过db2 get dbm cfgQ查询数据库理器配|参敎ͼ可以查到端口号或端口名?/p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">CZQ?/p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">$ db2 get dbm cfg | grep -i svcTCP/IP Service name (SVCENAME) = 50000</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">50000是端口号了?/p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><br style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; word-wrap: break-word;" /></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"></p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">如果查到的是端口名,可以通过|络服务配置文g来找到对应关pR?/p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">CZQ?/p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">$ db2 get dbm cfg | grep -i svc</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">TCP/IP Service name (SVCENAME) = db2c_DB2</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">q时Q就需要查找db2c_DB2对应的端口号了?/p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">$ cat /etc/services | grep db2c_DB2</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">db2c_DB2 60000/tcp</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">q个60000是端口号了?/p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft Yahei', 微Y雅黑, arial, 宋体, sans-serif; font-size: 16px; color: #333333; line-height: 28px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;">如果DB2是装在windows的server上,那么需要查找这个配|文件了QC:\WINDOWS\system32\drivers\etc\services格式Qdb2c_DB2 50000/tcp</p><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; word-wrap: break-word; background-color: #ffffff;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-family: 'Microsoft YaHei'; word-wrap: break-word;"><br /><br /></span></p><img src ="http://www.shnenglu.com/prayer/aggbug/216311.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2019-03-25 11:41 <a href="http://www.shnenglu.com/prayer/archive/2019/03/25/216311.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>not in/not exists ?null 陷阱http://www.shnenglu.com/prayer/archive/2019/01/11/216187.htmlPrayerPrayerFri, 11 Jan 2019 01:45:00 GMThttp://www.shnenglu.com/prayer/archive/2019/01/11/216187.htmlhttp://www.shnenglu.com/prayer/comments/216187.htmlhttp://www.shnenglu.com/prayer/archive/2019/01/11/216187.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/216187.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/216187.html阅读全文

Prayer 2019-01-11 09:45 发表评论
]]>
sql 在not in 子查询有null值情况下l常出现的陷?/title><link>http://www.shnenglu.com/prayer/archive/2019/01/11/216186.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Fri, 11 Jan 2019 01:40:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2019/01/11/216186.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/216186.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2019/01/11/216186.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/216186.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/216186.html</trackback:ping><description><![CDATA[<div>http://www.cnblogs.com/51net/p/4165781.html<br /><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">如果下:Table_A表和Table_B表,要求查询出在Table_A表中不在Table_B表中的记录?/p><div style="margin: 5px 0px; font-size: 12px !important;"><img id="code_img_opened_6d27530e-5e96-4b9f-b94c-41d81c347ece" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="" style="margin: 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px; border: 0px; max-width: 820px; height: auto;" /><div class="qgqyume" id="cnblogs_code_open_6d27530e-5e96-4b9f-b94c-41d81c347ece" style="margin: 0px;"><div style="margin: 5px 0px 0px;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5 !important;"><a title="复制代码" style="margin: 0px; padding: 0px; text-decoration: underline; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; max-width: 820px; height: auto; border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">CREATE TABLE [dbo].[Table_A]( [ID] [nchar](</span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">10</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">) NULL, [Name] [nchar](</span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">10</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">) NULL ) ON [PRIMARY] GO ID Name </span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">001</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> 张三 </span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">002</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> 李四 </span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">003</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> 王五 CREATE TABLE [dbo].[Table_B]( [ID] [nchar](</span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">10</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">) NULL, [Name] [nchar](</span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">10</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">) NULL ) ON [PRIMARY] GO ID Name NULL 张三 </span><span style="margin: 0px; padding: 0px; color: #800080; line-height: 1.5 !important;">002</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> 李四 NULL 王五 </span></pre><div style="margin: 5px 0px 0px;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5 !important;"><a title="复制代码" style="margin: 0px; padding: 0px; text-decoration: underline; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; max-width: 820px; height: auto; border: none !important;" /></a></span></div></div></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;"> </p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">很容大家W一旉相当的写法是Q?/p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span> dbo.Table_A <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">AS</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> a </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">WHERE</span> a.ID <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">NOT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">IN</span> ( <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> b.ID </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span> dbo.Table_B <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">AS</span> b)</pre></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">然而查询出来ƈ没有辑ֈ预期?/p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">ID    Name<br style="margin: 0px; padding: 0px;" />001  张三        <br style="margin: 0px; padding: 0px;" />003  王五          </p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">原因很简单:׃NULL不能q行如何?#8220;操作”</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">–如果null参与术q算Q则该算术表辑ּ的gؓnull。(例如Q?Q?Q?Q? 加减乘除Q?/p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">–如果null参与比较q算Q则l果可视为false。(例如Q?gt;=,<=,<>  大于Q小于,不等于)</p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">–如果null参与聚集q算Q则聚集函数都置为null。除count(*)之外?/p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;">--如果在not in子查询中有null值的时?则不会返回数据?nbsp; Q最单的解释请参考下面的评论说明Q?nbsp;    </p><div style="margin: 5px 0px; font-size: 12px !important;"><img id="code_img_opened_760e3223-d8d4-4010-b307-5206ce6fb55c" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="" style="margin: 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px; border: 0px; max-width: 820px; height: auto;" /><div class="oamwuia" id="cnblogs_code_open_760e3223-d8d4-4010-b307-5206ce6fb55c" style="margin: 0px;"><div style="margin: 5px 0px 0px;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5 !important;"><a title="复制代码" style="margin: 0px; padding: 0px; text-decoration: underline; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; max-width: 820px; height: auto; border: none !important;" /></a></span></div><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New' !important;"><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">--</span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">正确写法 </span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span> dbo.Table_A <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">AS</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> a </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">WHERE</span> a.ID <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">NOT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">IN</span> ( <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> b.ID </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span> dbo.Table_B <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">AS</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> b </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">WHERE</span> b.ID <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">IS</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">NOT</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">NULL</span> ) <span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">--</span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">排除NULL值参与运符比较</span> <span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">--</span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">修改为关联查询方? </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> --</span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">正确写法1 </span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span> dbo.Table_A <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">AS</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> a </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">WHERE</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">NOT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">EXISTS</span> ( <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span> dbo.Table_B <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">AS</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> b </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">WHERE</span> a.ID <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> b.ID ) </span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">--</span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">正确写法2 </span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span> dbo.Table_A <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">AS</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> a </span><span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">LEFT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">OUTER</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">JOIN</span> dbo.Table_B <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">AS</span> b <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">ON</span> a.ID <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> b.ID </span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">WHERE</span> b.ID <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">IS</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">NULL</span></pre><div style="margin: 5px 0px 0px;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5 !important;"><a title="复制代码" style="margin: 0px; padding: 0px; text-decoration: underline; border: none !important;"><img src="http://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="margin: 0px; padding: 0px; max-width: 820px; height: auto; border: none !important;" /></a></span></div></div></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: #ffffff;"> </p></div><img src ="http://www.shnenglu.com/prayer/aggbug/216186.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2019-01-11 09:40 <a href="http://www.shnenglu.com/prayer/archive/2019/01/11/216186.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DB2 对于null?'的区?/title><link>http://www.shnenglu.com/prayer/archive/2019/01/11/216185.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Fri, 11 Jan 2019 01:33:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2019/01/11/216185.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/216185.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2019/01/11/216185.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/216185.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/216185.html</trackback:ping><description><![CDATA[<span style="color: #333333; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun; background-color: #ffffff;">null 当做一U情?昄null,不占内存  '',昄为空?占内? 判断null 只能使用is null,  ?='',不包?nullq种情况,  对于一些数据库的插入时,应注?为null?可能取不出数?D吓一x入语?参数错误,直接报错  ----1580 工作?感想<br /></span><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;">在DB2中,null?#8216;’是完全不同的两个东西?/p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;">NULL是一个不定值它不能通过列D滤,只能通过IS NULL 或者IS NOT NULL方式qo</p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;">?#8216;’可以用inQ?Q?lt;>,>,<来比较判断?br style="-webkit-font-smoothing: antialiased; margin: 0px; padding: 0px; max-width: 100%; word-break: break-all;" /></p><p style="font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, 'PingFang SC', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', 'Microsoft Yahei', sans-serif; -webkit-font-smoothing: antialiased; margin: 0px 0px 0.7rem; padding: 0px; max-width: 100%; font-size: 16px; word-break: break-all; color: #3d464d; line-height: 1.8; word-wrap: break-word;">此外Q若一个属性的gؓnullQ则select昄Ӟ会以-代替Q?#8216;’则直接什么都不显C?/p><span style="color: #333333; font-family: -apple-system, 'SF UI Text', Arial, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif, SimHei, SimSun; background-color: #ffffff;"><br /><br /></span><img src ="http://www.shnenglu.com/prayer/aggbug/216185.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2019-01-11 09:33 <a href="http://www.shnenglu.com/prayer/archive/2019/01/11/216185.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用where in遇到null时的解决Ҏ1http://www.shnenglu.com/prayer/archive/2019/01/11/216184.htmlPrayerPrayerFri, 11 Jan 2019 01:33:00 GMThttp://www.shnenglu.com/prayer/archive/2019/01/11/216184.htmlhttp://www.shnenglu.com/prayer/comments/216184.htmlhttp://www.shnenglu.com/prayer/archive/2019/01/11/216184.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/216184.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/216184.html参考:https://www.2cto.com/database/201109/104960.htmlQhttp://ask.csdn.net/questions/680006
1 Q? 
SELECT
FROM
华东 
WHERE
公司代码 IN ( SELECT 公司?FROM 备选客?WHERE 公司?!= '' AND 公司?IS NOT NULL );
2Q用exists替换
SELECT
FROM
华东 
WHERE
EXISTS (
SELECT
公司?nbsp;
FROM
备选客?where 华东.公司代码=`备选客户`.公司?;
3Q?in和exists一点区?/div>
exists做ؓwhere 条gӞ是先对where 前的L询询q行查询Q然后用L询的l果一个一个的代入exists的查询进行判断,如果为真则输出当前这一条主查询的结果,否则不输出?/div>
in 是把外表和内表作hash q接Q而exists是对外表作loop循环Q每ơloop循环再对内表q行查询。一直以来认为exists比in效率高的说法是不准确的?/div>
如果查询的两个表大小相当Q那么用in和exists差别不大?/div>
如果两个表中一个较,一个是大表Q则子查询表大的用existsQ子查询表小的用inQ?/div>
--------------------- 
作者:csdncooker 
来源QCSDN 
原文Qhttps://blog.csdn.net/csdncooker/article/details/79299258 
版权声明Q本文ؓ博主原创文章Q{载请附上博文链接Q?/div>

Prayer 2019-01-11 09:33 发表评论
]]>db2之in和exist的性能区别http://www.shnenglu.com/prayer/archive/2019/01/10/216180.htmlPrayerPrayerThu, 10 Jan 2019 03:38:00 GMThttp://www.shnenglu.com/prayer/archive/2019/01/10/216180.htmlhttp://www.shnenglu.com/prayer/comments/216180.htmlhttp://www.shnenglu.com/prayer/archive/2019/01/10/216180.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/216180.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/216180.htmlhttps://blog.csdn.net/zhan19861022/article/details/7697652
一、IN 和EXISTS的性能区别
        in 是把外表和内表作hash q接Q而exists是对外表作loop循环Q每ơloop循环再对内表q行查询?nbsp;
其实区分in和exists主要是造成了驱动顺序的改变Q这是性能变化的关键)Q如果是existsQ那么以外层表ؓ驱动表,先被讉KQ如果是INQ那么先执行子查询,所以我们会以驱动表的快速返回ؓ目标Q那么就会考虑到烦引及l果集的关系了?/div>
EXISTS的执行流E?nbsp;
select * from t1 where exists ( select null from t2 where y = x ) 
可以理解? 
  for x in ( select * from t1 )    loop        if ( exists ( select null from t2 where y = x.x )        then          OUTPUT THE RECORD        end if    end  loop 

二、not in ?not exists的性能区别Q?nbsp;
         not in 只有当子查询中,select 关键字后的字D|not nullU束或者有q种暗示时用not in,另外如果L询中表大Q子查询中的表小但是记录多,则应当用not in,q用anti hash join. 
        如果L询表中记录少Q子查询表中记录多,q有索引Q可以用not exists。如果查询语句用了not in 那么内外表都q行全表扫描Q没有用到烦引;而not extsts 的子查询依然能用到表上的索引。所以无论哪个表大,用not exists都比not in要快?/div>
       ȝnot exists >> not inQin与exists的?span style="box-sizing: border-box; outline: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;">取决于子查询集合大小Q?span style="box-sizing: border-box; outline: 0px; font-family: 'Microsoft YaHei', 'SF Pro Display', Roboto, Noto, Arial, 'PingFang SC', sans-serif; word-wrap: break-word;">IN适合于外表大而内表小的情况;EXISTS适合于外表小而内表大的情?/span>Q即如果子查询得出的l果集记录较,L询中的表较大且又有烦引时应该用in,反之如果外层的主查询记录较少Q子查询中的表大Q又有烦引时使用exists?/div>

Prayer 2019-01-10 11:38 发表评论
]]>Unix环境下嵌入式CE序~译 http://www.shnenglu.com/prayer/archive/2012/03/21/168489.htmlPrayerPrayerWed, 21 Mar 2012 05:45:00 GMThttp://www.shnenglu.com/prayer/archive/2012/03/21/168489.htmlhttp://www.shnenglu.com/prayer/comments/168489.htmlhttp://www.shnenglu.com/prayer/archive/2012/03/21/168489.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/168489.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/168489.htmlA.预编译部?
1.预编译DB2?
1.1 什么是DB2预编?
  在我们用C语言~写讉KDB2的程序过E中,需要用到嵌入式SQL,其作用是DB2 SQL混入一般CE序? DB2预编译器可以SQL语法直接转换为DB2行时服务应用E序~程接口QAPIQ调用?
1.2 什么是bind
  q是DB2 prep要做的事情,xSQC中的SQL语句变ؓDB2数据库可认的API。bind的作用主要是Ҏ你SQC中的SQL语句使用的表和操作指定一个访问时DB要用的{略Q是一U优化作用,加快数据讉K的速度Q当然也可以不bindQ那P讉K的过E策略是在访问时才有的,速度会受很大的媄响,特别是ƈ发访问?

2.预编译命?
  2.1 db2 prep .sqc文g bindfile 其中bindfile参数作用是生成和sqc文g同名?bnd文g
? db2 prep /export/home/shwhome/sqc/CON_DB2.sqc bindfile 如果~译正常完成,则在.sqc文g同目录下会生成CON_DB2.c和CON_DB2.bnd文g
2.2 bind .bnd文g
  ? db2 bind /export/home/shwhome/sqc/CON_DB2.bnd
因ؓ是DB2的预~译命o,使用的是DB2的预~译?所以以上两条命令需要在q接DB2数据库的情况下才可以使用

B.嵌入式部?
1.嵌入式CE序的编?
我们采用GCC来编译CE序,GCC的一般编译命令请参考文档中的相兌?q里具体说明在目前环境下~译CE序的注意点?
1.1 ~译CE序
gcc -m64 -c -I/export/home/shwhome/inc -o /export/home/shwhome/obj/testdb.o /export/home/shwhome/src/testdb.c
参数说明
-m64: ?4位服务器上编译时采用,q里Z所有的~译后的目标文gl一,所以都加上-m64,如果再之后引用目标文件没有采?m64~译则在最后编译时会出现ELF CLASS32(或ELF CLASS64)错误. -C: 只编译ƈ生成目标文g,不做链接?
1.2 ~译SQC文g生成?C文g
gcc -m64 -c -I/export/home/shwhome/inc -I/export/home/aix/sqllib/include -L/usr/include/lib -o /export/home/shwhome/obj/CON_DB2.o /export/home/shwhome/sqc/CON_DB2.c
参数说明
-I/export/home/aix/sqllib/include: q个目录下主要用到2个头文g:sqladef.h和sqlca.h,q个是DB2预编译包含的都文?可以查看你用prep~译出来的与.sqc同名?C文g,其中包含这两个头文件。其中aix是DB2Instance用户,DB2安装后会include路径复制到instance用户的环境变量中,再次创徏instance后只要复制过来就可以,因ؓInstance用户q包含其他的环境讑֮,所以不要直接引?I/opt/IBM/db2/V9.5/include/q个DB2的安装\?
-L/usr/include/lib: q个目录是系l包含函数的库文?是编写应用程序的时候用的相当于API,也就是应用编E接口?
※ -I/usr/include?L/usr/include/lib是将usr/include下的函数作ؓ头文件包括进?q且程序链接到库文?q个例子中没有用?但是如果保险的话,在编译时最好加上这两个选项?
1.3 两个目标文?MCE序和嵌入式SQL)~译成可执行E序
gcc -m64 -ldb2 -lc -o /export/home/shwhome/bin/testdb /export/home/shwhome/obj/CON_DB2.o /export/home/shwhome/obj/testdb.o
参数说明
-ldb2: 链接DB2库文件。在SQCE序~译时必链接libdb2.so?其\径是/usr/lib/krb5/libdb2.so,之所以写?ldb2,是在使用-l?库名的lib和后~都去?卛_名是db2。以上命令是引用/export/home/shwhome/obj/CON_DB2.o /export/home/shwhome/obj/testdb.oq两个目标文?~译后生成testdb,攑֜路径/export/home/shwhome/bin下?


Prayer 2012-03-21 13:45 发表评论
]]>DB2的sqC文g名前八位不能重复的解军_?http://www.shnenglu.com/prayer/archive/2012/03/21/168486.htmlPrayerPrayerWed, 21 Mar 2012 05:24:00 GMThttp://www.shnenglu.com/prayer/archive/2012/03/21/168486.htmlhttp://www.shnenglu.com/prayer/comments/168486.htmlhttp://www.shnenglu.com/prayer/archive/2012/03/21/168486.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/168486.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/168486.html

我们的项目中使用CIBM的DB2数据库,pȝ开发语a是C++Q操作数据库是直接在C++中编写ESQLQ嵌入式SQLQ语句。在使用中发玎ͼ只要有文件名?位相同,造成部分文g中的代码失效?

原因Q?/strong>
------------------
db2默认情况下?.sqC的名字生?.bndQ又?.bnd的文件名部分在数据库中做l定Q徏一个同名的package。而db2的package的名字是?a >八字节长度限?/font>的,造成前八位文件名相同的C++代码QM后面的覆盖前面的?

知道原因好办事了?

解决Q?/strong>
------------------
取原始文件名的md5摘要前N位,拼成bnd文g的名字,再以此文件去目标数据库做l定Q这样package׃会前后覆盖了?

makefile中实际的做法Q?/strong>
------------------------

%.C : %.sqC
  db2 connect to $(dbName) user $(dbUser) using $(dbPassword);\
  db2 prep $*.sqC bindfile;\
  cp $*.bnd ${shell echo $* |md5sum -|cut -c1-8}_$*.bnd;\
  db2 bind ${shell echo $* |md5sum -|cut -c1-8}_$*.bnd;\
  db2 connect reset; \
  db2 terminate;


Prayer 2012-03-21 13:24 发表评论
]]>分布?DBA: 创徏和用分http://www.shnenglu.com/prayer/archive/2012/03/05/167218.htmlPrayerPrayerMon, 05 Mar 2012 15:47:00 GMThttp://www.shnenglu.com/prayer/archive/2012/03/05/167218.htmlhttp://www.shnenglu.com/prayer/comments/167218.htmlhttp://www.shnenglu.com/prayer/archive/2012/03/05/167218.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/167218.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/167218.htmlhttp://doc.chinaunix.net/db2/201009/893927.shtml

表分区是一U数据组l方案,它根据一列或多列中的值把表数据划分ؓ多个UCؓ数据分区 的存储对象。分区的表能够包含的数据比普通的表多得多Q另外,通过利用UCؓ分区消除 的过E,针对分区表运行的查询通常比针寚w分区表运行时执行速度更快Q需要的盘 I/O 更少。(DB2 优化器能够感知分区,在执行查询时只扫描相关的数据分区。)

  在这专栏文章中Q我讨论如何创建分Q解释分的定义如何决定各个记录的存储位置?

  范围分区?/p>

  数据分区也称_当前 DB2 只支持范围分区方案)Q一个数据分区包含一个行子集Q这些行存储在与表中其他行集不同的地斏V不同的数据分区可以ȝ在不同的表空间中Q也可以ȝ在相同的表空间中。CREATE TABLE 语句?PARTITION BY 子句中提供的信息军_表数据的分区方式。这个可选子句的语法取决于是希望?DB2 在指定的表数据范围内均匀地生成每个分_q是要手工控制每个范围的边界。对于给定的表数据范围自动生成分区的语法是:

PARTITION BY <RANGE> 
 ([ColumnName] <NULLS LAST | NULLS FIRST> ,...) 
 ( 
 STARTING <FROM> [Start | MINVALUE | MAXVALUE] | 
  STARTING <FROM> ([Start | MINVALUE | MAXVALUE] ,...) 
 <INCLUSIVE | EXCLUSIVE> 
 ENDING <AT> [End | MINVALUE | MAXVALUE] | 
  ENDING <AT> ([End | MINVALUE | MAXVALUE] ,...) 
 <INCLUSIVE | EXCLUSIVE> 
 EVERY <(>[Constant] <DurationLabel> <)> 
 ,...) 

  手工指定分区的语法是Q?/p>

PARTITION BY <RANGE>  
  ([ColumnName] <NULLS LAST | NULLS FIRST> ,...) 
  ( 
  <PARTITION [PartitionName]> 
 STARTING <FROM> [Start | MINVALUE | MAXVALUE] | 
  STARTING <FROM> ([Start | MINVALUE | MAXVALUE] ,...) 
 <INCLUSIVE | EXCLUSIVE> 
 ENDING <AT> [End | MINVALUE | MAXVALUE] | 
  ENDING <AT> ([End | MINVALUE | MAXVALUE] ,...) 
 <INCLUSIVE | EXCLUSIVE> 
  <IN [TSName]> 
  <INDEX IN [IndexTSName]> 
  <LONG IN [LongTSName]> 

  其中Q?/p>

  ColumnNameQ用名称指定一个或多个列(最?16 列)Q这些列的值用来决定数据行应该存储在哪个数据分Z。(指定的列l成表的分区?— 参见Ҏ “选择表分区键”。)数据cd?LONG VARCHAR、LONG VARGRAPHIC、BLOB、CLOB、DBCLOB、XML、基于这些数据类型的 distinct cd和结构化数据cd的列都不能作为数据分区键的组成部分?/p>

  PartitionNameQ指定分配给要创建的数据分区的惟一名称?/p>

  StartQ指定每个数据分区的范围下限?/p>

  EndQ指定每个数据分区的范围上限?/p>

  ConstantQ在使用语法的自动生成Ş式时Q指定每个数据分围的宽度。从 STARTING FROM 值开始创建数据分区,数据分区的范围内包含指定数量的倹{支持这U语法的条g是分区键由单一列组成,q一列的数据cd是数字、日期、时间或旉戟?/p>

  DurationLabelQ如果分区键列的数据cd是日期、时间或旉戻Iq个参数指定?Constant 值相关的旉单位。这个参数的有效值是QYEAR、YEARS、MONTH、MONTHS、DAY、DAYS、HOUR、HOURS、MINUTE、MINUTES、SECOND、SECONDS、MICROSECOND ?MICROSECONDS?/p>

  TSNameQ指定存储每个数据分区的表空间?/p>

  IndexTSNameQ指定存储每个数据分区的分区索引的表I间?/p>

  LongTSNameQ指定存储长列的值的表空间?/p>

  注意Q尖括号 (< >) 中的参数是可选的Q方括号 ([ ]) 中的参数或选项是必需的,必须提供它们Q逗号后面跟着省略?(...) 表示前面的参数可以重复出现多ơ?/p>

  因此Q如果希望创Z个名?SALES 的分Q把每个季度的数据存储在单独的分ZQ每个分区驻留在不同的表I间中,那么可以执行以下 CREATE TABLE 语句Q?/p>

CREATE TABLE sales 
 (sales_date  DATE, 
 sales_amt   NUMERIC(5,2)) 
 IN tbsp0, tbsp1, tbsp2, tbsp3 
 PARTITION BY RANGE (sales_date) 
  (STARTING '1/1/2010' ENDING '12/31/2010' 
  EVERY 3 MONTHS) 

  ?1 说明生成的表是什么样的?/p>

?1. 一个简单分中存储的数据
分布?DBA: 创徏和用分

  另一斚wQ如果希望创Z个名?INVENTORY 的分Q把物品~号?1 ?100 之间的行存储在一个表I间中的一个分ZQ把~号?101 ?200 之间的行存储在另一个表I间中的另一个分ZQ以此类推,那么可以执行下面?SQL 语句Q?/p>

CREATE TABLE inventory 
  (item_no INT, 
  desc VARCHAR(20)) 
PARTITION BY (item_no NULLS FIRST) 
(PARTITION PRODUCE STARTING MINVALUE ENDING 100 IN tbsp0, 
PARTITION DAIRY  STARTING    101 ENDING 200 IN tbsp1, 
PARTITION BAKERY  STARTING    201 ENDING 300 IN tbsp2, 
PARTITION MEAT   STARTING    301 ENDING 400 IN tbsp3) 

  选择表分区键

  选择有效的表分区键列对于发挥表分区的优势非常重要。最有效的表分区键列是有利于分区消除的列。例如,如果通常按日期查询表中的记录Q那么应该用日期或时间列q行表分区?/p>

  同样Q如果希望随着旉的推UL表数据的一部分删除或存档,应该Ҏ期望的记录存档方式进行表分区。例如,如果希望把三q前的所有数据都存档Q应该按周、月或季度进行表分区Q这样就可以分别在每周、每月或每季度末删除一个老分区?/p>

  对于q个CZQITEM_NO 值在 1 ?100 之间的行存储在名ؓ PRODUCE 的分ZQ这个分区的数据写到表空?TBSP0 中)QITEM_NO 值在 101 ?200 之间的行存储在名ؓ DAIRY 的分ZQ这个分区的数据写到表空?TBSP1 中)Q依ơ类推;ITEM_NO gؓ NULL 的行存储在 PRODUCE 分区中?/p>

  一定要注意Q当指定 NULLS FIRST 选项ӞW一个分区必M MINVALUE 开始。(同样Q如果?NULLS LAST 选项Q最后一个分区必ȝ束于 MAXVALUE。)否则Q在插入分区键列?NULL 值的记录Ӟ会?“data out of bounds” 错误。另外,每个分区的数据、烦引和长列数据可以攑֜不同的表I间中。如果不为烦引或长列指定表空_分区索引和长列数据会存储在与数据相同的表I间中?/p>

 

  在默认情况下Q范围包含边界本w。要想防止在某一分区中存储特定的记录Q可以用 EXCLUSIVE 选项创徏范围。例如:

CREATE TABLE sales 
 (sales_date DATE, 
 sales_amt NUMERIC(5,2)) 
IN tbsp0, tbsp1, tbsp2, tbsp3 
PARTITION BY RANGE (sales_date) 
(STARTING '1/1/2010' ENDING '3/31/2010' EXCLUSIVE,  
STARTING '3/31/2010' ENDING '6/30/2010' EXCLUSIVE,  
STARTING '6/30/2010' ENDING '9/30/2010' EXCLUSIVE,  
STARTING '9/30/2010' ENDING '12/31/2010') 

  在这个示例中Q销售日期ؓ 3/31/2010 的记录不会存储在表空?TBSP0 中,而是存储在表I间 TBSP1 中?/p>

  当在分区表中插入行时Q会Ҏ键值及其所处的范围自动地把它放到适当的数据分Z。如果键g处于表的M范围内,插入操作׃p|q生一个错误?/p>

  L地移入和Ud数据

  使用分区表的另一个优ҎQ可以轻村֜在表中添加新数据Q作为新的数据分区)Q同时可以轻村֜删除q存档老数据。在下一专栏文章中Q我讲解添加(UdQ和删除Q移出)数据分区的过E。还要讨?DB2 9.7 中的改进如何大大加快Ud和移出数据分区的速度Q减这些操作生的q扰?



Prayer 2012-03-05 23:47 发表评论
]]>
DB2 V9表分?/title><link>http://www.shnenglu.com/prayer/archive/2012/03/05/167217.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Mon, 05 Mar 2012 15:21:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2012/03/05/167217.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/167217.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2012/03/05/167217.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/167217.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/167217.html</trackback:ping><description><![CDATA[<strong><a >http://www.itokit.com/2011/0325/59467.html</a><br /><br />【IT168 专稿?/strong>DB2 V9新增了表分区功能,因此对一些大?我们在DB2 V9中不再需要分拆成表,再用UNION ALL视图的方式进?a class="keylink" target="_blank">设计</a>,而是直接用分实现一些这些功能。表分区功能是一U数据组l方??表数据根据一个或多个表列中的值分布到多个存储对象(UCؓ数据分区或范?中。每个数据分区都是单独存储的。q些存储对象可以在不同的表空间中,也可以在相同表空间中。由于表分区是DB2 V9新增的功?所以很多用户对其特性不是很了解,本文重点介lDB2 V9表分区功?q过实际的例子来帮助大家理解和提高。 <br /><br />?<br /><br />在DB2 V9之前,对一些大?ZҎ能和数据容量限制的考虑,我们通常会把大表分拆成一些小?再用UNION ALL 视图的方式进行联合v来。DB2 V9在数据容量方面有了重大突?DMS 表空间的新缺省类型是“大型”,当?#8220;大型”DMS表空间时,单表的最大容量限制是16384G(Byte),而不再是以前?12 G(Byte)。DB2 V9新增了表分区功能,使得我们对大表的性能和数据容量的虑都不再存在。使用表分?能够创徏非常大的?通过跨多个存储器对象划分表数?可显著增大表,一个表最多可以有32K个数据分区。使用表分区分隔数据能够避免扫描不相关的数?从而提高查询处理性能。DB2优化器从查询操作中去除不相关的分区。 <br /><br />表分区功能是一U数据组l方?Ҏ一个或多个表列中的值将表数据划分到多个UCؓ数据分区或范围的存储对象中。每个数据分区都是单独存储的。q些存储器对象可位于不同的表I间?或相同的表空间中。跨多个存储器对象对表数据进行分区的能力?a class="keylink" target="_blank">数据?/a>理员提供了更高的可伸羃性和灉|?同时提高了性能和控制能力。表分区可大幅度减管理庞?a class="keylink" target="_blank">数据?/a>所需的维护工?q可有效增加单个表的潜在大小。表和烦引自动重l的新策略选项使您能够更有效地理DB2<a class="keylink" target="_blank">服务?/a>对表和烦引的自动重组。表分区使您能够定义表数据的范围,以便单独保存每个范围。例?您可Z表中的日期列,按月对表q行分区。每个范?UCؓ数据分区)与单个存储器对象对应。这些存储器对象可位于不同的表空间和/或相同的表空间中。由于可以对单个数据分区执行理d,很耗时的维护操作分成一pd较小的操作来执行,从而ɽ理工作更ؓ灉|。例?可备份和复原单个数据分区而不是整个表。DB2 V9新增的表分区功能增强了对索引位置的细化控?可将索引|于不同表空间ƈ单独理它们。?ALTER TABLE语句?ATTACH PARTITION和DETACH PARTITION子句可进行快速及方便的数据{入或转出。此功能在数据仓库环境中特别有用,在此环境中经帔R要装入或删除数据以运行决{支持查询。能够表分区与其他数据组l方案组合在一P通过表分区与数据分区功?DPF)一起?可跨数据库分区均匀地分布数据范?以利?DPF 的查询内q行性和数据库分载均衡功能。表分区与多l集?MDC)一起用时,能够对同一表扩展数据块中在多个l上hcM值的行进行分l。 <br />׃表分区是DB2 V9新增的功?所以很多用户对其特性不是很了解,本文重点介lDB2 V9表分区功?q过实际的例子来帮助大家理解和提高。 <br /><br />我们按照下列顺序介l表分区: <br /><br />1. 创徏CZ数据库DB2TEST1,在示例数据库上创Z个?2K大的~冲?创徏3个DMS表空?用来存放CZ分区表的数据,创徏3个大型表I间(DMS),用来存放CZ分区表的大型数据,创徏1个DMS表空?用来存放CZ分区表的索引 <br /><br />2. 使用自动方式创徏CZ分区?<br /><br />3. 使用手工方式创徏CZ分区?<br /><img src ="http://www.shnenglu.com/prayer/aggbug/167217.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2012-03-05 23:21 <a href="http://www.shnenglu.com/prayer/archive/2012/03/05/167217.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>fragment on db2 and informixhttp://www.shnenglu.com/prayer/archive/2012/03/05/167215.htmlPrayerPrayerMon, 05 Mar 2012 14:57:00 GMThttp://www.shnenglu.com/prayer/archive/2012/03/05/167215.htmlhttp://www.shnenglu.com/prayer/comments/167215.htmlhttp://www.shnenglu.com/prayer/archive/2012/03/05/167215.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/167215.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/167215.htmlhttp://hi.baidu.com/shenqb/blog/item/1c9ea8de8894644fccbf1aa1.html

转蝲?koolkite
最l编?koolkite
表分区功能是一U数据组l方案,卻I表数据根据一个或多个表列中的值分布到多个存储对象Q称为数据分区或范围Q中。每个数据分区都是单独存储的。这 些存储对象可以在不同的表I间中,也可以在相同表空间中。按?CREATE TABLE 语句?PARTITION BY 子句中指定那样将表数据分区。此定义中用的列被UCؓ表分区键列。DB2 表分区功能与 Informix® Dynamic Server ?Informix Extended Parallel Server 提供的数据分D늻l方法相对应?
Informix Ҏ

Informix 支持若干U数据组l方案,?Informix 产品中,q些ҎUCؓ分段。其中一U较怋用的分段cd?FRAGMENT BY EXPRESSION。这U类型的分段的工作方式与 CASE 语句非常怼Q其中有一个与表的每个分段相关联的表达式。检查这些表辑ּ以便定行的攄位置?/p>

Informix ?DB2 数据库系l的比较

DB2 数据库提供了丰富的补充功能,q些功能?Informix 数据l织Ҏ直接对应Q这使客戯够相对容易地?Informix 语法转换?DB2 语法。DB2 数据库管理器生成列?CREATE TABLE 语句?PARTITION BY RANGE 子句配合使用Q以处理复杂?Informix Ҏ?a >?78 ?Informix ?DB2 数据库品中使用的数据组l方案作了比较?/p>

 

?78. 所?Informix ?DB2 数据l织Ҏ的映?/caption>
数据l织Ҏ Informix 语法 DB2 版本 9.1 语法
  • InformixQ基于表辑ּ
  • DB2Q表分区
FRAGMENT BY EXPRESSION PARTITION BY RANGE
  • InformixQ@环法
  • DB2Q缺?
FRAGMENT BY ROUND ROBIN 没有语法QDB2 数据库管理器自动在容器之间分布数?/td>
  • InformixQ范围分?/li>
  • DB2Q表分区
FRAGMENT BY RANGE PARTITION BY RANGE
  • InformixQ系l定义的散列
  • DB2Q数据库分区
FRAGMENT BY HASH DISTRIBUTE BY HASH
  • InformixQHYBRID
  • DB2Q在q行表分区的情况下进行数据库分区
FRAGMENT BY HYBRID DISTRIBUTE BY HASH ?PARTITION BY RANGE
  • InformixQ不适用
  • DB2Q多l集?
不适用 ORGANIZE BY DIMENSION
CZ

下列CZ详细说明了在 DB2 中如何实CM使用表达式的 Informix 分段Ҏ{同的结果?/p>

CZ 1Q?/em>下面q个基本?Create Table 语句昄?Informix 分段以及{同?DB2 数据库系l表分区语法Q?/p>

Informix 语法Q?/p>

CREATE TABLE demo(a INT) FRAGMENT BY EXPRESSION
a = 1 IN db1,
a = 2 IN db2,
a = 3 IN db3;

DB2 语法Q?/p>

CREATE TABLE demo(a INT) PARTITION BY RANGE(a)
(STARTING(1) IN db1,
STARTING(2) IN db2,
STARTING(3) ENDING(3) IN db3);

Informix XPS 支持UCؓ hybrid 的两层分D|案,在此Ҏ中,使用一个表辑ּ来在协作服务器之间分布数据,q用第二个表达式来在协作服务器内分布数据。这使所有协作服务器都能够参与查 询(卻I在所有协作服务器上都有数据)Qƈ使查询能够利用数据分区消除功能的优势?/p>

通过l合使用 CREATE TABLE 语句?DISTRIBUTE BY ?PARTITION BY 子句QDB2 数据库系l实C?Informix hybrid {同的组l方案?/p>

CZ 2Q?/em>以下CZ昄了组合子句的语法Q?/p>

Informix 语法

CREATE TABLE demo(a INT, b INT) FRAGMENT BY HYBRID HASH(a)
EXPRESSION b = 1 IN dbsl1,
b = 2 IN dbsl2;

DB2 语法

CREATE TABLE demo(a INT, b INT) IN dbsl1, dbsl2
DISTRIBUTE BY HASH(a),
PARTITION BY RANGE(b) (STARTING 1 ENDING 2 EVERY 1);

此外Q可以用多l集来q一步组l数据:

CREATE TABLE demo(a INT, b INT, c INT) IN dbsl1, dbsl2
DISTRIBUTE BY HASH(a),
PARTITION BY RANGE(b) (STARTING 1 ENDING 2 EVERY 1)
ORGANIZE BY DIMENSIONS(c);

q样Q列 a 值相同的所有行都在同一个数据库分区中。所有列 b 值相同的行都在同一个表I间中。对于具有给定的 a ?b 值的行,会将再具有相?c 值的所有行集中C个磁盘上。此Ҏ非常适合?OLAP cd的下L作,q是因ؓQ仅需扫描单个数据库分Z单个表空间中的一个或C扩展数据块就可以满此类查询?/p>

应用表分Z解决常见的应用程序问?/span>

下列各节讨论如何应用各种 DB2 表分区功能以解决常见的应用程序问题。每一节都特别侧重于采取最x施来各U?Informix 分段Ҏ映射到等同的 DB2 表分区方案?/p>

创徏单数据分围时的注意事?/span>

其中一U最常见的表分区应用是根据日期键对大型事实表q行分区。如果需要创建大统一的日期范_误虑使用自动生成?CREATE TABLE 语法格式?/p>

CZ

CZ 1Q?/em>以下CZ昄自动生成的语法格式:

CREATE TABLE orders
(
l_orderkey DECIMAL(10,0) NOT NULL,
l_partkey INTEGER,
l_suppkey INTEGER,
l_linenumber INTEGER,
l_quantity DECIMAL(12,2),
l_extendedprice DECIMAL(12,2),
l_discount DECIMAL(12,2),
l_tax DECIMAL(12,2),
l_returnflag CHAR(1),
l_linestatus CHAR(1),
l_shipdate DATE,
l_commitdate DATE,
l_receiptdate DATE,
l_shipinstruct CHAR(25),
l_shipmode CHAR(10),
l_comment VARCHAR(44))
PARTITION BY RANGE(l_shipdate)
(STARTING '1/1/1992' ENDING '12/31/1993' EVERY 1 MONTH);

q将创徏 24 个范_卛_ 1992-1993 的每个月创徏一个范围。尝试插?l_shipdate 出该范围的行将D错误?/p>

CZ 2Q?/em>上一CZ与以?Informix 语法作比较:

create table orders
(
l_orderkey decimal(10,0) not null,
l_partkey integer,
l_suppkey integer,
l_linenumber integer,
l_quantity decimal(12,2),
l_extendedprice decimal(12,2),
l_discount decimal(12,2),
l_tax decimal(12,2),
l_returnflag char(1),
l_linestatus char(1),
l_shipdate date,
l_commitdate date,
l_receiptdate date,
l_shipinstruct char(25),
l_shipmode char(10),
l_comment varchar(44)
) fragment by expression
l_shipdate < '1992-02-01' in ldbs1,
l_shipdate >= '1992-02-01' and l_shipdate < '1992-03-01' in ldbs2,
l_shipdate >= '1992-03-01' and l_shipdate < '1992-04-01' in ldbs3,
l_shipdate >= '1992-04-01' and l_shipdate < '1992-05-01' in ldbs4,
l_shipdate >= '1992-05-01' and l_shipdate < '1992-06-01' in ldbs5,
l_shipdate >= '1992-06-01' and l_shipdate < '1992-07-01' in ldbs6,
l_shipdate >= '1992-07-01' and l_shipdate < '1992-08-01' in ldbs7,
l_shipdate >= '1992-08-01' and l_shipdate < '1992-09-01' in ldbs8,
l_shipdate >= '1992-09-01' and l_shipdate < '1992-10-01' in ldbs9,
l_shipdate >= '1992-10-01' and l_shipdate < '1992-11-01' in ldbs10,
l_shipdate >= '1992-11-01' and l_shipdate < '1992-12-01' in ldbs11,
l_shipdate >= '1992-12-01' and l_shipdate < '1993-01-01' in ldbs12,
l_shipdate >= '1993-01-01' and l_shipdate < '1993-02-01' in ldbs13,
l_shipdate >= '1993-02-01' and l_shipdate < '1993-03-01' in ldbs14,
l_shipdate >= '1993-03-01' and l_shipdate < '1993-04-01' in ldbs15,
l_shipdate >= '1993-04-01' and l_shipdate < '1993-05-01' in ldbs16,
l_shipdate >= '1993-05-01' and l_shipdate < '1993-06-01' in ldbs17,
l_shipdate >= '1993-06-01' and l_shipdate < '1993-07-01' in ldbs18,
l_shipdate >= '1993-07-01' and l_shipdate < '1993-08-01' in ldbs19,
l_shipdate >= '1993-08-01' and l_shipdate < '1993-09-01' in ldbs20,
l_shipdate >= '1993-09-01' and l_shipdate < '1993-10-01' in ldbs21,
l_shipdate >= '1993-10-01' and l_shipdate < '1993-11-01' in ldbs22,
l_shipdate >= '1993-11-01' and l_shipdate < '1993-12-01' in ldbs23,
l_shipdate >= '1993-12-01' and l_shipdate < '1994-01-01' in ldbs24,
l_shipdate >= '1994-01-01' in ldbs25;

注意QInformix 语法提供了上下不顶的范围以捕获预期范围外的日期。通过d使用 MINVALUE ?MAXVALUE 的范_可以?DB2 语法修改Z Informix 语法匚w?/p>

CZ 3Q?/em>以下CZ示?1 修改Z Informix 语法匚wQ?/p>

CREATE TABLE orders
(
l_orderkey DECIMAL(10,0) NOT NULL,
l_partkey INTEGER,
l_suppkey INTEGER,
l_linenumber INTEGER,
l_quantity DECIMAL(12,2),
l_extendedprice DECIMAL(12,2),
l_discount DECIMAL(12,2),
l_tax DECIMAL(12,2),
l_returnflag CHAR(1),
l_linestatus CHAR(1),
l_shipdate DATE,
l_commitdate DATE,
l_receiptdate DATE,
l_shipinstruct CHAR(25),
l_shipmode CHAR(10),
l_comment VARCHAR(44)
) PARTITION BY RANGE(l_shipdate)
(STARTING MINVALUE,
STARTING '1/1/1992' ENDING '12/31/1993' EVERY 1 MONTH,
ENDING MAXVALUE);

q种技术允许将M日期插入到表中?/p>

使用生成列按表达式进行分?/span>

虽然 DB2 数据库ƈ不直接支持按表达式进行分区,但支持按生成列进行分区,因此有可能获得相同的l果?/p>

在决定是否用此Ҏ前,误虑下列用法准则Q?/p>

  • 生成列是真实的列Q它占用物理盘I间。用生成列的表会略微变大?/li>
  • 对于在分q行分区时所Z的列Q不能改变其生成列表辑ּ。尝试执行此操作生消?SQL0190。如果按下一节描q的方式新数据分区dC用生成列的表中,通常要求改变定义生成列的表达式。目前,不支持改变定义生成列的表辑ּ?/li>
  • 当表使用生成列时Q对于何时可以应用数据分区消除是有限制的?
CZ

CZ 1Q?/em>以下CZ使用 Informix 语法Q在q种情况下适合使用生成列。在本示例中Q进行分区时所Z的列存放了加拿大的省和地域。由于省列表不大可能更改Q因此生成列表达式也不大可能更改?/p>

CREATE TABLE customer (
cust_id INT,
cust_prov CHAR(2))
FRAGMENT BY EXPRESSION
cust_prov = "AB" IN dbspace_ab
cust_prov = "BC" IN dbspace_bc
cust_prov = "MB" IN dbspace_mb
...
cust_prov = "YT" IN dbspace_yt
REMAINDER IN dbspace_remainder;

CZ 2Q?/em>在此CZ中,使用生成列对 DB2 表进行分区:

CREATE TABLE customer (
cust_id INT,
cust_prov CHAR(2),
cust_prov_gen GENERATED ALWAYS AS (CASE
WHEN cust_prov = 'AB' THEN 1
WHEN cust_prov = 'BC' THEN 2
WHEN cust_prov = 'MB' THEN 3
...
WHEN cust_prov = 'YT' THEN 13
ELSE 14 END))
IN tbspace_ab, tbspace_bc, tbspace_mb, .... tbspace_remainder
PARTITION BY RANGE (cust_prov_gen)
(STARTING 1 ENDING 14 EVERY 1);

q里QCASE 语句中的表达式与 FRAGMENT BY EXPRESSION 子句中的相应表达式匹配。CASE 语句每个原始表辑ּ映射C个数字,该数字存储在生成列(在本CZ中是 cust_prov_genQ中。此列是存储在磁盘上的真实列Q因此,表占用的I间量会?DB2® 通过表达式直接支持的分区所必需的空间量略多。本CZ使用短语法格式。因此,必须?CREATE TABLE 语句?IN 子句中列C用来放|数据分区的表空间。如果用长语法格式Q则每个数据分区都需要不同的 IN 子句?/p>



Prayer 2012-03-05 22:57 发表评论
]]>
911错不一定是死锁Q怎么区分死锁和超?http://www.shnenglu.com/prayer/archive/2012/03/01/166847.htmlPrayerPrayerThu, 01 Mar 2012 02:53:00 GMThttp://www.shnenglu.com/prayer/archive/2012/03/01/166847.htmlhttp://www.shnenglu.com/prayer/comments/166847.htmlhttp://www.shnenglu.com/prayer/archive/2012/03/01/166847.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/166847.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/166847.html

d:/>db2 ? sql0911n


SQL0911N因ؓ死锁或超Ӟ所以当前事务已回滚。原因码?br />          "<原因?gt;"?br />
解释:

当前工作单元涉及到未解决的对使用对象的争用,因此不得不回滚?br />
原因码如下:


 2 ׃死锁而导致事务已回滚?br />
 68 ׃锁定时而导致事务已回滚?br />
 72 因ؓ存在与事务中所涉及?nbsp;DB2 Data Links Manager
有关的错误,所以事务已回滚?br />
注释: 必须再次输入与工作单元相关的更改?br />
应用E序已回滚至上一?nbsp;COMMIT?br />
用户响应:

Z帮助避免死锁或锁定超Ӟ寚w旉q行的应用程序或有可能遇到死?br />的应用程序频J发?nbsp;COMMIT 操作Q如果有可能的话Q?br />
联合pȝ用户Q死锁可能发生在联合服务器或数据源上。没有检跨数?br />源ƈ潜在地跨联合系l的死锁的机制。有可能标识使请求失败的数据源(
参阅 Problem Determination Guide 以确定哪一个数据源?nbsp;SQL
语句的处理失败)?br />
当处?nbsp;SQL 语句的某些组合时Q通常会发生死锁或者预期会发生死锁。徏?br />您设计应用程序来可能避免死锁?br />
 sqlcode :  -911

 sqlstate :  40001


d:/>


很明显是两种原因可能造成q样的错误?br />1、死?br />2、锁{待时

怎么区分呢?

思\Q?br />     Ҏ原因码,如果?是死锁引v的;如果?8是时引v的?br />     如果没有获得原因码,那么从系l自带的死锁监视器里认是否发生q死锁,如果没有发生Q则是时引v的?br />
时解决办法Q?br />     1、优化相关sql
     2、g长超时设|?br />
死锁分析ҎQ?br />     用实例用戯接到db2实例Q切换到死锁监视器\径下Q运行db2evmon -path xxx >lock_rpt.txt来生成报告?br />

-- The End --



Prayer 2012-03-01 10:53 发表评论
]]>
不管怎么sortheap的重要性都不ؓq?http://www.shnenglu.com/prayer/archive/2012/02/28/166696.htmlPrayerPrayerTue, 28 Feb 2012 06:58:00 GMThttp://www.shnenglu.com/prayer/archive/2012/02/28/166696.htmlhttp://www.shnenglu.com/prayer/comments/166696.htmlhttp://www.shnenglu.com/prayer/archive/2012/02/28/166696.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/166696.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/166696.html

今天看了一文章,觉得不管怎么sortheap的重要性都不ؓq。理由我后面肯定会写详细的,q里写记录下Q占个位|:

----2007.07.10.00?3Q没惛_?0可以ؓ9号呢 Q?号刚q?img alt="" src="http://acme1921209.iteye.com/javascripts/fckeditor/editor/images/smiley/msn/sad_smile.gif" />Q?/p>

 

========================

感觉学的不是很好Q没有达到目标,但还是把q?天学的写上吧 ?/p>

 1.sortheap在数据库配置说明上是q样的:定义要用于专用排序的专用内存늚最大数目,或者要用于׃n排序的共享内存页的最大数目。现在这个项目ƈ没有启动分区q行性,所以此参数只是表示要用于专用排序的专用内存늚最大数目。不知道是我没理解好Q还是db2没有说好Q其实这个参数还有个很重要的作用Q数据库在执行散列连接sql的时候也用到此内存区域。db2  ?个表q行q接的时候,只有3U类型:嵌套Q合qӞ散列。其中散列连接用的最多(我在执行复杂sql的时候是q样的,单的没有试q大家可以测试下Q。进行散列连接的时候,数据库会把其中一个表的内容复制到sortheap对应的内存中Q如果sortheap对应的内存不够大Q就会吧余下的数据库复制C时表I间中。然后进行连接比较。可以想x作内存和操作盘的差别吧Q所以我们应量大的讄sortheapQ他不溢出到硬盘中Q或者很溢出。(关于上面3中嵌套,合ƈQ散列连接类型,可以看下面的附gQ附件中有很详细的说明)

2.  查看是否溢出的方法:

大家执行下面的命令: db2 gen snapshot for db on 数据库名 Q这个命令不需要打开db2的快照开养Idb2有些默认的快照信息)。在输出的信息中查找下面的信息:

已分配的专用排序堆L          = 0
已分配的׃n排序堆L                    = 0
׃n排序堆高水位标记                      = 0
总计排序                          = 34600
总计排序旉Q毫U)              = 35491
排序溢出                            = 2384
zd排序?nbsp;                                = 0

?/p>

散列q接?nbsp;                       = 38808
散列循环?nbsp;                       = 0
散列q接溢出?nbsp;                   = 534
散列连接溢出数                  = 1

 

 排序溢出 /总计排序   可以得到溢出比例  Q?font size="+0">如果溢出比例大于 3 个百分点Q那么在应用E序 SQL 中会出现严重的或意外的排序问题。因为正是溢出的存在表明发生了大的排序,所以理想的情况是发现没有排序溢出或臛_其百分比于一个百分点?br />如果出现q多的排序溢出,那么“应?#8221;解决Ҏ是增加SORTHEAP的大。然而,q样做只是掩盖了真实的性能问题。相反,您应该确定引h序的 SQL q更改该 SQL、烦引或集来避免或减少排序开销。如果溢出比例大?5 Q作ZU经验之谈)Q那么每个事务的排序数可能很大。虽然某些应用程序事务执行许多小的组合排序(它们不会溢出q且执行旉很短Q,但是它消耗了q多?CPU。当SortsPerTX很大Ӟ按我的经验,q些机器通常会受?CPU 的限制。确定引h序的 SQL q改q存取方案(通过索引、群集或更改 SQLQ对提高事务吞吐率是极ؓ重要的?/font>Q?/p>

散列q接?nbsp;  是在执行sql的时候进行散列连接的数目。这里只说下散列循环?nbsp;的意义,其他参数的意义在下面的附件中都有很详l的说明Q?nbsp; 我在试的时候,把sortheap讄?6个页Q然后执行复杂的sqlQ散列@环数有|而且很高。一般看到散列@环数有值就要注意,他说明你的sortheap或?font size="+0">SHEAPTHRESQ实例参数Q太低了。现在的试情况p明sortheap太低了。另外一U情?font size="+0">SHEAPTHRES太低的原因: SHEAPTHRES已经分配l前面的代理q程了,再有代理q程甌sortheap的时候,SHEAPTHRES已经辑ֈ上限了,q个时候db2׃l申请sortheap的进E很的|此时代理q程q行散列q接的时候就需要把很多数据攑ֈ盘上,q个时候就会导致散列@环数值很高,q个时候大家可以增?SHEAPTHRESq行观察?/font>

 

3.查看排序溢出的sqlҎQ?首先打开快照监视器:  db2 update monitor switches using sort on statements on ;

然后q段旉Q?分钟可以了Q执?get snapshot for all on 数据库名Q?/p>

在输出的信息中查找:语句排序溢出                    = 1   Q看对应的sqlq道了Q对sql的执行计划分析下明白了?/font>

记得在测试完要关?快照开养I db2 update monitor switches using sort off statements off;



http://acme1921209.iteye.com/blog/99526

Prayer 2012-02-28 14:58 发表评论
]]>如何?DB2 UDB 中监控死?/title><link>http://www.shnenglu.com/prayer/archive/2011/12/21/162543.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Wed, 21 Dec 2011 08:59:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2011/12/21/162543.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/162543.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2011/12/21/162543.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/162543.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/162543.html</trackback:ping><description><![CDATA[<a >http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0602jiangt/</a><br /><br /> <p sizcache="23" sizset="76"><a name="N10039"><span id="kykceec" class="atitle">序言</span></a></p> <p>本文的目的就是通过详细的实例来阐述如何在DB2 UDB 中监控死锁的发生。在DB2 UDB中有两种cd的监控器Q快照监控器和事件监控器。快照顾名思义是数据库连l状态下的一个切面,通过快照监控器,你可以很方便地查看当前连接的应用E序Q当前等待的锁,当前的死锁,以及正在执行的SQL语句Q同时你可以查看~冲区,表和表空间的用法。如果保存历史数据,q且能够做出比较Q对于分析数据库的ƈ发性能有很大的帮助?/p> <p>但是我们q不能预什么时候发生死锁,所以如果有一个后台程序能够一直监控数据库的活动,记录下所有的死锁事gQ这对于数据库管理员来说是非帔R要的。DB2 UDB提供了事件监控器。通过不遗漏地获得一D|间内所有的数据库事Ӟ在本文中只关心其中的死锁事gQ,事g监控器提供了一U可以分析历史数据(本文的重点)Q预将来趋势的可能。DB2 UDB同时提供了DB2 Performance Expert (DB2/PE) 或者类似的E序用来生成分析报表Q不q这已经出了本文的范畴?/p> <div id="gameqgg" class="ibm-alternate-rule"> <hr /> </div> <p class="ibm-ind-link ibm-back-to-top" sizcache="23" sizset="77"><a class="ibm-anchor-up-link" >回页?/a></p> <p sizcache="23" sizset="78"><a name="N10045"><span id="moacgwe" class="atitle">常用术语</span></a></p> <p>锁是控制应用E序q发的数据库软g机制Q锁用来防止以下情况的发生:</p> <p>1Q?丢失以前更新</p> <p>2Q?不可重复d</p> <p>3Q?讉K未提交数?/p> <p>锁的模式包括׃n锁和排他锁,׃n锁允许其他程序读取已l被其他׃n锁占用的资源Q所以也叫读锁,排他锁意味着在释放资源以前其他的应用E序无法讉K同一资源Q所以也叫写锁。此外,DB2 UDB q提供了不同的锁U别Q不同的应用E序可能会要求访问不同范围的数据Q锁U别有利于充分利用系l资源,提高pȝ性能。若一个应用程序请求一个锁Q而该锁被另外一个应用程序所使用且不能共享,DB2 UDB ׃挂v前一个应用程序。锁升񔞮是当LOCKLIST (LOCKLIST代表锁能够占用的内存I间) 耗尽或者一个应用程序所拥有的锁大于MAXLOCKS*LOCKLIST的时候(MAXLOCKS 代表应用E序所拥有的锁占所I间的百分比Q,DB2 UDB p图把几个行别的锁合qؓ一个表U别的锁Q从而释NI间。虽焉升本nq不耗费多少旉Q但是锁住整个表通常会大大地降低q发性能?/p> <p>当应用程序处于挂L态超q了一D规定的旉后,DB2 UDB׃自动中止q个应用E序Q同时会向SQLCA发送描q性的错误信息。当两个或者更多的应用E序都持有另外一个应用程序所需资源上的锁,没有q些资源Q那些应用程序都无法l箋完成其工作的时候,׃发生死锁?/p> <p>在DLCHKTIME时之后QDB2 UDB会中止发生死锁的某个应用E序Q通常为所做工作最的那个应用E序Q,q会释放q个应用E序所持有的所有的锁,q允许别的应用程序l工作,DB2 UDB 向被终止的应用E序的SQLCA发送描q性的错误信息。LOCKTIMEOUT 指定一个应用程序被允许的锁{待的时_q将避免全局的死锁从而导致整个应用崩溃。如果LOCKTIMEOUT 的gؓ-1Q应用程序会{待直到该锁被释放或者发生一个死锁?/p> <div id="aceqaai" class="ibm-alternate-rule"> <hr /> </div> <p class="ibm-ind-link ibm-back-to-top" sizcache="23" sizset="79"><a class="ibm-anchor-up-link" >回页?/a></p> <p sizcache="23" sizset="80"><a name="N10060"><span id="iiuyqqo" class="atitle">事g监控?/span></a></p> <p>事g监控器用来收集当一个数据库事g发生时所兌的应用程序的信息。这里的事g指,q接Q死锁,声明和事务。你可以定义你想监控的事件类型的监控器。比如说Q一个死锁监控器是用来监控死锁的发生?/p> <p>在DB2 UDB 中存在两U和死锁有关的事件类型:</p> <ul><li>DEADLOCKS<br />记录单的应用E序信息?/li><li>DEADLOCKS WITH DETAILS<br />记录所有复杂的信息Q包括应用程序、执行语句声明以及死锁的详细信息。但是用这U事件监控器会因为需要得到大量额外的信息而降低系l的性能?</li></ul> <div id="mwgkoek" class="ibm-alternate-rule"> <hr /> </div> <p class="ibm-ind-link ibm-back-to-top" sizcache="23" sizset="81"><a class="ibm-anchor-up-link" >回页?/a></p> <p sizcache="23" sizset="82"><a name="N10079"><span id="iamokqy" class="atitle">如何监控死锁</span></a></p> <p>Z详细说明事g监控器在死锁监控中的用途,我引入了一个简单的死锁场景来触发一个死锁,在随后的章节Q我会告诉读者如何分析监控结果以及根据结果来避免死锁的发生?/p> <p>q里我们需要至三个应用程序来调用DB2 CLIQ一个用来监控死锁的发生Q另外两个用来生死锁。我们可以用DB2 UDB 安装旉带的SAMPLE数据库?/p> <p>1Q?首先建立一个死锁事件监控器</p><br /><a name="N10088"><strong>Session Monitor</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">db2 connect to sample db2 "create event monitor dlmon for tables, deadlocks with details write to file 'C:\dlmon'" mkdir C:\dlmon db2 "set event monitor dlmon state 1" </pre></td></tr></tbody></table><br /> <p>2Q?用另外两个应用程序来产生一个死?/p><br /><a name="N10095"><strong>Session A</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">db2 connect to sample db2 +c "insert into employee values('000350', 'Truman', 'I', 'Jiang', 'B00', '5892', '1999-02-21', 'Engineer', 19, 'M', '1978-06-17', 60000, 2000, 6000)" </pre></td></tr></tbody></table><br /> <p>现在应用E序A拥有了一个EMPLOYEE表的行别的排他?/p> <p>Q注: +c 代表不自动提交SQL语句QDB2 ?autocommit 是缺省设|,也可以通过 db2 update command options using c off 关闭该缺省选项。)</p><br /><a name="N100A5"><strong>Session B</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">db2 connect to sample db2 +c "insert into project values('AD3300', 'Dead Lock Monitor', 'B00', '000350', 7.00, '1982-07-21', '1983-02-03', 'AD3111')" </pre></td></tr></tbody></table><br /> <p>现在应用E序B拥有了一个PROJECT表的行别的排他?/p><br /><a name="N100B2"><strong>Session A</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">db2 +c "select projname from project" </pre></td></tr></tbody></table><br /> <p>应用E序A需要PROJECT表上所有行的共享锁Q但是因为PROJECT表正在被应用E序B以排他锁的Ş式独占,q时候应用程?p入一个锁{待的状态?/p><br /><a name="N100BF"><strong>Session B</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">db2 +c "select firstnme from employee" </pre></td></tr></tbody></table><br /> <p>应用E序B也进入一个锁{待的状态。此时就出现了一个死锁状态?/p> <p>3Q?两个本n处于锁等待ƈ且占有资源的应用E序互相{待另外一Ҏ持有的资源,q时候Session A和Session B出C死锁状态,q种状态一直会延箋直到死锁查器Q超出DLCHKTIME旉以后Q检查出一个死锁ƈ且回滚其中的一个事务?/p><br /><a name="N100CF"><strong>Session B</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">SQLN0991N 因ؓ死锁或者超Ӟ当前事务已经被回滚。原因码?"2". SQLSTATE=40001 q时候死锁事件监控器׃记录q个死锁Q同时应用程序A可以完成他的工作? </pre></td></tr></tbody></table><br /><br /><a name="N100D9"><strong>Session A</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">PROJNAME ---------------------------------------- …… 20 条记录已选择 </pre></td></tr></tbody></table><br /><br /><a name="N100E3"><strong>Session A</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">db2 connect reset </pre></td></tr></tbody></table><br /><br /><a name="N100ED"><strong>Session B</strong></a><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">db2 connect reset </pre></td></tr></tbody></table><br /> <p>4Q?通过 db2evmon 工具可以获得死锁信息的日志,q且把日志文件导入到本地机器的文件系l当中。在下面一节,我们详l分析导出的日志文g?/p><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode">Session Monitor db2 connect reset db2evmon -path c:\dlmon > c:\dlmon\dllog1.txt </pre></td></tr></tbody></table><br /> <div id="kkoikqg" class="ibm-alternate-rule"> <hr /> </div> <p class="ibm-ind-link ibm-back-to-top" sizcache="23" sizset="92"><a class="ibm-anchor-up-link" >回页?/a></p> <p sizcache="23" sizset="93"><a name="N10103"><span id="sugauui" class="atitle">分析监控l果</span></a></p> <p>本节我们开始详l分析上一节生的监控l果Q从监控导出的日志文件中Q我们可以分析出死锁发生的时_U别Q模式以及生死锁的SQL语句Q从而据此来q一步地修正可能q序ƈ发设计或者数据库设计所D的缺陗?/p><br /> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"><pre class="displaycode"> -------------------------------------------------------------------------- EVENT LOG HEADER Event Monitor name: DLMON Server Product ID: SQL08022 …… Server instance name: DB2 -------------------------------------------------------------------------- -------------------------------------------------------------------------- Database Name: SAMPLE Database Path: C:\DB2\NODE0000\SQL00001\ …… -------------------------------------------------------------------------- 3) Deadlock Event ... Deadlock ID: 1 …… 4) Connection Header Event ... Appl Handle: 949 …… 5) Deadlocked Connection ... Deadlock ID: 1 Participant no.: 2 Participant no. holding the lock: 1 Appl Id: G9B56A72.HE13.01B406083205 Appl Seq number: 0001 Appl Id of connection holding the lock: G9B56A72.HD13.02CE06083152 …… Deadlock detection time: 2006-01-06 16:34:27.327582 Table of lock waited on : EMPLOYEE (A锁发生的? Schema of lock waited on : JT Tablespace of lock waited on : USERSPACE1 Type of lock: Row QA锁别ؓ行锁Q? Mode of lock: X - Exclusive QA锁模式ؓ排他锁) Mode application requested on lock: NS - Share (and Next Key Share) Q在A排他锁上要求B׃n锁,发生死锁Q? …… Text : select name from employee Q生B׃n锁的SQL语句Q? List of Locks: Q当前所有锁的列表) …… Lock Name : 0x020005000D0000000000000052 Lock Attributes : 0x00000008 Release Flags : 0x40000000 Lock Count : 1 Hold Count : 0 Lock Object Name : 13 Object Type : Row Tablespace Name : USERSPACE1 Table Schema : JT Table Name : PROJECT Mode : X - Exclusive Q在PROJECT表上有一个排他锁Q? …… Lock Name : 0x02000300000000000000000054 Lock Attributes : 0x00000000 Release Flags : 0x00000001 Lock Count : 1 Hold Count : 0 Lock Object Name : 3 Object Type : Table Tablespace Name : USERSPACE1 Table Schema : JT Table Name : EMPLOYEE Mode : IS - Intent Share Q在EMPLOYEE表上有一个共享锁Q? Locks Held: 6 Locks in List: 6 …… 9) Table Event ... Table schema: JT Table name: EMPLOYEE Record is the result of a flush: FALSE Table type: User Data object pages: 1 …… Rows read: 35 Rows written: 1 …… Tablespace id: 2 Table event timestamp: 2006-01-06 16:37:28.972501 Q记录EMPLOYEE表上发生的事Ӟ </pre></td></tr></tbody></table><br /> <p>我们可以分析一下dllog1.txt 文gQ来准确定位死锁发生的原因,看看5QDeadlocked Connection: 我们可以看出死锁发生的表是EMPLOYEEQ同时我们也可以判断是一个对于已被排他锁占有的资源申请共享锁所D的死锁。更加重要的是我们得C产生死锁的SQL语句Q从上面我们可以推断Z定存在别的应用程序在以独占锁的方式占用EMPLOYEE表,q很有可能就是对于EMPLOYEE表的插入或者更新动作造成的?/p> <p>而这最有可能就是插入或者更C务时间过长所D的,D事务旉q长的原因大体有两种Q一是来自于q发E序的设计和~写Q二是来自于数据库的设计和数据库参数的调整?/p> <p>本节我们通过仔细地分析事件监控器的结果来推断出导致死锁发生的原因Q从而采取有效的措施去避免死锁的发生。这些措施包括调整数据库参数Q或者修改应用程序的代码Q或者修改SQL语句甚至是数据库的设计来提高代码和SQL语句执行的效率?/p> <div id="akeosqg" class="ibm-alternate-rule"> <hr /> </div> <p class="ibm-ind-link ibm-back-to-top" sizcache="23" sizset="94"><a class="ibm-anchor-up-link" >回页?/a></p> <p sizcache="23" sizset="95"><a name="N1011E"><span id="sugqcig" class="atitle">避免死锁的方?/span></a></p> <p>早地考虑数据库设计中的ƈ发性问题,p可以提高代码执行的效率,降低E序开发和l护的成本,q里我们提出了一些避免死锁,提高应用E序q发性的Ҏ?/p> <ul><li>讄隔离U别Q根据应用程序的业务逻辑和数据完整性需求来军_合适的隔离U别Q包括:RRQRSQCSQUR。该军_需要对应用E序需求和相关的业务规则具有基本理?/li><li>量避免锁升U,正确调整参数LOCKLIST, MAXLOCKS</li><li>SQL0911Nq回?8QLOCKTIMEOUT参数Q的原因是锁{待时Q而SQL0911q回?QDLCHKTIME参数Q的原因则是因ؓ死锁被强制回滚,避免q两U错误的Ҏ是合理设计数据库和建立合理的烦?/li><li>快提交事务Q不要在事务中加入不必要的执行时间过长的代码Q比如大的代码@环和q程调用Q或者一些没有用处的SELECT语句</li><li>应用E序的框架实C证一旦发现SQL错误Q立L行回滚事务,释放锁?/li><li>如果多个应用E序讉K同一资源Q最好以相同的次序访问。这P即前一个访问资源的应用E序会gq其他应用程序的讉KQ也不会D死锁的发?/li><li>讑֮外键索引Q如果想删除父表中的行,需要扫描多个子表中的多行数据,q样需要占用多个子表的锁,我们可以通过在外键上建立索引来减扫描子表的行数Q否则若不徏立烦引,如果从父表中删除一行的时候,需要扫描整个子?</li></ul><img src ="http://www.shnenglu.com/prayer/aggbug/162543.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2011-12-21 16:59 <a href="http://www.shnenglu.com/prayer/archive/2011/12/21/162543.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>两阶D|?/title><link>http://www.shnenglu.com/prayer/archive/2011/12/21/162529.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Wed, 21 Dec 2011 06:30:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2011/12/21/162529.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/162529.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2011/12/21/162529.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/162529.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/162529.html</trackback:ping><description><![CDATA[ 一阶段提交(1PC One Phase Commit) <div> <wbr></wbr> <wbr></wbr> <wbr></wbr>一 阶段提交是事务处理器向数据库服务器发出提交hQ然后等待数据库服务器的回应Q收到回应后完成事务的提交,或者服务器q回提交p|的结果就回撤事务?危险期从发出h开始,到收到回应结束,q段旉中数据库完成数据的修攏V日志记录等处理Q处理越复杂Q危险期pѝ?/div> <div> <wbr></wbr></div> <h5> <wbr></wbr> <wbr></wbr> <wbr></wbr>两阶D|?2PC <wbr></wbr>Two Phase Commit)</h5> <p> <wbr></wbr> <wbr></wbr> <wbr></wbr> 两阶D|交把事务提交分成两个阶段Q?/p> <ul><li>W一阶段Q事务处理器向数据库服务器发?准备提交"hQ数据库收到h后执行相同的数据修改和日志记录等处理Q不同的是处理完成后只是把事务的状态改?可以提交",然后把结果返回给事务处理器?/li><li>事务处理器收到回应后q入W二阶段Q如果在W一阶段内的危险期中发生了故障,事务处理器收不到回应Q则认ؓ事务p|Q回撤事务。数据库服务器收不到W二阶段的确认提交请求,?可以提交"的事务回?</li><li>两阶D늚W二阶段中事务处理器向数据库服务器发?认提交"hQ数据库服务器把事务?可以提交"状态改?提交完成"状态,然后q回应答?</li></ul> <p> <wbr></wbr> <wbr></wbr> 从严格意义上_两阶D|交ƈ没有完全解决|络通讯危险期的问题Q?strong>但因为第二阶D늚处理很简单,只是修改了事务的状态,与第一阶段相比其处理时间极短,所以危险期极短Q发生事务提交故障的可能性几乎不存在?nbsp;<wbr></wbr></strong></p> <p> </p> <div>所谓两阶段提交, 即Two Phase Commit (2PC), 是分布式事务采用的一U处?/div><img src ="http://www.shnenglu.com/prayer/aggbug/162529.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2011-12-21 14:30 <a href="http://www.shnenglu.com/prayer/archive/2011/12/21/162529.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>主键与唯一索引http://www.shnenglu.com/prayer/archive/2011/12/21/162519.htmlPrayerPrayerWed, 21 Dec 2011 02:58:00 GMThttp://www.shnenglu.com/prayer/archive/2011/12/21/162519.htmlhttp://www.shnenglu.com/prayer/comments/162519.htmlhttp://www.shnenglu.com/prayer/archive/2011/12/21/162519.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/162519.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/162519.html     2.一个表中可以有多个唯一性烦引,但只能有一个主键;
     3.主键列不允许I|而唯一性烦引列允许I倹{?img src ="http://www.shnenglu.com/prayer/aggbug/162519.html" width = "1" height = "1" />

Prayer 2011-12-21 10:58 发表评论
]]>
詹姆斯h?http://www.shnenglu.com/prayer/archive/2011/12/21/162517.htmlPrayerPrayerWed, 21 Dec 2011 02:58:00 GMThttp://www.shnenglu.com/prayer/archive/2011/12/21/162517.htmlhttp://www.shnenglu.com/prayer/comments/162517.htmlhttp://www.shnenglu.com/prayer/archive/2011/12/21/162517.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/162517.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/162517.html詹姆?#183;格雷

                              ——数据库技术和“事务处理”专家

1998q度的图灵奖授予了声誉卓著的数据库专家詹姆斯·格雷(James Gray)或称吉姆·格雷(JimGrayQJim是James的昵U?。这是图灵奖诞生32q的历史上,l数据库技术的先驱查尔?#183;巴赫?Charles WQBachmanQ?973)和关pL据库之父埃d?#183;Ud(Edgar FQCoddQ?981)之后Q第3位因在推动数据库技术的发展中做出重大A献而获此殊荣的学者?/font>

    格雷生于1944q_在著名的国加州大学伯克利分校计机U学p获得博士学位。其博士论文是有关优先文法语法分析理论的。学成以后,他先后在贝尔实验室、IBM、Tandem、DEC{公司工作,研究方向转向数据库领域?/font>

    在IBM期间Q他参与和主持过IMS、System R、SQLQDS、DB2{项目的开发,其中除System R仅作为研I原型,没有成ؓ产品外,其他几个都成为IBM在数据库市场上有影响力的产品?/font>

    在Tandem期间Q格雷对该公司的主要数据库品ENCOMPASSq行了改q与扩充Qƈ参与了系l字典、ƈ行排序、分布式SQL、Nonstop SQL{项目的研制工作?/font>

    在DECQ他仍然主要负责数据库品的技术。格雯入数据库领域Ӟ关系数据库的基本理论已经成熟Q但各大公司在关pL据库理pȝ(RDBMS)的实现和产品开发中Q都遇到了一pd技术问题,主要是在数据库的规模愈来愈大Q数据库的结构愈来愈复杂Q又有愈来愈多的用户׃n数据库的情况下,如何保障数据的完整?Integrity)、安全?Security)、ƈ行?Concurrency)Q以及一旦出现故障后Q数据库如何实现从故障中恢复(Recovery)。这些问题如果不能圆满解冻I无论哪个公司的数据库产品都无法进入实用,最l不能被用户所接受。正是在解决q些重大的技术问题,使DBMS成熟q利进入市场的q程中,格雷以他的聪明才智发挥了十分关键的作用?/font>

目前Q各DBMS解决上述问题的主要技术手D和Ҏ如下Q?/font>

1Q把Ҏ据库的操作划分ؓUC?#8220;事务”(?#8220;事务?#8221;Qtransaction)的一个个原子单位。事务是事务处理(transaction processing)的基本执行单位,即一个事务中的操作要么全部被执行Q要么全部都不执行,卛_行所谓all or none的原则。一个事务一般以一?#8220;开?#8221;语句(begin)开始,先从数据库中取出一些数据,然后q行所需的处理,最后以“提交”语句(commit)l束。如事务中发生异常,则用“异常l止”语句(abort)?#8220;回退”语句(rollback)撤销本事务执行过E中Ҏ据库已做的所有更?x谓undo)Q将数据库恢复到事务开始时的正状态,以保障数据的完整性、一致性?/font>

    2Q用户在Ҏ据库发出操作hӞpȝҎ关的不同_度(granularity)的数据元?字段、记录以x个文?“加锁”(10cking)Q加锁的数据被暂时止其他用户讉K(我们q里仅是一U简化的解释Q实际上Q根据用户对数据h的不同性质Q加锁的数据如何对待另一用户的请求,呈现复杂的情况,例如Q如果加锁的数据被修改Q那是绝对禁止其他用戯问的Q而如果加锁的数据只用于读出,则其他用Ldhq将是允许的。这由所?#8220;锁相Ҏ矩?#8221;——lock compatibility matrix理和控?。操作完成后“解锁”(unlocking)。这一机制用以既保持事务之间的“q发?#8221;Q又保证数据?#8220;完整?#8221;?/font>

    3Q徏立系l运行日?10g)Q记载各事务的始炏V终点以及在事务中被更新q的面的改前和改后状况(before image和afterimage)Q以便在pȝ出现散障使数据库遭到破坏Ӟ能根据定期或不定期ؓ数据库所作的备䆾(backup)加上日志中的信息数据库恢复到系l故障前的正状态,同时又能保留最后一ơ备份以来对数据库所作的修改?/font>

    4。对数据库的M更新分两阶段提交(two-phase commit)。这是基于一个事务可能同时涉及两个不同的数据库系l而必需的,q在分布式系l中ؓ重要?/font>

    上述及其他各U方法可ȝ?#8220;事务处理技?#8221;(transaction processing technique)。格雷在事务处理技术上的创造性思维和开拓性工作,使他成ؓ该技术领域公认的权威。他的研I成果反映在他发表的一pd论文和研I报告之中,最后结晶ؓ一部厚厚的专著Transaction ProcessingQConcepts and Techniques(Morgan Kaufmann PublishersQ?993Q另一作者ؓ德国斯图加特大学的AQReuter教授)。事务处理技术虽然诞生于数据库研IӞ但对于分布式pȝQclientQserverl构中的数据理与通信Q对于容错和高可靠性系l,同样h重要的意义?/font>

    格雷的另一部著作是The Benchmark HandbookQfor Database and Transaction Processing SystemsQ第1版于1991q_W?版于1993q出版,也是Morgan Kaufmann出版Cև版的。格雯是该出版C?#8220;数据理pȝ丛书”的主~?/font>

    格雷在数据库学术界十分活跃。国际上定期或不定期举行的一些重要的数据库学术会议如VLDB、SIGMOD上,都能见到他的w媄Q听C的声韟뀂除了在公司从事研究开发外Q他q兼职在母校伯克利、斯坦福大学、布达佩斯大学从事过教学和讲学活动?992q_VLDB杂志(The VLDB Journal)创刊Q他ZQȝ?/font>

    格雷是ACM?988q授予IBM的System R以Y件系l奖?位得奖h之一Q其?人是Donald Chamberlin、Raymond Lorie、Gianfranco Putzolu、Patricia Selinger和Irving Traiger。正是由于格雷在数据库技术方面的声誉QY件业中的“巨无?#8221;微Y公司?993q决定进入大型关pL据库市场Ӟ才不惜用U种手段把格雷从DEC公司挖过来。因格雷不喜Ƣ微软总部所在的多雨的西雅图Q愿意留在阳光灿烂的旧金山,微Y特地在旧金山开辟第二个微Y研究院v湑֌研究中心BARC(Bay Area Research Center)Q安排格雷Q该研Iȝ。格h然不负所望,领导一个研制小l开发出了MS SQL Server 7Q?Q成为微软历史上一个里E碑式的版本Q而且也成为当今关pL据库市场上的g者?/font>

    格雷是在1999q??日于亚特兰大举行的ACM全国会议上接受图灵奖的。格雷发表了“信息技术今后的目标”的演?What Next?一A dozen remaining IT problems)Q纵Z信息技术发展中有关的几个方向性问题。后来,该文l修改后在SIGMOD的会上以What Next?一A dozen IT Research Goals为题再次发表。格L演说在对计算技术的发展作ȝ性回时认ؓQ英国数学家巴贝?Charles BabageQ?791—1871)?9世纪所梦想和追求的计算Z天已l基本实玎ͼ国数学家布什(Vannevar BushQ?890—1974Q曾ȝ斯福ȝ的科学顾?20世纪40q代所设想?#8220;梅米克斯”MEMEX?#8220;记忆延?#8221;(MEMory EXtender)当前已接q实玎ͼ而图灉|提出的智能机器离实现q有一D距,目前的计机q难以通过“囄试”。ؓ了完全实Cq?位科学巨人的理想Q格雷呼吁美国政府要重视支持对IT技术的长期研究Q认为其重要意义不亚?00q前杰弗?Thomas JeffersonQ?743—1826Q?#8220;独立宣言”的v草者,国W三LȝQ?801—1809在位)军_? 500万美元从法国政府手中买回路易斯安娜领?Louisiana TerritoryQ这是位于密西西比河和洛矶山脉之_北至加拿大,南达墨西哥湾的大块土圎ͼ面积? 070 000km2)q一被称为Louisiana Purchase的著名历史事Ӟ然后又派Z刘易斯上?Captain Meriwether Lewis)和克拉克(William Clark)为首?#8220;发现军团(Corps for Discovery)到西部探险直臛_qx岸Qؓ最lŞ成美国如今的版图奠定了基。格雯为,一个好的IT长期目标应具有以?个关键性:

    1Q可理解?nbsp; 目标应能单表qƈ被h理解?/font>

    2Q有挑战?nbsp; 如何辑ֈ目标不是很明昄?/font>

    3Q用途广?nbsp; 不只对计机U学家有用,而是对大多数人有用?/font>

  4Q可试?nbsp; 以便查项目进展ƈ知道目标是否已经辑ֈ?/font>

    5Q渐q?nbsp; 中间有若q里E碑Q以查项目进展ƈ鼓舞研究人员q下厅R?/font>

    在以上论Ҏ持下Q格h出的几个IT技术的长期研究目标如下Q?/font>

    1Q规模可伸羃?scalability)?/font>

    2Q通过囄试?/font>

    3Q语韛_文本的{?Speech to Text)?/font>

    4Q文本到语音的{?Text to Speech)?/font>

    5Q机器视觉,能像Z栯别物体和q动?/font>

    6.个h?#8220;梅米克斯”Q可记录人所看到和听到的一切,需要时快速检索出来?/font>

    7Q世界的“梅米克斯”Q即建立文本、音乐、图像、艺术、电q“全集”(corpus)Q可回答有关的Q何提问,像hcM安样快而好地做索引Q做文摘?/font>

    8Q虚拟现?格雷用了TelePreseneeq个词,参见?969q图灵奖获得者明斯基的介l??/font>

    9Q无故障pȝ(Trouble-Free Systems)?/font>

    10Q安全系l?Secure Systems)?/font>

    11Q高可用pȝ(AlwaysUp)?/font>

    12Q自动程序设?Automatic Programming)?/font>

  格雷的图灵奖演说全文已由W者译出,摘要刊于《中国计机报?000q?月,有兴的读者可以一阅?/font>

    目前Q格h人正在从事Scalabilityq一长期目标的研IӞ他是微Y“规模可׾~的服务器研I小l?#8221;(Scalable Servers Research Group)的高U研I员Q该目已有若干研究成果在网上公布?/font>

    格雷的电子信׃ؓQ?/font>

    gray @ microsoftQcom

他的因特|个ZؓQ?/font>

httpQ?/wwwQresearchQmicrosoftQcom/researchQbarcQgray

(引用?http://202.207.0.245:9001/jisuanjifazhanshi/tuling/33.htm)

 

 



Prayer 2011-12-21 10:58 发表评论
]]>DB2 Merge语句http://www.shnenglu.com/prayer/archive/2011/10/18/158618.htmlPrayerPrayerTue, 18 Oct 2011 07:42:00 GMThttp://www.shnenglu.com/prayer/archive/2011/10/18/158618.htmlhttp://www.shnenglu.com/prayer/comments/158618.htmlhttp://www.shnenglu.com/prayer/archive/2011/10/18/158618.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/158618.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/158618.html  DB2 Merge语句的作用非常强大,它可以将一个表中的数据合ƈ到另一个表中,在合q的同时可以q行插入、删除、更新等操作。我们还是先来看个简单的例子吧,假设你定义了一个雇员表(employe)Q一个经理表(manager)Q如下所C:

  ---雇员?EMPLOYE)

以下是代码片D:
    CREATE TABLE EMPLOYE (
  EMPLOYEID INTEGER NOT NULL,---员工?
  NAME VARCHAR(20) NOT NULL,---姓名
  SALARY DOUBLE---薪水
  );
  INSERT INTO EMPLOYE (EMPLOYEID,NAME,SALARY) VALUES
  (1,'张三',1000),
  (2,'李四',2000),
  (3,'王五',3000),
  (4,'赵六',4000),
  (5,'高七',5000);

  --l理?MANAGER)

以下是代码片D:
    CREATE TABLE MANAGER (
  EMPLOYEID INTEGER NOT NULL,---l理?
  NAME VARCHAR(20) NOT NULL,---姓名
  SALARY DOUBLE---薪水
  );
  INSERT INTO MANAGER (MANAGERID,NAME,SALARY) VALUES
  (3,'王五',5000),
  (4,'赵六',6000);

  ---雇员?EMPLOYE)

以下是代码片D:
    CREATE TABLE EMPLOYE (
  EMPLOYEID INTEGER NOT NULL,---员工?
  NAME VARCHAR(20) NOT NULL,---姓名
  SALARY DOUBLE---薪水
  );
  INSERT INTO EMPLOYE (EMPLOYEID,NAME,SALARY) VALUES
  (1,'张三',1000),
  (2,'李四',2000),
  (3,'王五',3000),
  (4,'赵六',4000),
  (5,'高七',5000);

  --l理?MANAGER)

以下是代码片D:
    CREATE TABLE MANAGER (
  EMPLOYEID INTEGER NOT NULL,---l理?
  NAME VARCHAR(20) NOT NULL,---姓名
  SALARY DOUBLE---薪水
  );
  INSERT INTO MANAGER (MANAGERID,NAME,SALARY) VALUES
  (3,'王五',5000),
  (4,'赵六',6000);

 l过一D|_你发现这L数据模型Q或者说表结构设计简直就是一大|W,l理和雇员都是员工嘛Qؓ什么要设计两个表呢Q发现错误后需要改正,所以你军_Q删除经理表(MANAGER)表,MANAGER 表中的数据合q到EMPLOYE 表中Q仔l分析发玎ͼ王五在两个表中都存在(可能是干的好升官?Q而刘八在EMPLOYE 表中q不存在Q现在,我们要求把EMPLOYE 表中不存在的MANAGER都插入到EMPLOYE 表中Q存在的更新薪水。该怎么办呢Q这个问题ƈ不难Q通常Q我们可以分两步Q如下所C:

  --更新存在?/p>

以下是代码片D:
    UPDATE EMPLOYE AS EM SET SALARY=(SELECT SALARY FROM MANAGER WHERE MANAGERID=EM.EMPLOYEID)
  WHERE EMPLOYEID IN (
  SELECT MANAGERID FROM MANAGER
  );

  ---插入不存在的

以下是代码片D:
    INSERT INTO EMPLOYE (EMPLOYEID,NAME,SALARY)
  SELECT MANAGERID,NAME,SALARY FROM MANAGER WHERE MANAGERID NOT IN (
  SELECT EMPLOYEID FROM EMPLOYE
  );

  --更新存在?/p>

以下是代码片D:
    UPDATE EMPLOYE AS EM SET SALARY=(SELECT SALARY FROM MANAGER WHERE MANAGERID=EM.EMPLOYEID)
  WHERE EMPLOYEID IN (
  SELECT MANAGERID FROM MANAGER
  );

  ---插入不存在的

以下是代码片D:
    INSERT INTO EMPLOYE (EMPLOYEID,NAME,SALARY)
  SELECT MANAGERID,NAME,SALARY FROM MANAGER WHERE MANAGERID NOT IN (
  SELECT EMPLOYEID FROM EMPLOYE
  );

  上面的处理是可以的,但是我们q可以有更简单的ҎQ就是用Merge语句Q如下所C:

以下是代码片D:
    MERGE INTO EMPLOYE AS EM
  USING MANAGER AS MA
  ON EM.EMPLOYEID=MA.MANAGERID
  WHEN MATCHED THEN UPDATE SET EM.SALARY=MA.SALARY
  WHEN NOT MATCHED THEN INSERT VALUES (MA.MANAGERID,MA.NAME,MA.SALARY);
  MERGE INTO EMPLOYE AS EM
  USING MANAGER AS MA
  ON EM.EMPLOYEID=MA.MANAGERID
  WHEN MATCHED THEN UPDATE SET EM.SALARY=MA.SALARY
  WHEN NOT MATCHED THEN INSERT VALUES (MA.MANAGERID,MA.NAME,MA.SALARY);

 


 在上面的处理中,我们用经理表(MANAGER)的薪水更C雇员?EMPLOYE)的薪_假设现在要求Q如果经理表(MANAGER)的薪?gt;雇员?EMPLOYE)的薪水的时候更斎ͼ否则不更斎ͼ怎么办呢Q如下:

以下是代码片D:
    MERGE INTO EMPLOYE AS EM
  USING MANAGER AS MA
  ON EM.EMPLOYEID=MA.MANAGERID
  WHEN MATCHED AND EM.SALARY
  WHEN NOT MATCHED THEN INSERT VALUES (MA.MANAGERID,MA.NAME,MA.SALARY);
  MERGE INTO EMPLOYE AS EM
  USING MANAGER AS MA
  ON EM.EMPLOYEID=MA.MANAGERID
  WHEN MATCHED AND EM.SALARY
  WHEN NOT MATCHED THEN INSERT VALUES (MA.MANAGERID,MA.NAME,MA.SALARY);

  不仔l的朋友可能没有看出上面两条语句的区别,哈哈Q请仔细Ҏ一下这两条语句。上面的语句中多了ELSE IGNORE语句Q它的意思正如它英文的意思,其它情况忽略不处理。如果你认ؓ理论上应该不存在EM.SALARY>MA.SALARY的数据,如果有,说明有问题,你想抛个异常Q怎么办?如下Q?/p>

以下是代码片D:
    MERGE INTO EMPLOYE AS EM
  USING MANAGER AS MA
  ON EM.EMPLOYEID=MA.MANAGERID
  WHEN MATCHED AND EM.SALARY
  WHEN MATCHED AND EM.SALARY>MA.SALARY THEN SIGNAL SQLSTATE '70001' SET MESSAGE_TEXT = 'EM.SALARY>MA.SALARY'
  WHEN NOT MATCHED THEN INSERT VALUES (MA.MANAGERID,MA.NAME,MA.SALARY)
  ELSE IGNORE;
  MERGE INTO EMPLOYE AS EM
  USING MANAGER AS MA
  ON EM.EMPLOYEID=MA.MANAGERID
  WHEN MATCHED AND EM.SALARY
  WHEN MATCHED AND EM.SALARY>MA.SALARY THEN SIGNAL SQLSTATE '70001' SET MESSAGE_TEXT = 'EM.SALARY>MA.SALARY'
  WHEN NOT MATCHED THEN INSERT VALUES (MA.MANAGERID,MA.NAME,MA.SALARY)
  ELSE IGNORE;

  对于EM.SALARY>MA.SALARY的情况,如果你不x异常Q而是删除EMPLOYE中的数据Q怎么办?如下Q?/p>

以下是代码片D:
    MERGE INTO EMPLOYE AS EM
  USING MANAGER AS MA
  ON EM.EMPLOYEID=MA.MANAGERID
  WHEN MATCHED AND EM.SALARY
  WHEN MATCHED AND EM.SALARY>MA.SALARY THEN DELETE
  WHEN NOT MATCHED THEN INSERT VALUES (MA.MANAGERID,MA.NAME,MA.SALARY)
  ELSE IGNORE;
  MERGE INTO EMPLOYE AS EM
  USING MANAGER AS MA
  ON EM.EMPLOYEID=MA.MANAGERID
  WHEN MATCHED AND EM.SALARY
  WHEN MATCHED AND EM.SALARY>MA.SALARY THEN DELETE
  WHEN NOT MATCHED THEN INSERT VALUES (MA.MANAGERID,MA.NAME,MA.SALARY)
  ELSE IGNORE;

  以上单介l了Merge语句的用,它的应用不只是上面介l的情况Q其实它可以应用在很多其他语句不好处理情况,q需要你d玎ͼC熟能生y





Prayer 2011-10-18 15:42 发表评论
]]>
DB2 锁升U失败将引v死锁http://www.shnenglu.com/prayer/archive/2010/12/14/136361.htmlPrayerPrayerTue, 14 Dec 2010 02:39:00 GMThttp://www.shnenglu.com/prayer/archive/2010/12/14/136361.htmlhttp://www.shnenglu.com/prayer/comments/136361.htmlhttp://www.shnenglu.com/prayer/archive/2010/12/14/136361.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/136361.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/136361.htmlDB2 锁升U失败将引v死锁 文章分类:数据?/font>
--start
引用

DB2 SQL error: SQLCODE: -911, SQLSTATE: 40001, SQLERRMC: 2
Message: The current transaction has been rolled back because of a deadlock or timeout.  Reason code "2".


    昨天Q执行了一条很单的SQLQ却怎么也执行不成功Q报的错误如上所C,是死锁。既然是死锁Q那p一会执行吧。等了一会后仍然死锁。到底是哪个事务和哪个事务相互锁了呢Q查询了老半天才发现原来q条SQL语句更新的数据量非常大,D锁升U,然后锁升U又p|了,D了死锁。原来锁升p|会导致死锁。所以,通常我们应该LOCKLIST和MAXLOCK参数调整到够大Q尽量避免锁{待、锁升Q发挥数据库的最大ƈ发性?


Prayer 2010-12-14 10:39 发表评论
]]>
如何使用db2expln工具查看某个E序包中SQL语句的存取计?/title><link>http://www.shnenglu.com/prayer/archive/2010/10/15/130037.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Fri, 15 Oct 2010 07:33:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2010/10/15/130037.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/130037.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2010/10/15/130037.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/130037.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/130037.html</trackback:ping><description><![CDATA[<p><font size=2>举个例子Q对于数据库SAMPLE中程序包DB2INST1.P0203450Q用下面命令:<br>db2expln -d SAMPLE -g -c db2inst1 -p P0203450 -s 0 -t<br>其中<br>-g 是指l出存取计划的图形输?用字W模拟的)<br>-s 0 是指分析所有的SQL命o</font></p> <p><font size=2>下面是相应的输出Q?br>DB2 Universal Database Version 7.2, 5622-044 (c) Copyright IBM Corp. 1991, 2001<br>Licensed Material - Program Property of IBM<br>IBM DATABASE 2 SQL Explain Tool</font></p> <p><font size=2>Processing package DB2INST1.P0203450.<br>******************** PACKAGE *********************</font></p> <p><font size=2>Package Name = DB2INST1.P0203450<br><font color=#f0f0f0>--------</font>Prep Date = 2002/12/17<br><font color=#f0f0f0>--------</font>Prep Time = 16:02:04</font></p> <p><font size=2><font color=#f0f0f0>--------</font>Bind Timestamp = 2002-12-17-16.02.04.373971</font></p> <p><font size=2><font color=#f0f0f0>--------</font>Isolation Level <font color=#f0f0f0>--------</font><font color=#f0f0f0>-</font>= Cursor Stability<br><font color=#f0f0f0>--------</font>Blocking<font color=#f0f0f0>--------</font><font color=#f0f0f0>--------</font> = Block Unambiguous Cursors<br><font color=#f0f0f0>--------</font>Query Optimization Class = 5</font></p> <p><font size=2><font color=#f0f0f0>--------</font>Partition Parallel <font color=#f0f0f0>------</font>= No<br><font color=#f0f0f0>--------</font>Intra-Partition Parallel = No</font></p> <p><font size=2><font color=#f0f0f0>--------</font>Function Path<font color=#f0f0f0>--------</font><font color=#f0f0f0>---</font> = "SYSIBM", "SYSFUN", "DB2INST1"</font></p> <p><font size=2>Processing Section 1.<br>-------------------- SECTION ----------------------<br>......<br>-------------------- SECTION ----------------------<br>Section = 2</font></p> <p><font size=2>SQL Statement:<br><br>update STAFF set NAME = 'test' <br>where ID = 350</font></p> <p><font size=2>Estimated Cost = 75<br>Estimated Cardinality = 2</font></p> <p><font size=2>Access Table Name = DB2INST1.STAFF ID = 2,3<br>| #Columns = 2<br>| Relation Scan<br>| | Prefetch: Eligible<br>| Lock Intents<br>| | Table: Intent Exclusive<br>| | Row : Update<br>| Sargable Predicate(s)<br>| | #Predicates = 1<br>Update: Table Name = DB2INST1.STAFF ID = 2,3</font></p> <p><font size=2>End of section</font></p> <p><font size=2>Optimizer Plan:</font></p> <p><font size=2><font color=#f0f0f0>------</font>UPDATE <br><font color=#f0f0f0>------</font>( -2) <br><font color=#f0f0f0>------</font>/<font color=#f0f0f0>--</font> \<br><font color=#f0f0f0>-</font>TBSCAN <font color=#f0f0f0>--</font>Table: <br><font color=#f0f0f0>--</font>( 3) <font color=#f0f0f0>--</font>DB2INST1 <br><font color=#f0f0f0>---</font>|<font color=#f0f0f0> -----</font>STAFF <br>Table: <br>DB2INST1 <br>STAFF <br>......</font></p> <p><font size=2><br>可以用下面命令找出数据库中存在的E序包:<br>db2 "select pkgschema, pkgname from syscat.packages"<br>上面例子中的E序包DB2INST1.P0203450是一个存储过E?/font></p> <p> </p> <img src ="http://www.shnenglu.com/prayer/aggbug/130037.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2010-10-15 15:33 <a href="http://www.shnenglu.com/prayer/archive/2010/10/15/130037.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>db2讄参数数据及更?/title><link>http://www.shnenglu.com/prayer/archive/2010/10/15/130031.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Fri, 15 Oct 2010 07:26:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2010/10/15/130031.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/130031.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2010/10/15/130031.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/130031.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/130031.html</trackback:ping><description><![CDATA[<pre>#!/bin/sh # ******************************************************* # DB2 ENVIRONMENT VARIABLES # ******************************************************* db2set DB2_MMAP_READ=NO db2set DB2_MMAP_WRITE=NO db2set DB2_FMP_COMM_HEAPSZ= db2set DB2_EVALUNCOMMITTED=YES db2set DB2_SKIPINSERTED=YES db2set DB2_SKIPDELETED=YES db2set DB2_HASH_JOIN=NO # ******************************************************* # DB2 DATABASE MANAGER SETTINGS; NOTE: MONITORING # IS OFF TO REDUCE CPU; YOUR APPLICATION MAY REQUIRE # MONITORS TO BE ON, SO CHANGE ACCORDINGLY # ******************************************************* db2 update dbm cfg using NUMDB 4 db2 update dbm cfg using DFT_MON_BUFPOOL OFF db2 update dbm cfg using DFT_MON_LOCK OFF db2 update dbm cfg using DFT_MON_SORT OFF db2 update dbm cfg using DFT_MON_STMT OFF db2 update dbm cfg using DFT_MON_TABLE OFF db2 update dbm cfg using DFT_MON_UOW OFF db2 update dbm cfg using DFT_MON_TIMESTAMP OFF db2 update dbm cfg using MON_HEAP_SZ 10000 db2 update dbm cfg using UDF_MEM_SZ 256 db2 update dbm cfg using JAVA_HEAP_SZ 512 db2 update dbm cfg using SHEAPTHRES 10000 db2 update dbm cfg using DIR_CACHE YES db2 update dbm cfg using ASLHEAPSZ 15 db2 update dbm cfg using RQRIOBLK 65535 db2 update dbm cfg using QUERY_HEAP_SZ 16384 db2 update dbm cfg using DRDA_HEAP_SZ 128 # ******************************************************* # DB2 DATABASE MANAGER SETTINGS FOR CONNECTIONS AND AGENTS # SHOWN HERE SUPPORTS 1200 CONCURRENT CONNECTIONS! # ******************************************************* db2 update dbm cfg using FENCED_POOL 200 db2 update dbm cfg using NUM_INITAGENTS 50 db2 update dbm cfg using MAXAGENTS 200 db2 update dbm cfg using MAX_COORDAGENTS 200 db2 update dbm cfg using NUM_INITFENCED 50 db2 update dbm cfg using NUM_POOLAGENTS 200 db2 update dbm cfg using MAX_CONNECTIONS 200 # ******************************************************* # UPDATE YOUR DATABASE SETTINGS # ******************************************************* db2 update db cfg for yourdb using DFT_QUERYOPT 2 db2 update db cfg for yourdb using DBHEAP 1200 db2 update db cfg for yourdb using CATALOGCACHE_SZ 64 db2 update db cfg for yourdb using LOGBUFSZ 128 db2 update db cfg for yourdb using UTIL_HEAP_SZ 5000 db2 update db cfg for yourdb using LOCKLIST 1000 db2 update db cfg for yourdb using APP_CTL_HEAP_SZ 1000 db2 update db cfg for yourdb using APPGROUP_MEM_SZ 60000 db2 update db cfg for yourdb using SORTHEAP 256 db2 update db cfg for yourdb using STMTHEAP 4096 db2 update db cfg for yourdb using APPLHEAPSZ 4096 db2 update db cfg for yourdb using PCKCACHESZ 5000 db2 update db cfg for yourdb using STAT_HEAP_SZ 4384 db2 update db cfg for yourdb using MAXLOCKS 25 db2 update db cfg for yourdb using LOCKTIMEOUT 60 db2 update db cfg for yourdb using CHNGPGS_THRESH 60 db2 update db cfg for yourdb using NUM_IOCLEANERS 4 db2 update db cfg for yourdb using NUM_IOSERVERS 6 db2 update db cfg for yourdb using MAXAPPLS 1200 db2 update db cfg for yourdb using AVG_APPLS 1 db2 update db cfg for yourdb using MAXFILOP 64 db2 update db cfg for yourdb using LOGFILSIZ 1000 db2 update db cfg for yourdb using LOGPRIMARY 10 db2 update db cfg for yourdb using LOGSECOND 20</pre> <pre>-------------------</pre> <pre>讄当前模式Q?/pre> <pre>set current path = oais(模式?</pre> <pre>查看当前的模式:</pre> <pre>db2 values(current path)</pre> <pre>讄为默认的、缺省的Q?/pre> <pre>set current path = system path</pre> <pre>----------------------------------------</pre> <pre>详细的列表信息请查看Q? <p>see IBM publib site for <a ><u><font color=#0000ff>Database tuning overview</font></u></a>.</p> </pre> <img src ="http://www.shnenglu.com/prayer/aggbug/130031.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2010-10-15 15:26 <a href="http://www.shnenglu.com/prayer/archive/2010/10/15/130031.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>db2表名大小写问?/title><link>http://www.shnenglu.com/prayer/archive/2010/08/05/122320.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Thu, 05 Aug 2010 08:16:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2010/08/05/122320.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/122320.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2010/08/05/122320.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/122320.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/122320.html</trackback:ping><description><![CDATA[<p class=smalltitle>今天在查warehous数据库下的表Linux_CPU</p> <p class=smalltitle><a onclick="javascript:tagshow(event, 'db2');" href="javascript:;" target=_self><u><strong><font color=#0000ff>db2</font></strong></u></a> "select * from Linux_CPU" L提示表未定义.后来发现表名大小写问?应该在db2提示W下q行 select * from "Linux_CPU"或者db2 "select * from \"Linux_CPU\""才正?.晚上?a onclick="javascript:tagshow(event, 'IBM');" href="javascript:;" target=_self><u><strong><font color=#0000ff>IBM</font></strong></u></a>|站上查到详l说?</p> <h1 class=smalltitle>如何定义和用含写字符?DB2 表名Q?/h1> <img class=display-img title=点击囄可在新窗口打开 style="CURSOR: pointer" height=6 alt="" src="http://www.ibm.com/i/c.gif" width=1> <table cellSpacing=0 cellPadding=0 width=443 border=0 sizcache="2" sizset="9"> <tbody sizcache="1" sizset="9"> <tr> <td class=docfnt> <p><strong><font face=Arial>Document #:</font></strong><font face=Arial>1807545I27000</font><br><br><strong><font face=Arial>Body:</font></strong><br><font face=宋体>[标题]</font>如何定义和用含写字符?DB2 表名Q?font face=宋体><br></font><br><font face=宋体><br>环境:</font><br><font face=宋体>产品QDB2 UDB</font><br><font face=宋体>q_Q跨q_</font><br><font face=宋体>版本Qv8<br></font><br><font face=宋体><br>问题描述:<br></font><br>?DB2 UDB 中除非另外指定,否则Q所有名U都可包括下列字W:<br><br>·A ?Z。当在大多数名称中用时Q字W?A ?Z 从写形式转换为大写Ş式?br>·0 ?9<br>·@?? ?_Q下划线Q?br>·名称不能以数字或下划U字W开始?br><br>作ؓ<a onclick="javascript:tagshow(event, '%CA%FD%BE%DD%BF%E2');" href="javascript:;" target=_self><u><strong><font color=#0000ff>数据?/font></strong></u></a>对象的表Q其命名同样遵@上述规则Q因此即使用户创时用的名称是小写的QDB2 仍会自动其转化为大写的形式Q如Q?br><br>db2 create table testname (a1 int)<br>DB20000I <a onclick="javascript:tagshow(event, 'SQL');" href="javascript:;" target=_self><u><strong><font color=#0000ff>SQL</font></strong></u></a> 命o成功完成?br><br>db2 list tables<br><br>表/视图    模式 cd 创徏旉<br>------------------------------- --------------- ----- --------------------------<br>:<br>TESTNAME TESTUSER T 2005-09-24-18.15.30.428001<br>:<br><br>如果用户希望创徏的表名含有小写字W时应如何处理呢Q这里简单介l一下其创徏和用的Ҏ?br><br><font face=宋体><br>解答:</font><br><br>如果需要创建含写英文字符?DB2 表名Q应使用双引号将表名括v来,为避免双引号被{义,需在双引号前加上{义字W?font face="Times New Roman">“</font>\<font face="Times New Roman">”</font>。以创徏一个名?TestName 的表ZQ其创徏语句应写为:<br><br>db2 "create table \"TestName\" (col1 int)" -- Windows & Unix 环境?br><br>如果创徏的表名中包含?font face="Times New Roman">“</font>$<font face="Times New Roman">”</font>的特D字W时Q在 Unix 环境下,q需要在q些字符的前面也加一个{义字W,以创建名?Test$Name 的表ZQ创句应为:<br><br>db2 create table \"Test\$Name\" (col1 int)<br><br>而在 Windows 环境下,可直接写为:<br><br>db2 create table \"Test$Name\" (col1 int)<br><br>表创建完成之后,在以后对q些表进行引用的时候,同样需要象在创的语句中那样对表名加转义W进行引用,如:<br><br>Windows 环境下:<br><br>db2 insert into \"Test$Name\" values (1),(2)<br>DB20000I SQL 命o成功完成?br><br>db2 select * from \"Test$Name\"<br><br>COL1<br>-----------<br>1<br>2<br>2 条记录已选择?br><br>Unix 环境下:<br><br>db2 "insert into \"Test\$Name\" values (1),(2)"<br>DB20000I SQL 命o成功完成?br><br>db2 "select * from \"Test\$Name\""<br><br>COL1<br>-----------<br>1<br>2<br>2 条记录已选择?br><br><font face=宋体>当然除D例中所使用?#8220;$”Ҏ字符外,q有一些其它的Ҏ字符Q在今后使用中,应根据情况尝试加上{义符Q以创徏用户需要的表名?/font><br></p> </td> </tr> </tbody> </table> <img src ="http://www.shnenglu.com/prayer/aggbug/122320.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2010-08-05 16:16 <a href="http://www.shnenglu.com/prayer/archive/2010/08/05/122320.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>db2Load API - Load data into a tablehttp://www.shnenglu.com/prayer/archive/2010/07/23/121108.htmlPrayerPrayerFri, 23 Jul 2010 04:26:00 GMThttp://www.shnenglu.com/prayer/archive/2010/07/23/121108.htmlhttp://www.shnenglu.com/prayer/comments/121108.htmlhttp://www.shnenglu.com/prayer/archive/2010/07/23/121108.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/121108.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/121108.html阅读全文

Prayer 2010-07-23 12:26 发表评论
]]>
游标中rollback引v游标关闭 http://www.shnenglu.com/prayer/archive/2010/06/10/117540.htmlPrayerPrayerThu, 10 Jun 2010 02:39:00 GMThttp://www.shnenglu.com/prayer/archive/2010/06/10/117540.htmlhttp://www.shnenglu.com/prayer/comments/117540.htmlhttp://www.shnenglu.com/prayer/archive/2010/06/10/117540.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/117540.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/117540.htmldeclare test_cur cursor with hold for
     select .... from A where ... order by ... with ur;

open test_cur;
while( 1 ){
    fecth test_cur into ......;
    判断SQLCODE

    begin_work();           /* 其实是讄了一个标?*/
    SQL 操作Q修改其他表或者游标所在表?span class=t_tag onclick=tagshow(event) href="tag.php?name=%CA%FD%BE%DD">数据?br>   Ҏl果判断 commit or rollback?nbsp;   /* 此处如果rollback 游标被关?*/
}

异常状态:
如果游标中进行了SQL操作Q根据结果判断ƈrollbackӞ
下一ơfetchӞ会提C?501 没有打开游标。从而报错退出?br>Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-
疑问Q?br>使用前参考的文章Q?a target=_blank>http://searchdatabase.techtarget.com.cn/tips/365/2297365.shtml
之中有说刎ͼ 
10.DB2的游标打开后遇到commit和rollback默认是会关闭的。保持游标打开的方法是在定义游标时加上with hold选项
但是Q我declare 游标时用了with hold选项Qؓ什么还会出现这个问题?



额卖p的

从vlife以前的回复中扑ֈ的答案:
无论是否使用with hold与否Qrollback释放session中的游标。commit只释放不带with hold的游标?
Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-Q-
救命啊。这些程序是从informixULq来的?br>N让我满x件的记录全部d一个结构数l里面,然后再从l构数组里面逐条取出处理么?
量很大的哈。。。。我M。。?/td>


摘自《SQL Reference Volume 2?br>declare Cursor WITH HOLD
   Maintains resources across multiple units of work.

Q?QFor units of work ending with COMMIT:
   Q?Open cursors defined WITH HOLD remain open.
   Q?All locks are released, except locks protecting the current cursor position of open WITH HOLD cursors.
   。。?br>
Q?QFor units of work ending with ROLLBACK:
   QAll open cursors are closed.
   QAll locks acquired during the unit of work

q种Ҏ是否可行

游标改用普通游标?br>游标取出当前记录后,fork子进E?br>主进E只从游标取数?br>子进E进行事务、处理、判断、修改状态、提交等{?br>主进E等子进E的l束信号Q然后取下一条记录?br>E序D:
declare test_cur cursor with hold for
     select .... from A where ... order by ... with ur;

open test_cur;
while( 1 ){
    fecth test_cur into ......;
    判断SQLCODE

    pid = fork();

    if( pid == 0 ) {    /* 子进E干z?*/
            sqledtin( &sqlca );
            setsid();
            signal( SIGHUP, SIG_IGN );

            db_disconn( G_mdb_name );
            begin_work();           /* 其实是讄了一个标?*/
            SQL 操作Q修改其他表或者游标所在表的数据?br>        Ҏl果判断 commit or rollback?nbsp;  
        db_disconn();
            exit();
    }

    /* 主进E等待子q程l束 */
}
close test_cur;


如果是两个不同的事务的话Q你用CLI来写比较方便

用savepoint

在cursor内部讄一个savepoint, rollback时用
rollback to savepoint a;


Prayer 2010-06-10 10:39 发表评论
]]>
IBM DB2 内存分配与用策?/title><link>http://www.shnenglu.com/prayer/archive/2010/05/19/115854.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Wed, 19 May 2010 15:23:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2010/05/19/115854.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/115854.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2010/05/19/115854.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/115854.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/115854.html</trackback:ping><description><![CDATA[     摘要: 【彭建军】IBM DB2 内存分配与用策?Q上Q出处:Ҏ ChinaUnix 的相x章整理?nbsp;               【导诅R本文将向您讲解 DB2 内存使用的基Q以及共享内存和U有?..  <a href='http://www.shnenglu.com/prayer/archive/2010/05/19/115854.html'>阅读全文</a><img src ="http://www.shnenglu.com/prayer/aggbug/115854.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2010-05-19 23:23 <a href="http://www.shnenglu.com/prayer/archive/2010/05/19/115854.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sheapthres Q?排序堆阈?配置参数 http://www.shnenglu.com/prayer/archive/2010/05/19/115852.htmlPrayerPrayerWed, 19 May 2010 15:21:00 GMThttp://www.shnenglu.com/prayer/archive/2010/05/19/115852.htmlhttp://www.shnenglu.com/prayer/comments/115852.htmlhttp://www.shnenglu.com/prayer/archive/2010/05/19/115852.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/115852.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/115852.htmlsheapthres Q?排序堆阈?配置参数
配置cd
数据库管理器
适用?
  • h本地和远E客h的数据库服务?
  • h本地客户机的数据库服务器
  • h本地和远E客h的分区数据库服务?
参数cd
可配|?
~省?[范围]
UNIX 32 位^?
20 000 [ 250 -- 2 097 152 ]
Windows q_
10 000 [ 250 -- 2 097 152 ]
64 位^?
20 000 [ 250 -- 2 147 483 647 ]
计量单位
(4 KBQ?

专用排序和共享排序用两个不同内存资源中的内存?strong>׃n排序内存区的大小是根?sheapthres 的?/strong>Q?strong>在第一ơ与数据库连接时静态地预先定的?/strong>专用排序内存区的大小不受限制?

sheapthres 参数对于专用和共享的排序用法是不同的Q?

  • 对于专用排序Q此参数是在一个实例内对Q何给定时间专用排序可占用的d存量??限制。当一个实例的M用排序内存占用达C此限制时Qؓ附加入站的专用排序请求分配的内存显著减?
  • 对于׃n排序Q此参数是在一个数据库内对Ml定旉׃n排序占用的d存量的硬限制。当辑ֈ此限制时Q将不允许其它共享排序内存请求(直到d享排序内存的占用降低?sheapthres 指定的限制以下ؓ止)。(在某些情况下Q配|共享排序最大值的另一U方法是使用 sheapthres_shr 数据库配|参数。)

使用排序堆的操作的示例包括:排序、散列连接、动态位图(用于索引 AND q算和星型连接)和表位于内存中的操作?

昑ּ定义阈值可防止数据库管理器对大量排序用过量内存?

当从非分区数据库U至分区数据库环境时Q不应增大此参数的倹{一旦在单个数据库分区环境中调整了数据库和数据库理器配|参敎ͼ在大多数情况下,相同的值在分区数据库环境将同样合适?

作ؓ数据库管理器配置参数?#8220;排序堆阈?#8221;参数应用于整?DB2 实例。将该参数设|ؓ不同节点或分Z的不同值的唯一Ҏ是创建多?DB2 实例。这需要通过不同数据库分区组理不同?DB2 数据库。这样安排将无法发挥分区数据库环境的许多优点?

Q?理想情况下,应将此参数设|ؓ您在数据库管理器实例中拥有的最?sortheap 参数的一个合理倍数。此参数 臛_ 应是该实例中ZQ何数据库定义的最?sortheap 的两倍?/strong>

如果您正执行专用排序q且您的pȝ不受内存U束Q则可用下列步骤来计算此参数的理想|

  1. 计算每个数据库的典型排序堆的使用Q?
    Q对该数据库q行的ƈ发代理程序的典型数目Q?
        * QsortheapQؓ该数据库定义的) 
  2. 对以上结果求和,该值提供可在实例中所有数据库的典型环境中使用的L序堆?

应用基准程序技术来调整此参C扑ֈ在排序性能和内存用之间的相应q?

可以使用数据库系l监视器q借助后阈值排序( post_threshold_sorts Q监视元素来跟踪排序zd?br>

sortheap Q?排序堆大?配置参数

配置cd
数据?
参数cd
可联机配|?
传播c?
语句边界
~省?[范围]
32 位^?
256 [ 16 - 524 288 ] 2 2
64 位^?2
256 [ 16 - 4 194 303 ] 2
计量单位
(4 KBQ?
分配?
需要执行排序时
释放?
当排序完成时

此参数定义要用于专用排序的专用内存页的最大数目或要用于共享排序的׃n内存늚最大数目。如果排序ؓ专用排序Q则此参数将影响代理E序专用内存。如果排序ؓ׃n排序Q则此参数将影响数据库共享内存。每个排序都有一个独立的排序堆,该排序堆是由数据库管理器按照需要分配的。此排序堆是数据排序的区域。如果由优化器定向,则将使用优化器提供的信息分配一个比此参数指定的排序堆小的排序堆?

Q?当用排序堆Ӟ应该考虑下列事项Q?

  • 适当的烦引可使排序堆的用减x程度?
  • 散列q接~冲区和动态位图(用于索引 AND 计算和星型连接)使用排序堆内存。在使用q些技术时Q增大此参数的大?
  • 当需要进行频J的大型排序Ӟ增大此参数的大小?
  • 当增大此参数的值时Q应该检查是否还需要调整数据库理器配|文件中?sheapthres 参数?
  • 排序堆大由优化器在定存取路径时用。在更改此参数后Q应考虑重新l定应用E序Q?REBIND 命oQ?


 Which of the following settings would allow 20 sorts with a maximum of 10MB each to run currently on a 64-bit instance?
A. Set the DB SHEAPTHERS to 50000 and DB SORTHEAP to 2500
B. Set the DBM SHEAPTHERES to 50000 and DB SORTHEAP to 2500
 C. Set the DBM SHEAPTHERS to 50000 and DBM SORTHEAP to 2500
D. Set the DBM SHEAPTHERS_SHR to 50000 and DBM SHEAPTHRES to 2500



Prayer 2010-05-19 23:21 发表评论
]]>
使用DB2配置向导配置参数http://www.shnenglu.com/prayer/archive/2010/05/19/115851.htmlPrayerPrayerWed, 19 May 2010 15:02:00 GMThttp://www.shnenglu.com/prayer/archive/2010/05/19/115851.htmlhttp://www.shnenglu.com/prayer/comments/115851.htmlhttp://www.shnenglu.com/prayer/archive/2010/05/19/115851.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/115851.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/115851.html  DB2版本8提供了一个自动配|参数的工具-配置向导。你可以在控制中心中启动囑Ş界面的配|向|或者用autoconfigure命o来配|你的数据库。配|向导可以配|数据库理器、数据库配置参数和缓冲池大小。注意,你必连接到数据库才能用数据库配置向导Q而且在分区数据库的情况下Q数据库配置向导只配|你q接的一个分区。在分区数据库环境下Q你可以使用db2_all 命o来配|所有数据库分区的参数?/p>

  如果你用图形界面的配置向导Q你需要回{一pd问题Q这些问题相当于AUTOCONFIGURE命o中的参数(如表1所C?。首先让我们看一AUTOCONFIGURE的命令格?

  >>-AUTOCONFIGURE--+---------------------------------------+----->
  | .----------------------------. |
  | V | |
  '-USING----input-keyword--param-value-+-'
  >--APPLY--+-DB ONLY----+---------------------------------------><
  +-DB AND DBM-+
  '-NONE-------'

  ?1昄了选项关键字和取D围?/p>

  ?1 关键字和取D?/p>

  关键?/p>

  
 取D?nbsp; 默认?解释
mem_percent  1-100  80  讑֮DB2使用内存的多。如果还有其他应用程序用,请选择于100的数?/p>

  
 
workload_type  simple, mixed,

  
 complex mixed  指定工作负荷cdQsimpleQ简单)cd主要指IO讉K比较集中Q对于大多数OLTPpȝQ选择simplecd。Complexcd主要是对CPU占用较多的复杂查询系l,如OLAPpȝ。如果你的系l介于两者之_选择mixedcd?
num_stmts

  
 1-1 000 000  10  pȝ中每一个事务包含的SQL语句?
tpm  1-200 000  60  每分钟进行的交易数?/p>

  
 
admin_priority

  
 performance, recovery, both both  选择你的理{略Q可以是更好的性能Q或者是更快的数据库恢复旉?
is_populated

  
 yes, no  yes  数据库已l存在数?
num_local_apps

  
 0-5 000  0  本地q接?
num_remote_apps  0-5 000  10

  
 q程q接?
isolation  RR, RS, CS, UR  RR

  
 应用E序的隔ȝ?
bp_resizeable

  
 yes, no yes  ~冲池是否可调整大小


  APPLY DB ONLY

  在当前数据库理器的配置参数下,昄推荐的数据库和缓冲池的参敎ͼq应用与数据库和~冲池?/p>

  APPLY DB AND DBM

  昄q应用推荐的数据库管理器参数、数据库参数和缓冲池参数?/p>

  APPLY NONE

  仅仅昄推荐|但不更改配置参数?/p>

  使用该命令配|数据库Q关键要选择合适的参数(参见?选择你的参数选项)。下面我们通过一个例子来说明如何使用AUTOCONFIGURE命o配置数据库。假设我们在一个分区的数据库环境中Q只有一个数据库实例db2inst1和数据仓库TESTDWQƈ且已l装载了数据?我们使用下面的命令对该数据库调整参数:

  db2_all “db2 connect to testdw; db2 autoconfigure using mem_percent 80 workload_type complex num_stmts 10 tpm 20 admin_priority both num_local_apps 5 num_remote_apps 50 isolation cs apply db and dbm; db2 connect reset;”

  你也可以创徏一个脚本autoconfigure.db2Q存攑֜DB2 实例的共享目录下Q假设ؓ/home/db2inst1, 内容如下:

  connect to testdw;

  autoconfigure using mem_percent 80 workload_type complex num_stmts 10 tpm 20 admin_priority both num_local_apps 5 num_remote_apps 50 isolation cs apply db and dbm;

  connect reset;

  然后使用db2_all命o在所有的数据库分Z执行q条命oQ我们假设改脚本的存攄录ؓ/home/db2inst1/autoconfigure.db2:

  db2_all “”db2 -tvf /home/db2inst1/autoconfigure.db2 >>autoconfigure##.log”

  执行完毕后,你可以通过autoconfigure*.log来察看该命o在每一个数据库分区上的执行情况。然后重新启动DB2实例Q让q些参数生效。运行一些基准测试的查询语句Q测试DB2 配置向导的配|结果?/p>

  你也可以使用配置向导囑Ş界面来配|你的数据库。你可以通过在控制中心中选中你的数据库,然后点右键,选择“配置向导”来启动配|向对{如果你需要用图形界面配|分区数据库Q记得要结果保存ؓdQƈ配|结果导出到一个脚本文件中Q如/home/db2inst1/autoconfigure.db2。这样你可以用db2_all命o来执行该脚本配置所有的数据库分Z:

  db2_all “”db2 -tvf /home/db2inst1/autoconfigure.db2 >>autoconfigure##.log”

  如果你对DB2非常熟悉Q你可以对DB2自动配置产生的配|文件做适当的修攏VMQDB2配置向导是一个非常简单易用的工具Q能够大大减DBA的工作量?/p>


原文来自Q雨枫技术教E网 http://www.fengfly.com
原文|址Q?a >http://www.fengfly.com/plus/view-30426-1.html

 



Prayer 2010-05-19 23:02 发表评论
]]>
db2batch工具的?/title><link>http://www.shnenglu.com/prayer/archive/2010/05/19/115850.html</link><dc:creator>Prayer</dc:creator><author>Prayer</author><pubDate>Wed, 19 May 2010 14:56:00 GMT</pubDate><guid>http://www.shnenglu.com/prayer/archive/2010/05/19/115850.html</guid><wfw:comment>http://www.shnenglu.com/prayer/comments/115850.html</wfw:comment><comments>http://www.shnenglu.com/prayer/archive/2010/05/19/115850.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/prayer/comments/commentRss/115850.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/prayer/services/trackbacks/115850.html</trackback:ping><description><![CDATA[<p>  基准试是从各种不同斚w(例如数据库响应时间、cpu ?a class=fllink target=_bank><u><font color=#0000ff>内存</font></u></a>使用情况)对应用程序进行评的一个过E。基准测试基于一个可重复的环境,以便能够在相同的条g下运行相同的试。之后,Ҏ试收集到的结果可以进行评估和比较?/p> <p>  db2batch 是一U基准测试工P它以一l?SQL ??XQuery 语句作ؓ输入Q动态地准备语句和描q语句,q返回一个结果集。取决于 db2batch 命o中所使用的选项Q结果集可以q回q些语句的执行时间、关于内存用情?例如~冲?的数据库理器快照和~存信息?/p> <p>  可以在一?flat 文g或标准输入中指定要运行基准测试的语句。在输入文g中可以设|很多控刉项。指定这些选项的语法是Q?-#SET control_option value 。下面是包含控制选项的一个输入文件的例子。要获得控制选项的完整列表,请参?Information Center?/p> <p> <table style="BORDER-TOP-STYLE: dotted; BORDER-RIGHT-STYLE: dotted; BORDER-LEFT-STYLE: dotted; BORDER-BOTTOM-STYLE: dotted" borderColor=#e6941a cellSpacing=0 cellPadding=0 width="90%" align=center bgColor=#ffffff border=1 heihgt=""> <tbody> <tr> <td> <pre class=section>-- db2batch.sql -- ------------ --#SET PERF_DETAIL 3 --#SET ROWS_OUT 5 -- This query lists employees, the name of their department -- and the number of activities to which they are assigned for -- employees who are assigned to more than one activity less than -- full-time. --#COMMENT Query 1 select lastname, firstnme, deptname, count(*) as num_act from employee, department, emp_act where employee.workdept = department.deptno and employee.empno = emp_act.empno and emp_act.emptime < 1 group by lastname, firstnme, deptname having count(*) > 2; --#SET PERF_DETAIL 1 --#SET ROWS_OUT 5 --#COMMENT Query 2 select lastname, firstnme, deptname, count(*) as num_act from employee, department, emp_act where employee.workdept = department.deptno and employee.empno = emp_act.empno and emp_act.emptime < 1 group by lastname, firstnme, deptname having count(*) <= 2; </pre> </td> </tr> </tbody> </table> </p> <ul> <li>  选项 PERF_DETAIL 3 意味着返回关于花费的旉和数据库理器、数据库及应用程序的快照q些性能斚w的细节? <li>  选项 ROWS_OUT 5 意味着无论查询q回的实际行数是多少Q只从结果集中取 5 行? <li>  COMMENT Query1 语句命名ؓ Query1?/li> </ul> <p>  下面的命令在 SAMPLE 数据库上调用基准试工具Q输入文件ؓ db2batch.sql?/p> <p>  db2batch -d sample -f db2batch.sql</p> <p>  q个命o返回查询的l果??5 ?和查询所p的时间及 CPU 旉。另外还q回数据库管理器、数据库和应用程序快照。由于输出很大,因此q里只显C?db2batch 命o的概要?/p> <p> <table style="BORDER-TOP-STYLE: dotted; BORDER-RIGHT-STYLE: dotted; BORDER-LEFT-STYLE: dotted; BORDER-BOTTOM-STYLE: dotted" borderColor=#e6941a cellSpacing=0 cellPadding=0 width="90%" align=center bgColor=#ffffff border=1 heihgt=""> <tbody> <tr> <td>* Summary Table:<br><br>Type      Number      Repetitions Total Time (s) Min Time (s)   ...<br>--------- ----------- ----------- -------------- -------------- <br>Statement           1           1       0.052655       0.052655 ...<br>Statement           2           1       0.004518       0.004518 ...<br><br><br>...Max Time (s)   Arithmetic Mean Geometric Mean Row(s) Fetched Row(s) Output <br>   -------------- --------------- -------------- -------------- ------------- <br>...      0.052655        0.052655       0.052655              5             5 <br>...      0.004518        0.004518       0.004518              8             5 <br><br>                                              <br>* Total Entries:              2               <br>* Total Time:                 0.057173 seconds<br>* Minimum Time:               0.004518 seconds<br>* Maximum Time:               0.052655 seconds<br>* Arithmetic Mean Time:       0.028587 seconds<br>* Geometric Mean Time:        0.015424 seconds </td> </tr> </tbody> </table> </p> <p>  db2batch 命o支持很多选项。这里只列出其中一些选项Q让您对q个工具的威力有所了解?/p> <ul> <li>  -m parameter_file 用参数值指定用于绑定到 SQL 语句参数占位W的一个输入文件? <li>  -r result_file 指定存放命ol果的输出文件? <li>  -i short|long|complete 指定从哪个方面测量所p的时间。short 量q行每条语句所p的时间。long 量q行每条语句所p的时_包括语句之间的开销。complete 量q行每条语句所p的时_分别报告准备、执行和取数据的旉? <li>  -iso 指定语句使用的隔ȝ别。默认情况下Qdb2batch 使用 Repeatable Read 隔离U别?/li> </ul> <img src ="http://www.shnenglu.com/prayer/aggbug/115850.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/prayer/" target="_blank">Prayer</a> 2010-05-19 22:56 <a href="http://www.shnenglu.com/prayer/archive/2010/05/19/115850.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>信息U束http://www.shnenglu.com/prayer/archive/2010/05/18/115739.htmlPrayerPrayerTue, 18 May 2010 15:16:00 GMThttp://www.shnenglu.com/prayer/archive/2010/05/18/115739.htmlhttp://www.shnenglu.com/prayer/comments/115739.htmlhttp://www.shnenglu.com/prayer/archive/2010/05/18/115739.html#Feedback0http://www.shnenglu.com/prayer/comments/commentRss/115739.htmlhttp://www.shnenglu.com/prayer/services/trackbacks/115739.html如果一个应用程序在记录插入到 DB2 中之前已验证了信息,那么使用信息U束 要比普通约束更有效?strong>信息U束告诉 DB2 数据应采取的格式Q而不是在插入或更新处理过E中强制实施。但q一信息可被 DB2 优化器利用,q提?SQL 查询的性能?/strong>考虑以下 CREATE TABLE 语句Q?/p>

CREATE TABLE EMPDATA
(
EMPNO INT NOT NULL,
SEX CHAR(1) NOT NULL
CONSTRAINT SEXOK
CHECK (SEX IN ('M','F'))
NOT ENFORCED
ENABLE QUERY OPTIMIZATION,
SALARY INT NOT NULL,
CONSTRAINT SALARYOK
CHECK (SALARY BETWEEN 0 AND 100000)
NOT ENFORCED
ENABLE QUERY OPTIMIZATION
)

本例包含两个更改列约束行为的语句。第一个选项?NOT ENFORCEDQ它 DB2 在插入或更新数据时不强制查本列。第二个选项?ENABLE QUERY OPTIMIZATIONQDB2 在对该表q行 SELECT 语句时用它。指定该值时QDB2 在优化 SQL 时用约束中的信息?/p>

NOT ENFORCED 选项

若表包含 NOT ENFORCED 选项QINSERT 语句的行为可能会变得很古怪。对 EMPDATA 表运行以?SQL 语句Ӟ不会产生M错误Q?/p>

INSERT INTO EMPDATA VALUES
(1, 'M', 54200),
(2, 'F', 28000),
(3, 'M', 21240),
(4, 'F', 89222),
(5, 'Q', 34444),
(6, 'K',132333)

~号?5 的员工的性别昄有问题(QQ,~号 6 的员工不但性别有问题,同时工资也超Z SALARY 列的限制。在q两U情况下QDB2 依然允许插入Q因为约束是 NOT ENFORCED。这指出了信息约束的一个薄׃处。您必须定所插入或蝲入的数据W合?DB2 中放|的定义?/p>

ENABLE QUERY OPTIMIZATION 选项

在上一屏运行的插入之后Q如果再?EMPDATA 表执?SELECT 语句Q其l果很可能会令您更加qhQ?/p>

SELECT * FROM EMPDATA
WHERE SEX = 'Q';

EMPNO SEX SALARY
----------- --- -----------

0 record(s) selected.

DB2 向查询返回了错误的答案。表中发C “Q” |但该列上的约束告?DB2 有效g包括 “M” ?“F”。ENABLE QUERY OPTIMIZATION 关键字还允许 DB2 在优?SQL 语句时用这一U束信息。若qƈ非您所希望的行为,那么您就需要?ALTER 命o来更改约束:

ALTER TABLE EMPDATA
ALTER CHECK SEXOK DISABLE QUERY OPTIMIZATION

现在Q再重新执行之前的查询。结果如下所C:

SELECT * FROM EMPDATA
WHERE SEX = 'Q';

EMPNO SEX SALARY
----------- --- -----------
5 Q 34444

1 record(s) selected.



Prayer 2010-05-18 23:16 发表评论
]]>
޾þþþþ77777| ˬݾþþۺ鶹| þó鱬Ļ| þþAVҰ | ĻþþƷ| 99þó18վ| þþþþþAv| ɫۺϾþĻ| re99þþƷ99| þҹ³˿Ƭ| 99þùۺ| Ʒһþþ | 99þۺϾƷ| žžþ99ۺһ| 󽶾þĻ| ھƷþþþù| þù㽶Ƶ| ھƷ˾þþӰԺ| þĻƷһ| ˾Ʒþ| Ʒþþþþø69| ձþþþþĻ| ݺɫ˾þþƷۺ| Ļav鲻þ| ˾ƷۺϾþþþ| Ʒ9999þþþ| þùҹƵ| һƷ˾þ| ޾Ʒþþþþ| þþþһ| ŷպ˾Ʒþþѿ| þѾDzݲƷ| ˾Ʒ׽þ69| ھƷþþþþþþ | þҹɫƷ| ƷɫۺϾþ| þ996ȾƷxxxx| Ļɫ͵͵þ | þþƷƷ | ھƷ˾þþþ| ޹ƷAVþۺӰԺ|