Oracle报告分区索引
从关于索引的数据字典中可以收集到很多信息,它们包括以下内容:
.分区名称
.索引类型
.索引分区的状态(需要查询相应的视图)
.索引分区的大小
在下面的例子中,你只是希望得到employees_part表的索引名,分区名和状态的列表。因为此表上既有分区索引又有非分区索引。所以你用union操作把对两种索引的查询合并在一起。
SQL> select table_name,index_name,partition_name,p.status 2 from user_ind_partitions p join user_indexes i using(index_name) 3 where table_name='EMPLOYEES_PART' 4 union 5 select table_name,index_name,null,status 6 from user_indexes 7 where table_name='EMPLOYEES_PART' 8 order by 2,3; TABLE_NAME INDEX_NAME PARTITION_NAME STATUS ------------------------------ ------------------------------ ---------------------------------------- -------- EMPLOYEES_PART EMPLOYEES_PART_PK VALID EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_100 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_200 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_300 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_400 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_500 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_600 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_700 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_800 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_900 UNUSABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 MANAGER_MAX USABLE EMPLOYEES_PART EMPLOYEES_PART_UK1 N/A EMPLOYEES_PART EMPLOYEE_PART_LI P1990 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1991 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1992 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1993 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1994 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1995 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1996 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1997 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1998 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P1999 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI P2000 USABLE EMPLOYEES_PART EMPLOYEE_PART_LI PMAX USABLE EMPLOYEES_PART EMPLOYEE_PART_LI N/A 25 rows selected.
请注意,在查询user_indexes视图时,分区索引对应的状态(status)列中显示N/A(表示不可用)。只有(基于索引分区的)最精细的数据字典视图的状态列才会被填入数据。也就是说,对于分区索引,user_ind_partitions视图的status列将被填充。如果你查询的最子分区索引,那么只有user_ind_subpartitions视图的status列将被填充,而user_indexes和user_ind_partitions视图的status列将是N/A。
接下来,需要执行一个查询,以确定表上所有索引分区的类型.
SQL> select table_name,index_name,partitioning_type,locality,alignment from user_part_indexes; TABLE_NAME INDEX_NAME PARTITION LOCALI ALIGNMENT ------------------------------ ------------------------------ --------- ------ ------------ EMPLOYEES_JY EMPLOYEES_UK1 RANGE GLOBAL PREFIXED EMPLOYEES_JY EMPLOYEES_JY_IH1 HASH GLOBAL PREFIXED EMPLOYEES_PART EMPLOYEE_PART_LI RANGE LOCAL PREFIXED EMPLOYEES_PART EMPLOYEES_PART_UK1 RANGE GLOBAL PREFIXED
在查询段信息时,需要注意区分子分区索引。对于子分区索引,为了获得子分区的信息,大多数数据字典视图中都有一个子分区列。但这有一个例外,当需要从dba_segments等视图中获得段信息时,只有实际分区或表示实际段的子分区名才会在dba_segments中表示。换句话说,对于子分区索引,子分区名称将在dba_segments的partition_name列中出现。在下面的例子中,想要获得billing_fact表中大小超过8GB的索引子分区。你对user_ind_subpartitions执行了一个子查询,这表明dba_segments视图的partition_name列实际上代表了user_ind_subpartitions视图的subpartition_name列。
select segment_name,partition_name,round(bytes/1048576) meg from dba_segments where (segment_name,partition_name) in (select index_name,subpartition_name from user_ind_subpartitions where index_name in (select index_name from user_indexes where table_name='BILLING_FACT')) and bytes>1048576*8192 order by 3 desc;