Tom 的 Expert one on one 的一个Bug

| 4 Comments

Tom 的 Expert one on one: Oracle 的一个Bug. 第三章讲到DML所的时候 Tom 用了一个脚本:

tkyte@TKYTE816> select username,
  2         v$lock.sid,
  3         trunc(id1/power(2,16)) rbs,
  4         bitand(id1,to_number('ffff','xxxx'))+0 slot,
  5         id2 seq,
  6         lmode,
  7         request
  8  from v$lock, v$session
  9  where v$lock.type = 'TX'
 10    and v$lock.sid = v$session.sid
 11    and v$session.username = USER
 12  /
    
USERNAME        SID        RBS       SLOT        SEQ      LMODE    REQUEST
-------- ---------- ---------- ---------- ---------- ---------- ----------
TKYTE             8          2         46        160          6          0

产品库上最好别直接用这个脚本,很慢很慢的.

解决的办法是加上一个Hint:

SELECT /*+ rule */ username, v$lock.SID, TRUNC (id1 / POWER (2, 16)) rbs,
       BITAND (id1, TO_NUMBER ('ffff', 'xxxx')) + 0 slot, id2 seq, lmode,
       request
  FROM v$lock, v$session
 WHERE v$lock.TYPE = 'TX'
   AND v$lock.SID = v$session.SID
   AND v$session.username = USER
/

4 Comments

需要看optimzer_mode参数的设置了:)

考虑不周就是Bug了阿

fenng这次有点过于严以律人了。

tom的例子是帮助我们理解技术的,不是给dba做管理脚本用的。

另外像这种join多个v$表的情况,在不同版本的数据库上可能有不同的性能表现。像你那样加上hint,可能在其它版本中未必好。

总不能让他在书中写这段脚本的时候这样写吧?- 在8.1.x下用select /*+ hint1 */....., 在9.0.x下...., 在9.2.x下.....
:)


btw: tom好像不提倡在产品应用中使用hint。

总体上讲,这个SQL没有用途,所以我跳过去了...

关于本文

This page contains a single entry by Fenng published on April 23, 2005 1:16 AM.

ORA-02248 was the previous entry in this blog.

V$Session_LONGOPS is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.