Tom 的 Expert one on one 的一个Bug

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

[email protected]6> 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
/