从Oracle9i开始,为了监控column的使用信息,引入了一个对象col_usage$,用于记录运行时的COLUMN使用信息。
这部分信息由SMON维护,所以当看到SMON报出相关的死锁、错误时不要惊讶,SMON做的工作是越来越杂了。
在Oracle10g中,这个表的结构如下:
create table col_usage$
(
obj# number, /* object number */
intcol# number, /* internal column number */
equality_preds number, /* equality predicates */
equijoin_preds number, /* equijoin predicates */
nonequijoin_preds number, /* nonequijoin predicates */
range_preds number, /* range predicates */
like_preds number, /* (not) like predicates */
null_preds number, /* (not) null predicates */
timestamp date /* timestamp of last time this row was changed */
)
storage (initial 200K next 100k maxextents unlimited pctincrease 0)
/
create unique index i_col_usage$ on col_usage$(obj#,intcol#)
storage (maxextents unlimited)
/
注意,这里的每个选项都是有意义的,比如maxextents unlimited就是因为col_usage$表可能过度扩展空间设计的。
今天,在客户一个繁忙的数据库中,看到了关于这个表的操作SQL,执行次数非常频繁,以下是3个SQL:
LOCK TABLE SYS.col_usage$ IN EXCLUSIVE MODE NOWAIT;
UPDATE SYS.col_usage$
SET equality_preds = equality_preds + DECODE (BITAND (:flag, 1), 0, 0, 1),
equijoin_preds = equijoin_preds + DECODE (BITAND (:flag, 2), 0, 0, 1),
nonequijoin_preds =
nonequijoin_preds + DECODE (BITAND (:flag, 4),
0, 0,
1
),
range_preds = range_preds + DECODE (BITAND (:flag, 8), 0, 0, 1),
like_preds = like_preds + DECODE (BITAND (:flag, 16), 0, 0, 1),
null_preds = null_preds + DECODE (BITAND (:flag, 32), 0, 0, 1),
TIMESTAMP = :TIME
WHERE obj# = :objn AND intcol# = :coln;
INSERT INTO SYS.col_usage$
VALUES (:objn, :coln, DECODE (BITAND (:flag, 1), 0, 0, 1),
DECODE (BITAND (:flag, 2), 0, 0, 1),
DECODE (BITAND (:flag, 4), 0, 0, 1),
DECODE (BITAND (:flag, 8), 0, 0, 1),
DECODE (BITAND (:flag, 16), 0, 0, 1),
DECODE (BITAND (:flag, 32), 0, 0, 1), :TIME);
在以下1小时采样的报告中,3条SQL执行了数千次:
Parse CallsExecutions% Total ParsesSQL IdSQL ModuleSQL Text
9864,0750.713c1kubcdjnppq
update sys.col_usage$ set eq...
986690.7153btfq0dt9bs9
insert into sys.col_usage$ val...
9869860.71b2gnxm5z6r51n
lock table sys.col_usage$ in e...
相关的维护SQL还有:
delete from sys.col_usage$ c where not exists (select 1 from sys.obj$ o where o.obj# = c.obj# )
返回栏目页:http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/