dbms_stats和analyze 评估AVG_ROW_LEN
随着Oracle版本的不断更新,我们推荐使用dbms_stats来代替analyze获得对象的统计信息。本文主要讨论dbms_stats和analyze对AVG_ROW_LEN取值的异同
创建测试表格
引用
SQL> create table testt1 as select * from dba_objects;
SQL> insert into testt1 select * from testt1;
SQL> commit;
SQL> insert into testt1 select * from testt1;
SQL> commit;
SQL> select count(*) from testt1;
181860
用dbms_stats收集表格信息,可以发现AVG_ROW_LEN*NUM_ROWS小于表格实际物理大小
引用
SQL> exec dbms_stats.gather_table_stats('ZHOU','TESTT1');
SQL> select AVG_ROW_LEN,NUM_ROWS from dba_tables where table_name='TESTT1';
94 181860
SQL> select bytes from dba_segments where segment_name='TESTT1';
20971520
SQL> select 94*181860 from dual;
17094840
用analyze命令收集表格信息,我们发现AVG_ROW_LEN*NUM_ROWS比dbms_stats更接近于实际物理大小,
不过这差别并不会对CBO构成致命影响引用
SQL> analyze table TESTT1 compute statistics;
SQL> select AVG_ROW_LEN,NUM_ROWS from dba_tables where table_name='TESTT1';
97 181860
SQL> select 97*181860 from dual;
17640420