Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [oracle@stormking cdb12102 partition]$ sqlplus /nolog @ conn.u.sql
- SQL*Plus: Release 12.1.0.2.0 Production on Sat May 21 12:40:34 2016
- Copyright (c) 1982, 2014, Oracle. All rights reserved.
- Connected.
- SQL> @ demo.not.unusable.sql
- SQL> set linesize 200
- SQL> set trimspool on
- SQL> column table_name format a30
- SQL> column index_name format a30
- SQL> column partition_name format a30
- SQL> set echo on
- SQL> create table sherlock
- 2 (
- 3 season number not null,
- 4 episode number not null,
- 5 release date not null,
- 6 title varchar2(40) not null,
- 7 moriarty varchar2(40) null,
- 8 ireneadler varchar2(40) null
- 9 )
- 10 partition by range ( release )
- 11 (
- 12 partition p201008 values less than ( to_date( '201009','yyyymm' ) ),
- 13 partition p201009 values less than ( to_date( '201010','yyyymm' ) )
- 14 );
- Table created.
- SQL> create index sherlock_pk on sherlock ( season, episode, release ) local;
- Index created.
- SQL> alter table sherlock add constraint sherlock_pk primary key ( season, episode, release );
- Table altered.
- SQL> create index ireneadler_local_idx on sherlock ( ireneadler ) local;
- Index created.
- SQL> create index moriarty_global_idx on sherlock ( moriarty );
- Index created.
- SQL> insert into sherlock ( season, episode, release, title, moriarty, ireneadler )
- 2 values ( 1, 1, to_date('20100710', 'yyyymmdd' ), 'A Study in Pink', null, null );
- 1 row created.
- SQL> insert into sherlock ( season, episode, release, title, moriarty, ireneadler )
- 2 values ( 1, 2, to_date('20100810', 'yyyymmdd' ), 'The Blind Banker', null, null );
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL> begin
- 2 dbms_stats.gather_table_stats(
- 3 null,
- 4 'SHERLOCK'
- 5 );
- 6 end;
- 7 /
- PL/SQL procedure successfully completed.
- SQL> @ global.index.status.sql
- SQL> select i.table_name, i.index_name, i.num_rows, i.status
- 2 from user_indexes i
- 3 where i.table_name = 'SHERLOCK'
- 4 and status != 'N/A'
- 5 order by i.index_name;
- TABLE_NAME INDEX_NAME NUM_ROWS STATUS
- ------------------------------ ------------------------------ ---------- --------
- SHERLOCK MORIARTY_GLOBAL_IDX 0 VALID
- SQL> @ local.index.status.sql
- SQL> select i.table_name, ip.index_name, ip.partition_name, ip.num_rows, ip.status
- 2 from user_ind_partitions ip
- 3 join user_indexes i on ip.index_name = i.index_name
- 4 where i.table_name = 'SHERLOCK'
- 5 order by ip.index_name, ip.partition_position;
- TABLE_NAME INDEX_NAME PARTITION_NAME NUM_ROWS STATUS
- ------------------------------ ------------------------------ ------------------------------ ---------- --------
- SHERLOCK IRENEADLER_LOCAL_IDX P201008 0 USABLE
- SHERLOCK IRENEADLER_LOCAL_IDX P201009 0 USABLE
- SHERLOCK SHERLOCK_PK P201008 2 USABLE
- SHERLOCK SHERLOCK_PK P201009 0 USABLE
- SQL> alter table sherlock split partition p201008
- 2 at ( to_date( '201008','yyyymm' ) )
- 3 into ( partition p201007, partition p201008 )
- 4 ;
- Table altered.
- SQL> @ global.index.status.sql
- SQL> select i.table_name, i.index_name, i.num_rows, i.status
- 2 from user_indexes i
- 3 where i.table_name = 'SHERLOCK'
- 4 and status != 'N/A'
- 5 order by i.index_name;
- TABLE_NAME INDEX_NAME NUM_ROWS STATUS
- ------------------------------ ------------------------------ ---------- --------
- SHERLOCK MORIARTY_GLOBAL_IDX 0 UNUSABLE
- SQL> @ local.index.status.sql
- SQL> select i.table_name, ip.index_name, ip.partition_name, ip.num_rows, ip.status
- 2 from user_ind_partitions ip
- 3 join user_indexes i on ip.index_name = i.index_name
- 4 where i.table_name = 'SHERLOCK'
- 5 order by ip.index_name, ip.partition_position;
- TABLE_NAME INDEX_NAME PARTITION_NAME NUM_ROWS STATUS
- ------------------------------ ------------------------------ ------------------------------ ---------- --------
- SHERLOCK IRENEADLER_LOCAL_IDX P201007 UNUSABLE
- SHERLOCK IRENEADLER_LOCAL_IDX P201008 UNUSABLE
- SHERLOCK IRENEADLER_LOCAL_IDX P201009 0 USABLE
- SHERLOCK SHERLOCK_PK P201007 UNUSABLE
- SHERLOCK SHERLOCK_PK P201008 UNUSABLE
- SHERLOCK SHERLOCK_PK P201009 0 USABLE
- 6 rows selected.
- SQL> alter index moriarty_global_idx rebuild;
- Index altered.
- SQL> alter table sherlock drop partition p201008;
- Table altered.
- SQL> @ global.index.status.sql
- SQL> select i.table_name, i.index_name, i.num_rows, i.status
- 2 from user_indexes i
- 3 where i.table_name = 'SHERLOCK'
- 4 and status != 'N/A'
- 5 order by i.index_name;
- TABLE_NAME INDEX_NAME NUM_ROWS STATUS
- ------------------------------ ------------------------------ ---------- --------
- SHERLOCK MORIARTY_GLOBAL_IDX 0 UNUSABLE
Add Comment
Please, Sign In to add comment