SET LINESIZE 666
set pagesize 5000
column index_name format a30
column table_name format a26
column num_rows format 999999999
column index_type format a24
column num_rows format 999999999
column status format a8
column clustering_factor format 999999999
column degree format a10
column blevel format 9
column distinct_keys format 9999999999
column leaf_blocks format 9999999
column last_analyzed format a10
column column_name format a25
column column_position format 9
column temporary format a2
column partitioned format a5
column partitioning_type format a7
column partition_count format 999
--.查看索引情况
--1. 每张表对应有多少个索引,物理多大
select t2.table_name,t1.segment_name,sum(t1.bytes)/1024/1024
from user_segments t1,user_indexes t2
where t1.segment_name=t2.index_name
and t1.segment_type like '%INDEX%'
and t2.table_name in ('T1',
'T2')
group by t2.table_name,t1.segment_name
order by table_name;
--2. 结构情况(索引类型、高度、重复度、并行度、叶子高度、聚合因子、记录数、状态、最近分析时间。。。)
/*
通过index_type可以方便的得知索引类型,普通索引(NORMAL)?位图索引(BITMAP)?函数索引(FUNCTION-BASED NORMAL)?反向键索引NORMAL/REV?
通过status字段可知是否是分区索引(N/A)
通过status字段可知普通索引是否失效(VALID/UNUSABLE)
通过degree字段可得是否有被设置为并行度的属性(值大于1)
通过观察last_analyzed字段值可知是否有正常收集,看有无值,或者是看时间是否很久以前的。
*/
select t.table_name,
t.index_name,
t.num_rows,
t.index_type,
t.status,
t.clustering_factor,
t.blevel,
t.distinct_keys,
t.leaf_blocks,
t.uniqueness,
t.degree,
t.last_analyzed
from user_indexes t
where table_name in ('T1','T2');
--3. 查看索引列信息(在表的哪一列有索引,或者是在哪几个列有联合索引,普通表和分区表都一样)
select t.table_name,t.index_name, t.column_name, t.column_position, t.DESCEND
from user_ind_columns t
where table_name in ('T1',
'T2')
order by table_name,index_name, column_position;
--4. 分区索引总的信息(不会展示各分区上的各分区索引信息,总的描述了分区索引的类型及分区总数)
select table_name,index_name, partitioning_type, partition_count
from user_part_indexes
where table_name in ('T1',
'T2')
order by table_name,index_name;
----分区索引详细信息(每个分区的索引都展示,详细说明了各分区索引的状态、表空间位置、收集状态情况....)
select index_name,
partition_name,
status,
num_rows,
blevel,
leaf_blocks,
last_analyzed,
tablespace_name
from user_ind_partitions
where index_name in
(select index_name
from user_indexes
where table_name in ('T1', 'T2'));