SQL> set linesize 200
SQL> select a.column_name,
b.num_rows,
a.num_distinct Cardinality,
round(a.num_distinct / b.num_rows * 100, 2) selectivity,
a.histogram,
a.num_buckets
from dba_tab_col_statistics a, dba_tables b
where a.owner = b.owner
and a.table_name = b.table_name
and a.owner = 'MBFE'
and a.table_name = upper('messagein'); 2 3 4 5 6 7 8 9 10 11
COLUMN_NAME NUM_ROWS CARDINALITY SELECTIVITY HISTOGRAM NUM_BUCKETS
------------------------------ ---------- ----------- ----------- --------------- -----------
ID 978619 978619 100 NONE 1
MSGID 978619 978619 100 FREQUENCY 2
STATUS 978619 1 0 NONE 1
PROCCNT 978619 2 0 NONE 1
ACCEPTTIME 978619 653888 66.82 NONE 1
MSGBODY 978619 0 0 NONE 0
QUEUE 978619 4 0 NONE 1
7 rows selected.
SQL> BEGIN
DBMS_STATS.GATHER_TABLE_STATS(ownname => 'MBFE',
tabname => 'MESSAGEIN',
estimate_percent => 100,
method_opt => 'for columns MSGID size 1',
no_invalidate => FALSE,
degree => 16,
cascade => TRUE);
END; 2 3 4 5 6 7 8 9
10 /
PL/SQL procedure successfully completed.
SQL> select a.column_name,
b.num_rows,
a.num_distinct Cardinality,
round(a.num_distinct / b.num_rows * 100, 2) selectivity,
a.histogram,
a.num_buckets
from dba_tab_col_statistics a, dba_tables b
where a.owner = b.owner
and a.table_name = b.table_name
and a.owner = 'MBFE'
and a.table_name = upper('messagein'); 2 3 4 5 6 7 8 9 10 11
COLUMN_NAME NUM_ROWS CARDINALITY SELECTIVITY HISTOGRAM NUM_BUCKETS
------------------------------ ---------- ----------- ----------- --------------- -----------
ID 978619 978619 100 NONE 1
MSGID 978619 978619 100 NONE 1
STATUS 978619 1 0 NONE 1
PROCCNT 978619 2 0 NONE 1
ACCEPTTIME 978619 653888 66.82 NONE 1
MSGBODY 978619 0 0 NONE 0
QUEUE 978619 4 0 NONE 1
7 rows selected.
此时直方图已经被干掉
SQL> BEGIN
DBMS_STATS.GATHER_TABLE_STATS(ownname => 'MBFE',
tabname => 'MESSAGEIN',
estimate_percent => 100,
method_opt => 'for columns MSGID size repeat',
no_invalidate => FALSE,
degree => 16,
cascade => TRUE);
END; 2 3 4 5 6 7 8 9
10 /
PL/SQL procedure successfully completed.
SQL> ^C^C
SQL>
SQL> select a.column_name,
b.num_rows,
a.num_distinct Cardinality,
round(a.num_distinct / b.num_rows * 100, 2) selectivity,
a.histogram,
a.num_buckets
from dba_tab_col_statistics a, dba_tables b
where a.owner = b.owner
and a.table_name = b.table_name
and a.owner = 'MBFE'
and a.table_name = upper('messagein'); 2 3 4 5 6 7 8 9 10 11
COLUMN_NAME NUM_ROWS CARDINALITY SELECTIVITY HISTOGRAM NUM_BUCKETS
------------------------------ ---------- ----------- ----------- --------------- -----------
ID 978619 978619 100 NONE 1
MSGID 978619 978619 100 NONE 1
STATUS 978619 1 0 NONE 1
PROCCNT 978619 2 0 NONE 1
ACCEPTTIME 978619 653888 66.82 NONE 1
MSGBODY 978619 0 0 NONE 0
QUEUE 978619 4 0 NONE 1
7 rows selected.
SQL>
用repert 方式收集:
repeat表示以前收集过直方图,现在收集统计信息的时候就收集直方图,如果以前没收集过直方图,现在收集统计信息的时候就不收集。
此时无效果
SQL> BEGIN
DBMS_STATS.GATHER_TABLE_STATS(ownname => 'MBFE',
tabname => 'MESSAGEIN',
estimate_percent => 100,
method_opt => 'for columns MSGID size skewonly',
no_invalidate => FALSE,
degree => 16,
cascade => TRUE);
END; 2 3 4 5 6 7 8 9
10 /
PL/SQL procedure successfully completed.
SQL> select a.column_name,
b.num_rows,
a.num_distinct Cardinality,
round(a.num_distinct / b.num_rows * 100, 2) selectivity,
a.histogram,
a.num_buckets
from dba_tab_col_statistics a, dba_tables b
where a.owner = b.owner
and a.table_name = b.table_name
and a.owner = 'MBFE'
and a.table_name = upper('messagein');
2 3 4 5 6 7 8 9 10 11
COLUMN_NAME NUM_ROWS CARDINALITY SELECTIVITY HISTOGRAM NUM_BUCKETS
------------------------------ ---------- ----------- ----------- --------------- -----------
ID 978619 978619 100 NONE 1
MSGID 978619 978619 100 FREQUENCY 2
STATUS 978619 1 0 NONE 1
PROCCNT 978619 2 0 NONE 1
ACCEPTTIME 978619 653888 66.82 NONE 1
MSGBODY 978619 0 0 NONE 0
QUEUE 978619 4 0 NONE 1
7 rows selected.
此时已搜集:
skewonly 对所有的列搜集统计信息