ExaGridDba

index with 0 rows rendered unusable

May 21st, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. [oracle@stormking cdb12102 partition]$ sqlplus /nolog @ conn.u.sql
  2.  
  3. SQL*Plus: Release 12.1.0.2.0 Production on Sat May 21 12:40:34 2016
  4.  
  5. Copyright (c) 1982, 2014, Oracle. All rights reserved.
  6.  
  7. Connected.
  8. SQL> @ demo.not.unusable.sql
  9. SQL> set linesize 200
  10. SQL> set trimspool on
  11. SQL> column table_name format a30
  12. SQL> column index_name format a30
  13. SQL> column partition_name format a30
  14. SQL> set echo on
  15.  
  16. SQL> create table sherlock
  17. 2 (
  18. 3 season number not null,
  19. 4 episode number not null,
  20. 5 release date not null,
  21. 6 title varchar2(40) not null,
  22. 7 moriarty varchar2(40) null,
  23. 8 ireneadler varchar2(40) null
  24. 9 )
  25. 10 partition by range ( release )
  26. 11 (
  27. 12 partition p201008 values less than ( to_date( '201009','yyyymm' ) ),
  28. 13 partition p201009 values less than ( to_date( '201010','yyyymm' ) )
  29. 14 );
  30.  
  31. Table created.
  32.  
  33. SQL> create index sherlock_pk on sherlock ( season, episode, release ) local;
  34.  
  35. Index created.
  36.  
  37. SQL> alter table sherlock add constraint sherlock_pk primary key ( season, episode, release );
  38.  
  39. Table altered.
  40.  
  41. SQL> create index ireneadler_local_idx on sherlock ( ireneadler ) local;
  42.  
  43. Index created.
  44.  
  45. SQL> create index moriarty_global_idx on sherlock ( moriarty );
  46.  
  47. Index created.
  48.  
  49. SQL> insert into sherlock ( season, episode, release, title, moriarty, ireneadler )
  50. 2 values ( 1, 1, to_date('20100710', 'yyyymmdd' ), 'A Study in Pink', null, null );
  51.  
  52. 1 row created.
  53.  
  54. SQL> insert into sherlock ( season, episode, release, title, moriarty, ireneadler )
  55. 2 values ( 1, 2, to_date('20100810', 'yyyymmdd' ), 'The Blind Banker', null, null );
  56.  
  57. 1 row created.
  58.  
  59. SQL> commit;
  60.  
  61. Commit complete.
  62.  
  63. SQL> begin
  64. 2 dbms_stats.gather_table_stats(
  65. 3 null,
  66. 4 'SHERLOCK'
  67. 5 );
  68. 6 end;
  69. 7 /
  70.  
  71. PL/SQL procedure successfully completed.
  72.  
  73. SQL> @ global.index.status.sql
  74. SQL> select i.table_name, i.index_name, i.num_rows, i.status
  75. 2 from user_indexes i
  76. 3 where i.table_name = 'SHERLOCK'
  77. 4 and status != 'N/A'
  78. 5 order by i.index_name;
  79.  
  80. TABLE_NAME INDEX_NAME NUM_ROWS STATUS
  81. ------------------------------ ------------------------------ ---------- --------
  82. SHERLOCK MORIARTY_GLOBAL_IDX 0 VALID
  83.  
  84. SQL> @ local.index.status.sql
  85. SQL> select i.table_name, ip.index_name, ip.partition_name, ip.num_rows, ip.status
  86. 2 from user_ind_partitions ip
  87. 3 join user_indexes i on ip.index_name = i.index_name
  88. 4 where i.table_name = 'SHERLOCK'
  89. 5 order by ip.index_name, ip.partition_position;
  90.  
  91. TABLE_NAME INDEX_NAME PARTITION_NAME NUM_ROWS STATUS
  92. ------------------------------ ------------------------------ ------------------------------ ---------- --------
  93. SHERLOCK IRENEADLER_LOCAL_IDX P201008 0 USABLE
  94. SHERLOCK IRENEADLER_LOCAL_IDX P201009 0 USABLE
  95. SHERLOCK SHERLOCK_PK P201008 2 USABLE
  96. SHERLOCK SHERLOCK_PK P201009 0 USABLE
  97.  
  98. SQL> alter table sherlock split partition p201008
  99. 2 at ( to_date( '201008','yyyymm' ) )
  100. 3 into ( partition p201007, partition p201008 )
  101. 4 ;
  102.  
  103. Table altered.
  104.  
  105. SQL> @ global.index.status.sql
  106. SQL> select i.table_name, i.index_name, i.num_rows, i.status
  107. 2 from user_indexes i
  108. 3 where i.table_name = 'SHERLOCK'
  109. 4 and status != 'N/A'
  110. 5 order by i.index_name;
  111.  
  112. TABLE_NAME INDEX_NAME NUM_ROWS STATUS
  113. ------------------------------ ------------------------------ ---------- --------
  114. SHERLOCK MORIARTY_GLOBAL_IDX 0 UNUSABLE
  115.  
  116. SQL> @ local.index.status.sql
  117. SQL> select i.table_name, ip.index_name, ip.partition_name, ip.num_rows, ip.status
  118. 2 from user_ind_partitions ip
  119. 3 join user_indexes i on ip.index_name = i.index_name
  120. 4 where i.table_name = 'SHERLOCK'
  121. 5 order by ip.index_name, ip.partition_position;
  122.  
  123. TABLE_NAME INDEX_NAME PARTITION_NAME NUM_ROWS STATUS
  124. ------------------------------ ------------------------------ ------------------------------ ---------- --------
  125. SHERLOCK IRENEADLER_LOCAL_IDX P201007 UNUSABLE
  126. SHERLOCK IRENEADLER_LOCAL_IDX P201008 UNUSABLE
  127. SHERLOCK IRENEADLER_LOCAL_IDX P201009 0 USABLE
  128. SHERLOCK SHERLOCK_PK P201007 UNUSABLE
  129. SHERLOCK SHERLOCK_PK P201008 UNUSABLE
  130. SHERLOCK SHERLOCK_PK P201009 0 USABLE
  131.  
  132. 6 rows selected.
  133.  
  134. SQL> alter index moriarty_global_idx rebuild;
  135.  
  136. Index altered.
  137.  
  138. SQL> alter table sherlock drop partition p201008;
  139.  
  140. Table altered.
  141.  
  142. SQL> @ global.index.status.sql
  143. SQL> select i.table_name, i.index_name, i.num_rows, i.status
  144. 2 from user_indexes i
  145. 3 where i.table_name = 'SHERLOCK'
  146. 4 and status != 'N/A'
  147. 5 order by i.index_name;
  148.  
  149. TABLE_NAME INDEX_NAME NUM_ROWS STATUS
  150. ------------------------------ ------------------------------ ---------- --------
  151. SHERLOCK MORIARTY_GLOBAL_IDX 0 UNUSABLE
Add Comment
Please, Sign In to add comment