楼主: zhiliyang

[精华] 请教两个DB2上的两个隔离/锁相关的问题

[复制链接]
论坛徽章:
0
11#
 楼主| 发表于 2009-8-3 11:05 | 只看该作者
To Diablo2:
我的LUW db2是V9.5的,这个有问题么?

使用道具 举报

回复
论坛徽章:
78
ITPUB15周年纪念
日期:2020-08-28 17:23:53双鱼座
日期:2016-03-19 19:38:31秀才
日期:2016-02-18 09:31:52秀才
日期:2016-01-25 15:02:04双子座
日期:2016-01-19 20:35:54秀才
日期:2016-01-13 12:14:26秀才
日期:2015-12-25 15:31:10秀才
日期:2015-12-18 09:28:57秀才
日期:2015-12-14 14:56:09秀才
日期:2015-12-14 14:51:16
12#
发表于 2009-8-3 19:36 | 只看该作者
9.5有那个问题。9.7才解决。至于主机上面的DB2,估计短期内海不会解决。用脏读。

使用道具 举报

回复
论坛徽章:
0
13#
 楼主| 发表于 2009-8-3 20:56 | 只看该作者
难道说这两个问题都是db2的Bug?
偶不是这么点背吧,一下子连跌两个坑里面。

To wolfop:
有什么地方有这种db2版本升级的时候修正的bug汇总么,想看看。
谢一个先。

使用道具 举报

回复
论坛徽章:
78
ITPUB15周年纪念
日期:2020-08-28 17:23:53双鱼座
日期:2016-03-19 19:38:31秀才
日期:2016-02-18 09:31:52秀才
日期:2016-01-25 15:02:04双子座
日期:2016-01-19 20:35:54秀才
日期:2016-01-13 12:14:26秀才
日期:2015-12-25 15:31:10秀才
日期:2015-12-18 09:28:57秀才
日期:2015-12-14 14:56:09秀才
日期:2015-12-14 14:51:16
14#
发表于 2009-8-3 21:02 | 只看该作者
不是BUG,对于缺省的隔离级别,ANSI并没规定更新锁住记录时,其他事物读操作的行为。因此ORACLE/interbase/firebird等数据库采用了多版本读的方式。这种方式开发程序简单,但是其实数据库要做更多工作。
早期的SQL SERVER/DB2/INFORMIX/SYBASE都不支持这种方式。
现在最新的INFORMIX/DB2采用了双版本读的方式防止这种情况出现,简化了开发,但是数据库肯定开销变大,不过还是好过多版本的方式。
但是主机上面的DB2,估计短期内还没听说会有这个更新。

使用道具 举报

回复
论坛徽章:
18
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-02-13 15:09:522012新春纪念徽章
日期:2012-02-13 15:09:52
15#
发表于 2009-8-4 08:30 | 只看该作者

回复 #1 zhiliyang 的帖子

在你使用or时产生锁等待的时候做个snapshot for locks。
另外把这个or语句的explain也一起贴出来。

使用道具 举报

回复
论坛徽章:
9
2009日食纪念
日期:2009-07-22 09:30:00ITPUB8周年纪念徽章
日期:2009-09-27 10:21:21祖国60周年纪念徽章
日期:2009-10-09 08:28:002010新春纪念徽章
日期:2010-03-01 11:19:10ITPUB9周年纪念徽章
日期:2010-10-08 09:31:22ITPUB十周年纪念徽章
日期:2011-11-01 16:23:262012新春纪念徽章
日期:2012-01-04 11:53:54ITPUB 11周年纪念徽章
日期:2012-10-09 18:08:152013年新春福章
日期:2013-02-25 14:51:24
16#
发表于 2009-8-4 17:56 | 只看该作者
对于问题一,牛博士的书里有很好的解释。
DB2默认会加锁是在apply predicate 之前。
如果你要改变这个行为,请使用注册变量
DB2_EVALUNCOMMITTED

使用道具 举报

回复
论坛徽章:
0
17#
 楼主| 发表于 2009-8-5 09:58 | 只看该作者
兄弟在此先谢一个先。

下面是explain的结果:
DB2 Universal Database Version 9.5, 5622-044 (c) Copyright IBM Corp. 1991, 2007
Licensed Material - Program Property of IBM
IBM DATABASE 2 Explain Table Format Tool



******************** EXPLAIN INSTANCE ********************

DB2_VERSION:                 09.05.0
SOURCE_NAME:                 SQLC2G13
SOURCE_SCHEMA:                 NULLID  
SOURCE_VERSION:         
EXPLAIN_TIME:                 2009-08-04-15.11.51.359000
EXPLAIN_REQUESTER:         YANGLU  

Database Context:
----------------
        Parallelism:                 None
        CPU Speed:                 3.227686e-007
        Comm Speed:                 100
        Buffer Pool size:         1000
        Sort Heap size:         52
        Database Heap size:         600
        Lock List size:         1569
        Maximum Lock List:         97
        Average Applications:         1
        Locks Available:         129364

Package Context:
---------------
        SQL Type:                 Dynamic
        Optimization Level:         5
        Blocking:                 Block All Cursors
        Isolation Level:         Cursor Stability



---------------- STATEMENT 1  SECTION 203 ----------------
        QUERYNO:                 1
        QUERYTAG:                                    
        Statement Type:         Select
        Updatable:                 No
        Deletable:                 No
        Query Degree:                 1

Original Statement:
------------------
select *
from deadtable
where c1=2 or c1 = 3


Optimized Statement:
-------------------
SELECT Q3.C1 AS "C1"
FROM YANGLU.DEADTABLE AS Q3
WHERE Q3.C1 IN (2, 3)

Access Plan:
-----------
        Total Cost:                 0.0160821
        Query Degree:                1

      Rows
     RETURN
     (   1)
      Cost
       I/O
       |
        2
     IXSCAN
     (   2)
    0.0160821
        0
       |
        5
INDEX: YANGLU  
      INDX1




Extended Diagnostic Information:
--------------------------------

No extended Diagnostic Information for this statement.


Plan Details:
-------------


        1) RETURN: (Return Result)
                Cumulative Total Cost:                 0.0160821
                Cumulative CPU Cost:                 49825.5
                Cumulative I/O Cost:                 0
                Cumulative Re-Total Cost:         0.00463641
                Cumulative Re-CPU Cost:         14364.5
                Cumulative Re-I/O Cost:         0
                Cumulative First Row Cost:         0.0139097
                Estimated Bufferpool Buffers:         1

                Arguments:
                ---------
                BLDLEVEL: (Build level)
                        DB2 v9.5.0.808 : s071001
                HEAPUSE : (Maximum Statement Heap Usage)
                        64 Pages
                STMTHEAP: (Statement heap size)
                        2048

                Input Streams:
                -------------
                        2) From Operator #2

                                Estimated number of rows:         2
                                Number of columns:                 1
                                Subquery predicate ID:                 Not Applicable

                                Column Names:
                                ------------
                                +Q4.C1(A)


        2) IXSCAN: (Index Scan)
                Cumulative Total Cost:                 0.0160821
                Cumulative CPU Cost:                 49825.5
                Cumulative I/O Cost:                 0
                Cumulative Re-Total Cost:         0.00463641
                Cumulative Re-CPU Cost:         14364.5
                Cumulative Re-I/O Cost:         0
                Cumulative First Row Cost:         0.0139097
                Estimated Bufferpool Buffers:         1

                Arguments:
                ---------
                MAXPAGES: (Maximum pages for prefetch)
                        ALL
                PREFETCH: (Type of Prefetch)
                        NONE
                ROWLOCK : (Row Lock intent)
                        NEXT KEY SHARE
                SCANDIR : (Scan Direction)
                        FORWARD
                TABLOCK : (Table Lock intent)
                        INTENT SHARE

                Predicates:
                ----------
                3) Sargable Predicate
                        Comparison Operator:                 In List (IN), evaluated by binary search (list sorted at compile-time)
                        Subquery Input Required:         No
                        Filter Factor:                         0.4

                        Predicate Text:
                        --------------
                        Q3.C1 IN (2, 3)



                Input Streams:
                -------------
                        1) From Object YANGLU.INDX1

                                Estimated number of rows:         5
                                Number of columns:                 2
                                Subquery predicate ID:                 Not Applicable

                                Column Names:
                                ------------
                                +Q3.C1(A)+Q3.$RID$


                Output Streams:
                --------------
                        2) To Operator #1

                                Estimated number of rows:         2
                                Number of columns:                 1
                                Subquery predicate ID:                 Not Applicable

                                Column Names:
                                ------------
                                +Q4.C1(A)


Objects Used in Access Plan:
---------------------------

        Schema: YANGLU  
        Name:         DEADTABLE
        Type:         Table (reference only)

        Schema: YANGLU  
        Name:         INDX1
        Type:         Index
                        Time of creation:                 2009-07-31-15.48.02.165002
                        Last statistics update:         2009-08-03-15.22.56.296000
                        Number of columns:                 1
                        Number of rows:                 5
                        Width of rows:                         -1
                        Number of buffer pool pages:         2
                        Distinct row values:                 No
                        Tablespace name:                 RESOURCE         
                        Tablespace overhead:                 7.500000
                        Tablespace transfer rate:         0.060000
                        Source for statistics:                 Single Node
                        Prefetch page count:                 32
                        Container extent page count:         32
                        Index clustering statistic:         100.000000
                        Index leaf pages:                 1
                        Index tree levels:                 1
                        Index full key cardinality:         5
                        Index first key cardinality:         5
                        Index first 2 keys cardinality: -1
                        Index first 3 keys cardinality: -1
                        Index first 4 keys cardinality: -1
                        Index sequential pages:         0
                        Index page density:                 0
                        Index avg sequential pages:         0
                        Index avg gap between sequences:0
                        Index avg random pages:         1
                        Fetch avg sequential pages:         0
                        Fetch avg gap between sequences:0
                        Fetch avg random pages:         1
                        Index RID count:                 6
                        Index deleted RID count:         1
                        Index empty leaf pages:         0
                        Base Table Schema:                 YANGLU  
                        Base Table Name:                 DEADTABLE
                        Columns in index:
                                C1

Base Table For Index Not Already Shown:
---------------------------------------

        Schema: YANGLU  
        Name:         DEADTABLE
                        Time of creation:                 2009-07-31-15.48.01.977001
                        Last statistics update:         2009-08-03-15.22.56.296000
                        Number of data partitions:         1
                        Number of columns:                 1
                        Number of rows:                 5
                        Number of pages:                 2
                        Number of pages with rows:         1
                        Table overflow record count:         0
                        Indexspace name:                 RESOURCE
                        Tablespace name:                 RESOURCE
                        Tablespace overhead:                 7.500000
                        Tablespace transfer rate:         0.060000
                        Prefetch page count:                 -1
                        Container extent page count:         32

                        Long tablespace name:                 RESOURCE


查阅部分资料后觉得可能是红色的那部分的问题。
难道它是不是就是所谓的Residual Predicates?




另外,or怎么就被解释成了In了?  哎,看来偶还是很小白的。
继续查东西去吧

使用道具 举报

回复
论坛徽章:
3
2009日食纪念
日期:2009-07-22 09:30:00祖国60周年纪念徽章
日期:2009-10-09 08:28:002010新春纪念徽章
日期:2010-03-01 11:20:05
18#
发表于 2009-8-5 10:35 | 只看该作者
in查起来比or快。

使用道具 举报

回复
论坛徽章:
78
ITPUB15周年纪念
日期:2020-08-28 17:23:53双鱼座
日期:2016-03-19 19:38:31秀才
日期:2016-02-18 09:31:52秀才
日期:2016-01-25 15:02:04双子座
日期:2016-01-19 20:35:54秀才
日期:2016-01-13 12:14:26秀才
日期:2015-12-25 15:31:10秀才
日期:2015-12-18 09:28:57秀才
日期:2015-12-14 14:56:09秀才
日期:2015-12-14 14:51:16
19#
发表于 2009-8-5 11:41 | 只看该作者
对于第一个问题,没使用索引的很大可能是因为你的记录数太少,或者没有做统计更新。

使用道具 举报

回复
论坛徽章:
0
20#
 楼主| 发表于 2009-8-5 13:14 | 只看该作者
To wolfop:
用了索引的吧,不是IXSCAN么。
不过where c1 =2 or c1 =3 被db2翻译成了 WHERE Q3.C1 IN (2, 3)


不过对于这个explain该怎么理解还是不太明白。从text上看,因该是用的索引去检索,属于index sargable才对。
但是按照IBM的官方网站上对predicate分类的说明上来看,这个因该是属于Residual Predicates:
Residual Predicates

Residual predicates require more I/O costs than accessing a table. They might have the following characteristics:
      Use correlated subqueries
      Use quantified subqueries, which contain ANY, ALL, SOME, or IN clauses
      Read LONG VARCHAR or LOB data, which is stored in a file that is separate from the table

http://publib.boulder.ibm.com/in ... /admin/c0005292.htm





To biti.vector:
Are u sure? 第一次听见这个说法。
而且就从上面的说明看,in也是属于最慢的存取方式啊。

使用道具 举报

回复

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

本版积分规则 发表回复

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