Oracle Collecting Statstics
Procedure signature:
DBMS_STATS.GATHER_TABLE_STATS (
ownname VARCHAR2, --Owner/schema name
tabname VARCHAR2, --Table Name
partname VARCHAR2 DEFAULT NULL,
estimate_percent NUMBER DEFAULT to_estimate_percent_type
block_sample BOOLEAN DEFAULT FALSE,
method_opt VARCHAR2 DEFAULT get_param('METHOD_OPT'),
degree NUMBER DEFAULT to_degree_type(get_param('DEGREE')),
granularity VARCHAR2 DEFAULT GET_PARAM('GRANULARITY'),
cascade BOOLEAN DEFAULT to_cascade_type(get_param('CASCADE')),
stattab VARCHAR2 DEFAULT NULL,
statid VARCHAR2 DEFAULT NULL,
statown VARCHAR2 DEFAULT NULL,
no_invalidate BOOLEAN DEFAULT to_no_invalidate_type (
get_param('NO_INVALIDATE')),
stattype VARCHAR2 DEFAULT 'DATA',
force BOOLEAN DEFAULT FALSE);
Oracle database version:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production"
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
1. View table, index and column statistics.
select table_name,
num_rows,
blocks,
empty_blocks,
avg_space,
chain_cnt,
avg_row_len,
degree,
sample_size,
to_char(last_analyzed,'yyyy/mm/dd hh24:mi:ss') last_analyzed
from user_tables where table_name='TT';
Query user_tab_partitions for partition statistics, user_tab_subpartitions for subpartitions.
After table creation, there's no statistics at the table level. Oracle uses dynamic sampling to calculate the statistics.
select index_name,
table_name,
blevel,
leaf_blocks,
distinct_keys,
avg_leaf_blocks_per_key,
avg_data_blocks_per_key
cluster_factor,
status,
num_rows,
sample_size,
to_char(last_analyzed,'yyyy/mm/dd hh24:mi:ss') last_analyzed,
degree
from user_indexes
where table_name='TT';
Statistics exists after index is built.
select
table_name,
column_name,
density,
num_nulls,
num_buckets,
to_char(last_analyzed,'yyyy/mm/dd hh24:mi:ss') last_analyzed,
sample_size,
avg_col_len,
histogram
from user_tab_col_statistics
where table_name='TT';
No column statistics
2. Gather statistics of table and its indexes
SQL> exec dbms_stats.gather_table_stats(user, 'TT', cascade=>true);
PL/SQL procedure successfully completed.
Elapsed: 00:00:02.36
3. Gather statistics on partitioned table
exec dbms_stats.gather_table_stats(user, 'TT', granularity=>'ALL',cascade=>true);
4. Gather histogram statistics
SELECT dbms_stats.get_param('METHOD_OPT') opt FROM DUAL;
SQL> SELECT dbms_stats.get_param('METHOD_OPT') opt FROM DUAL;
OPT
------------------------------
FOR ALL COLUMNS SIZE AUTO
Determines how histogram statstics is collected by default."SIZE AUTO": Oracle determines the columns to collect histograms based on data distribution and the workload of the columns.
exec dbms_stats.gather_table_stats(user, 'TT', method_opt=>'FOR ALL COLUMNS SIZE 16',cascade=>true); --Histogram bucket size 16
5. Gather statistics in parallel
SQL> exec dbms_stats.gather_table_stats(user, 'TT', cascade=>true, degree=>2);
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.33
6. Delete statiscs
exec dbms_stats.delete_table_stats(user, 'TT');
This procedure by default deletes the statistics of paritions,indexes, columns.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/638844/viewspace-775894/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Collecting Numbers II
- PyCharm debug collecting data...PyCharm
- 「SWTR-4」Collecting Coins 題解
- Disable the automatic funciton of collecting statistics in 10G
- Collecting The Required Information To Troubleshot ASM/ASMLIB Issues_869526.1UIORMASM
- 關於collecting狀態的分散式懸掛事務分散式
- alert 檔案中的資訊:insert pending collecting tran, scn=1009024904 (hex=0.3c247f
- oracle DBLink oracleOracle
- Oracle 中$ORACLE_HOME/bin/oracle檔案Oracle
- oracle 修改ORACLE例項Oracle
- oracle安裝工具目錄常用解釋oracle wallet manager/Oracle Directory Manager /oracle net manager /Oracle Net ManagOracle
- ORACLE基礎之oracle鎖(oracle lock mode)詳解Oracle
- 【Oracle】oracle tablespace&datafile -- oracle表空間 分享[轉]Oracle
- cx_Oracle 連線 OracleOracle
- [Oracle]Oracle良性SQL建議OracleSQL
- oracle之 Oracle LOB 詳解Oracle
- [oracle]centos 7 安裝oracleOracleCentOS
- Oracle工具(Oracle Tools) – SQLT(SQLTXPLAIN)OracleSQLAI
- oracle clone oracle_home 方法Oracle
- oracle 817 archive err,oracle hangOracleHive
- 【Oracle】修改oracle監聽埠Oracle
- 【Oracle】Oracle常用EVENT之三Oracle
- 【Oracle】Oracle常用EVENT之二Oracle
- 【Oracle】Oracle常用EVENT之一Oracle
- Oracle Clusterware and Oracle Grid InfrastructureOracleASTStruct
- 【Oracle】--"任性"Oracle安裝之旅Oracle
- OracleOracle
- Oracle vs PostgreSQL DBA(21)- Oracle VPDOracleSQL
- 【Oracle】Oracle logminer功能介紹Oracle
- Oracle案例12——NBU Oracle恢復Oracle
- [Oracle] -- 配置Oracle環境變數Oracle變數
- 「Oracle」Oracle 資料庫安裝Oracle資料庫
- oracle 12c Deprecation of Oracle StreamsOracle
- Oracle HowTo:How to get Oracle SCN?Oracle
- Oracle Temporary Tables(Oracle 臨時表)Oracle
- ORACLE_BASE 與 ORACLE_HOMEOracle
- Oracle OAF(Oracle Application Framework) SampleOracleAPPFramework
- 20 Differences Between Oracle on NT and Oracle on UnixOracle