上班之余抽点时间出来写写博文,希望对新接触的朋友有帮助。今天在这里和大家一起学习一下统计、案例-
㈠ 先看两个来自产生境环的实在案例:
㈡ 道理:
Oracle 在对于 varchar等字符型字段集收统计信息时,其实不会对每一个值都停止确精的统计 而是,对值停止substr(,32)。一般来讲,种这方法没有什么问题 但是,如果恰巧列中存储的据数,前32bytes同相,那么,Oracle 的统计就会与实际情况不符
㈢ 测试:
hr@ORCL> drop table t purge;Table dropped.hr@ORCL> create table t (id number,name varchar2(300));Table created.hr@ORCL> create index idx_t on t (name);Index created.hr@ORCL> insert into t select rownum,lpad('a',6,'a')||to_char(rownum) from dba_objects;50322 rows created.hr@ORCL> commit;Commit complete.hr@ORCL> exec dbms_stats.gather_table_stats(user,'T',null,null,method_opt=>'for columns size 254 name',cascade=>true);PL/SQL procedure successfully completed.hr@ORCL> select column_name, endpoint_actual_value 2 from user_tab_histograms 3 where table_name = 'T' 4 and rownum<5 5 order by column_name, endpoint_Number;COLUM ENDPOINT_ACTUAL_VALUE----- --------------------------------------------------NAME aaaaaa46556NAME aaaaaa46734NAME aaaaaa46912NAME aaaaaa47090hr@ORCL> truncate table t;Table truncated.hr@ORCL> insert into t select rownum,lpad('a',31,'a')||to_char(rownum) from dba_objects;50322 rows created.hr@ORCL> exec dbms_stats.gather_table_stats(user,'T',null,null,method_opt=>'for columns size 254 name',cascade=>true);PL/SQL procedure successfully completed.hr@ORCL> select column_name, endpoint_actual_value 2 from user_tab_histograms 3 where table_name = 'T' 4 and rownum<5 5 order by column_name, endpoint_Number;COLUM ENDPOINT_ACTUAL_VALUE----- --------------------------------------------------NAME aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1NAME aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2NAME aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3NAME aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4hr@ORCL> truncate table t;Table truncated.hr@ORCL> insert into t select rownum,lpad('a',32,'a')||to_char(rownum) from dba_objects;50322 rows created.hr@ORCL> exec dbms_stats.gather_table_stats(user,'T',null,null,method_opt=>'for columns size 254 name',cascade=>true);PL/SQL procedure successfully completed.hr@ORCL> select column_name, endpoint_actual_value 2 from user_tab_histograms 3 where table_name = 'T' 4 and rownum<5 5 order by column_name, endpoint_Number;COLUM ENDPOINT_ACTUAL_VALUE----- --------------------------------------------------IDIDNAME
㈣ 解决方案:
删除引索列的直方图 例子:
SQL> begindbms_stats.gather_table_stats(ownname => 'HR', tabname => 'T' , estimate_percent => null , method_opt => 'for columns SIZE 1 name' , cascade => true);end;/
文章结束给大家分享下程序员的一些笑话语录: 很多所谓的牛人也不过如此,离开了你,微软还是微软,Google还是Google,苹果还是苹果,暴雪还是暴雪,而这些牛人离开了公司,自己什么都不是。