Managing Statistics part2

来源:互联网 发布:液压原理图软件 编辑:程序博客网 时间:2024/06/06 07:23
Segment-Level Statistics
Logical reads
Buffer busy waits
Db block changes
Physical reads
Physical writes
Physical reads direct
Physical writes direct
Global cache cr blocks served
Global cache current blocks served
ITL waits
Row lock waits


Query the Statistics
v$segstat_name:Lists the segment statistics being collected
v$segstat:Displays the statistics value,statistics name,and other basic information这个会把上面的每一项列出来。
v$segment_statistics:Displays the segment owner and tablespace name in addition to all the rows contained in v$segstat


实验二:desc v$segstat_name
col name format a30
select * from v$segstat_name
列出了segment级别的统计信息有哪些。


desc v$segstat
desc dba_objects需要找出object_id
select object_id from dba_objects where owner='HR', and object_name='T';
col statistic_name format a40
select statistic_name,statistic#,value FROM v$segstat where dataobj#=32567;就能看到段的统计信息
开多一个session,读这个表,如 select * from t where  id>1;
再查询一次,会发现逻辑读得数有了改变。


Using Dynamic Sampliing动态取样
OPTIMIZER_DYNAMIC_SAMPLING=0
动态取样被禁止
参数从0-10,默认是2,详情看11g performing turing guide。等级越高,开销越大,10是全表扫描以获得最全最精确的统计信息。这个也可以用HINT在session级别,对个别SQL语句指定。

Histograms:直方图
例如性别这一列,是50%男50%女,还是1%男99%女
Histograms describe the data distribution of a particular column in more detail.
They give better predicate selectivity estimates for unevenly distributed data.
如果数据不是均匀的,可以给出更好的预测。
You create histograms with the
dbms_stats.gather_table_stats procedure.
统计信息所放view:dba_histograms,dba_tab_histograms


Skewed Data 歪斜的数据
一边倒的数据,不均匀分布的数据,例如一列100万行记录,有ABCD四种值,但95%都是A,2%B,1%C,1%D。
如果select * from jobs where job='A';则全表扫描比较好。select * from jobs where jobs='D';则利用索引比较好。
数据分布不同,最优的执行计划是不同的,所以需要直方图这个统计信息。


直方图
宽度平衡Width-balanced Histogram
取值作为横坐标,例如0-10,11-20,21-30,频度作为纵坐标。宽度平衡是横坐标间隔都是10个单位相隔。小学学的就是这种。
高度平衡Height-balanced Histogram(ORACLE)
例如3行3行作为一个桶,与宽度平衡相反。
原创粉丝点击