Oracle Collecting Statstics

本文详细介绍了如何使用Oracle数据库的DBMS_STATS包来管理并分析表、索引和列的统计信息,包括如何获取统计信息、更新统计信息、指定采样百分比、收集特定列的直方图统计信息、并行收集统计信息等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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.

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';

Statistics exists after index is built.

select
  table_name,
  column_name,
  density,
  num_nulls,
  num_distinct,
  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';

SELECT column_name, endpoint_number, endpoint_value, endpoint_actual_value 
FROM   USER_TAB_HISTOGRAMS
WHERE  TABLE_NAME = 'xxx'
AND column_name='yyy';

Gather statistics of table and its indexes


exec dbms_stats.gather_table_stats(user, 'TT', cascade=>true);


Specifying sample percentage

exec dbms_stats.gather_table_stats(user, 'TT1',estimate_percent=>33, cascade=>true);


Gather statistics on partitioned table


exec dbms_stats.gather_table_stats(user, 'TT', granularity=>'ALL',cascade=>true);

Gather histogram statistics

SELECT dbms_stats.get_param('METHOD_OPT') opt FROM DUAL;

OPT
------------------------------
FOR ALL COLUMNS SIZE AUTO

This shows the default setting of  how histogram statstics is collected.

"SIZE AUTO": Oracle determines the columns to collect histograms based on data distribution and the workload of the columns.

User can specify the bucket size of histogram.

exec dbms_stats.gather_table_stats(user, 'TT', method_opt=>'FOR ALL COLUMNS SIZE 16',cascade=>true);  --Histogram bucket size 16
exec dbms_stats.gather_table_stats(user, 'EMP', method_opt=>'FOR COLUMNS DEPTNO SIZE 240',cascade=>true);
exec dbms_stats.gather_table_stats(user, 'EMP', estimate_percent=>33,method_opt=>'FOR COLUMNS DEPTNO SIZE 254',granularity=>'ALL',cascade=>true); 

Gather statistics in parallel

exec dbms_stats.gather_table_stats(user, 'TT', cascade=>true, degree=>2);


Delete statiscs

exec dbms_stats.delete_table_stats(user, 'TT');

This procedure deletes the statistics of paritions,indexes, columns.
s is a fascinating hobby for many people, particularly those interested in studying insects and their behavior. However, it's crucial to follow ethical and legal guidelines, and to ensure that bugs are collected and handled humanely. Here are some tips for collecting bugs: 1. Check local regulations: Before you start collecting bugs, check your local regulations to make sure it is legal to do so. Some areas may have restrictions on collecting certain species or collecting bugs in protected areas. 2. Use ethical and humane methods: It's important to use ethical and humane methods when collecting bugs. Avoid using harmful chemicals, and instead use gentle methods such as nets or traps. Handle the bugs carefully and avoid injuring them. 3. Respect the environment: When collecting bugs, make sure to respect the environment and the other creatures that live there. Avoid damaging plants or other habitats, and leave the area as you found it. 4. Keep accurate records: Keep accurate records of the species you collect, when and where you collected them, and any other relevant information. This can be helpful for scientific research and for tracking changes in insect populations over time. 5. Release the bugs: After you have collected and observed the bugs, release them back into their natural habitat. Make sure to do so in a safe and appropriate location, and handle them carefully to avoid injury. Remember that collecting bugs can be a fun and educational hobby, but it's important to do so responsibly and ethically. By following these guidelines, you can enjoy the hobby while also helping to protect these fascinating creatures and their habitats.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值