Partial Indexes for Partitioned Tables in Oracle Database 12c Release 1
Oracle 12c allows the creation of global and local indexes on a subset of the partitions of a partitioned table.
oracle 12cconfigurationintermediate
by OracleDba
13 views
Oracle 12c allows the creation of global and local indexes on a subset of the partitions of a partitioned table.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
-- Create and populate the partitioned table.
drop table t1 purge;
create table t1 (
id number,
description varchar2(50),
created_date date
)
partition by range (created_date) (
partition part_2014 values less than (date '2015-01-01'),
partition part_2015 values less than (date '2016-01-01') indexing on,
partition part_2016 values less than (date '2017-01-01') indexing off
);
insert into t1 values (1, 't1 one', date '2014-07-01');
insert into t1 values (2, 't1 two', date '2015-07-01');
insert into t1 values (3, 't1 three', date '2016-07-01');
commit;
column table_name format a20
column partition_name format a20
select table_name,
partition_name,
indexing
from user_tab_partitions
where table_name = 'T1'
order by 1,2;
TABLE_NAME PARTITION_NAME INDE
-------------------- -------------------- ----
T1 PART_2014 ON
T1 PART_2015 ON
T1 PART_2016 OFF
SQL>
alter table t1 modify partition part_2014 indexing off;
alter table t1 modify partition part_2015 indexing off;
alter table t1 modify partition part_2016 indexing on;
select table_name,
partition_name,
indexing
from user_tab_partitions
where table_name = 'T1'
order by 1,2;
TABLE_NAME PARTITION_NAME INDE
-------------------- -------------------- ----
T1 PART_2014 OFF
T1 PART_2015 OFF
T1 PART_2016 ON
SQL>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
drop index t1_local_partial_idx;
-- create index t1_local_partial_idx on t1(created_date) local indexing full;
create index t1_local_partial_idx on t1(created_date) local;
column index_name format a25
select index_name,
partition_name,
status
from user_ind_partitions
where index_name = 'T1_LOCAL_PARTIAL_IDX'
order by 1,2;
INDEX_NAME PARTITION_NAME STATUS
------------------------- -------------------- --------
T1_LOCAL_PARTIAL_IDX PART_2014 USABLE
T1_LOCAL_PARTIAL_IDX PART_2015 USABLE
T1_LOCAL_PARTIAL_IDX PART_2016 USABLE
SQL>
column indexing format a8
select index_name,
indexing
from user_indexes
where index_name = 'T1_LOCAL_PARTIAL_IDX'
order by 1;
INDEX_NAME INDEXING
------------------------- --------
T1_LOCAL_PARTIAL_IDX FULL
SQL>
drop index t1_local_partial_idx;
create index t1_local_partial_idx on t1(created_date) local indexing partial;
select index_name,
partition_name,
status
from user_ind_partitions
where index_name = 'T1_LOCAL_PARTIAL_IDX'
order by 1,2;
INDEX_NAME PARTITION_NAME STATUS
------------------------- -------------------- --------
T1_LOCAL_PARTIAL_IDX PART_2014 UNUSABLE
T1_LOCAL_PARTIAL_IDX PART_2015 UNUSABLE
T1_LOCAL_PARTIAL_IDX PART_2016 USABLE
SQL>
column indexing format a8
select index_name,
indexing
from user_indexes
where index_name = 'T1_LOCAL_PARTIAL_IDX'
order by 1;
INDEX_NAME INDEXING
------------------------- --------
T1_LOCAL_PARTIAL_IDX PARTIAL
SQL>
create index t1_global_partial_idx on t1(description) global indexing partial;
-- Check the indexing status of the indexes.
select index_name,
indexing
from user_indexes
where index_name like 'T1%'
order by 1;
INDEX_NAME INDEXING
------------------------- --------
T1_GLOBAL_PARTIAL_IDX PARTIAL
T1_LOCAL_PARTIAL_IDX PARTIAL
SQL>Please to add comments
No comments yet. Be the first to comment!