|
|
原帖由 zhiliyang 于 6/8/2009 11:57 发表 ![]()
谢谢楼上两位。
在下面这个MM的文章里面也有一个关于index scan的问题,然后有点点说明,但是偶不太确定是否理解正确
(http://www.ibm.com/developerwork ... &S_CMP=cn-a-db2)
...an index-sargable predicate (that is, it cannot be applied as a start/stop key on the index scan).
...
Without an index sarg, an index scan will use the index to access the data, but will return every key in the index.
...
Because the predicate on the main table cannot be applied to the index, we have to read all the rows from the table, using the index, and then apply the predicate before passing the qualifying rows up to the join.
And as before, we have to lock the rows before we can evaluate the predicate.
这个意思是不是如果IXSCAN的时候,没有start/stop key的话,那么db2实际上只是用index去访问表中每一条记录,然后再使用predicate来得到结果集。
而不是在对index使用predicate,用得到的在index上的一个结果集,去访问db,读取对应的数据。
另外,如果是这样的话,那么是不是这个IXSCAN实际上相当于退化成了TABLE SCAN(特别是对于一个tablespace里面只有一个table的情形)
我看了上面文章里的例子。如果你直白地去理解‘Because the predicate on the main table cannot be applied to the index, we have to read all the rows from the table, using the index, and then apply the predicate before passing the qualifying rows up to the join.
And as before, we have to lock the rows before we can evaluate the predicate’,那我认为他这个说明是错的。
因为很显眼plan中只是去scan整个main table的primary index,因为index中已经包括所有需要的数据,所以这是index only scan。肯定不需要读index再读data。所以你说的“退化”并不存在。
另外他这个例子跟你碰到的情况相似,因为都只是用Sargable predict, i.e.
Predicates:
----------
2) Sargable Predicate
Relational Operator: Equal (=)
Subquery Input Required: No
Filter Factor: 0.2
Predicate Text:
--------------
(Q2.MAIN_DATA_COLUMN = 'deadlock 1')
证明DB2需要读取整个INDEX,所以肯定要“经过”你在另一进程中刚刚插入或修改的数据所对应在index中的那个record。由于DB2中的行锁只在ROW或TABLE上,所以锁ROW data也就是mapping到锁住index中对应的那个Record。
文章作者的表述最多只能理解成这种映射锁DATA行和对应index中record的关系。如果说DB2回头还需要读再读一次TABLE中数据,那这种理解肯定是错误的。 |
|