阅读eygle的文章与落落书籍优化核心思想的记录。
从Oracle9i开始,为了监控column的使用信息,引入了一个对象col_usage,用于记录运行时的COLUMN使用信息。
这部分信息由SMON维护。
col_usage的表结构信息:
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)
/
不得不感慨oracle的管理的精细化。
这个信息在oracle使用auto方式收集直方图统计信息时会被调用,因为auto方式是基于列是否在where过滤条件中或表连接列中是否出现过来判断是否要收集此列的直方图。
SELECT /*+ RULE */
c.NAME col_name,
c.type# col_type,
c.CHARSETFORM col_csf,
c.default$ col_def,
c.null$ col_null,
c.property col_prop,
c.col# col_unum,
c.intcol# col_inum,
c.obj# col_obj,
c.scale col_scale,
h.bucket_cnt h_bcnt,
h.distcnt h_pndv,
c.LENGTH col_len,
cu.TIMESTAMP cu_time,
cu.equality_preds cu_ep,
cu.equijoin_preds cu_ejp,
cu.range_preds cu_rp,
cu.like_preds cu_lp
FROM SYS.user$ u,
SYS.obj$ o,
SYS.col$ c,
SYS.col_usage$ cu,
SYS.hist_head$ h
WHERE u.NAME = :b1
AND o.owner# = u.user#
AND o.type# = 2
AND o.NAME = :b2
AND o.obj# = c.obj#
AND c.obj# = cu.obj#(+)
AND c.intcol# = cu.intcol#(+)
AND c.obj# = h.obj#(+)
AND c.intcol# = h.intcol#(+);
sql优化DBA也可以通过列使用信息来抓取哪些列上需要创建索引
select r.name owner,
o.name table_name,
c.name column_name,
u.equality_preds, --等值过滤
u.equijoin_preds, --等值join
u.nonequijoin_preds,–不等join
u.range_preds,–范围过滤
u.like_preds,–like (not like) 过滤
u.null_preds,–null 过滤
u.timestamp --该列最后使用时间
from sys.col_usage$ u,sys.obj$ o,sys.col$ c,sys.user$ r
where o.obj#=u.obj#
and c.obj# = u.obj#
and c.col# =u.intcol#
and o.owner#=r.user#
and r.name=:b1
and o.name=:b2;
:b1 为schema name
:b2 为table_name