Bo's Oracle Station

查看: 3234|回复: 6

课程第39/40/41次(2017-08-11星期五和2017-08-13星期天上下午)

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2017-8-11 21:49:17 | 显示全部楼层 |阅读模式
第三阶段New Feature/OCM Exam Preparation31-41
  1. select  * from dba_indexes i
  2. where i.table_owner='SH' and i.table_name='SALES';

  3. select   tp.partition_name ,tp.compression ,
  4.      tp.compress_for  from dba_tab_partitions tp
  5. where tp.table_owner='SH' and tp.table_name='SALES';

  6. select  i.index_name , ip.partition_name , decode(ip.status  , null,i.status, ip.status)
  7. , ip.tablespace_name
  8.   from dba_indexes i , dba_ind_partitions  ip
  9.   where i.index_name=ip.index_name(+)  
  10.   and i.table_name='SALES'   and i.owner='SH'
  11.   order by  1,2;
  12.   
  13. select    c.constraint_name, c.constraint_type,
  14.               c.status,  c.validated, c.deferrable, c.deferred,c.rely            
  15.        from dba_constraints c
  16. where c.owner='SH' and c.table_name <>'SALES';
  17. -------

  18. select   t.compression , t.compress_for  from dba_tables t
  19. where t.owner='SH' and t.table_name='SALES_DELTA';

  20.   
  21.   
复制代码

  1. SQL> conn sh/oracle_4U
  2. Connected.
  3. ALTER TABLE sales SPLIT PARTITION sales_q1_2007
  4.   AT (TO_DATE('01-APR-2007','DD-MON-YYYY'))
  5.   3    INTO (PARTITION sales_q1_2007, PARTITION sales_beyond_q1_2007);

  6. Table altered.

  7. SELECT COUNT(*) FROM sales PARTITION (sales_beyond_q1_2007);007);


  8.   COUNT(*)
  9. ----------
  10.          0

  11. SQL> SQL> ALTER TABLE sales DROP PARTITION sales_beyond_q1_2007 update global indexes ;

  12. Table altered.

  13. SQL> alter table sales add partition sales_q2_2007  values less than ( to_date('2007-07-01','YYYY-MM-DD'))   ;

  14. Table altered.

  15. SQL>  alter table sales drop partition sales_q2_2007   ;

  16. Table altered.

  17. SQL> exit
  18. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
  19. With the Partitioning, Automatic Storage Management, OLAP, Data Mining
  20. and Real Application Testing options
  21. [oracle@station17 ~]$ dwworkshop/lab
  22. lab1/ lab2/ lab3/ lab4/ lab5/ lab6/ lab7/
  23. [oracle@station17 ~]$ dwworkshop/labs2
  24. -bash: dwworkshop/labs2: No such file or directory
  25. [oracle@station17 ~]$ cd dwworkshop/labs2
  26. -bash: cd: dwworkshop/labs2: No such file or directory
  27. [oracle@station17 ~]$ cd dwworkshop/lab2/
  28. [oracle@station17 lab2]$ ls
  29. create_constraints_old.sql          csbs.sql              ldsalesupdate.sql        salesq107.dat
  30. create_constraints.sql              csbsu.sql             load_stage_table2.sql    salesQ1.dat
  31. create_ndx.sql                      csbt.sql              mark_index_unusable.sql  show_sales_idx_status.sql
  32. create_partition_for_sales_etl.sql  csd.sql               modify_constraints.sql   sh_sales.bad
  33. create_static_bitmap_index.sql      fast_split_sales.sql  rebuild_indexes.sql      sh_sales.log_xt
  34. [oracle@station17 lab2]$ vim  create_ndx.sql
  35. [oracle@station17 lab2]$ ls
  36. create_constraints_old.sql          csbs.sql              ldsalesupdate.sql        salesq107.dat
  37. create_constraints.sql              csbsu.sql             load_stage_table2.sql    salesQ1.dat
  38. create_ndx.sql                      csbt.sql              mark_index_unusable.sql  show_sales_idx_status.sql
  39. create_partition_for_sales_etl.sql  csd.sql               modify_constraints.sql   sh_sales.bad
  40. create_static_bitmap_index.sql      fast_split_sales.sql  rebuild_indexes.sql      sh_sales.log_xt
  41. [oracle@station17 lab2]$ cd ..
  42. [oracle@station17 dwworkshop]$ ls
  43. fix  lab1  lab2  lab3  lab4  lab5  lab6  lab7  tuning_Workshop_Labs.pdf
  44. [oracle@station17 dwworkshop]$ cd lab3
  45. [oracle@station17 lab3]$ ls
  46. add_salestemp_pk.sql  create_global_index.sql         lab2.zip                see_split2.sql
  47. cleanup_labs123.sql   exchange_partition_w_gim.sql    prep4_global_index.sql  see_split.sql
  48. cleanup_split_q1.sql  exchange_partition_wo_gim2.sql  run_select.sql          show_sales_idx_status.sql
  49. count_mar_sales.sql   first_split_q1.sql              second_split_q1.sql     use_global_index.sql
  50. [oracle@station17 lab3]$ vim first_split_q1.sql
  51. [oracle@station17 lab3]$ sqlplus /nolog

  52. SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 11 21:29:18 2017

  53. Copyright (c) 1982, 2009, Oracle.  All rights reserved.

  54. SQL> conn sh/oracle_4U
  55. Connected.
  56. SQL> @first_split_q1.sql
  57. We now want to leverage the new functionality and break down the existing
  58. quarter partition into monthly ones

  59. Table altered.

  60. SQL> @second_split_q1.sql
  61.    (PARTITION sales_JAN_2007 TABLESPACE sysaux COMPRESS  for otlp ,
  62.                                                              *
  63. ERROR at line 4:
  64. ORA-14464: Compression Type not specified


  65. SQL> @second_split_q1.sql

  66. Table altered.

  67. ALTER TABLE sales MOVE PARTITION sales_JAN_2007 TABLESPACE example
  68. UPDATE INDEXES (sales_time_bix    (PARTITION sales_jan_2007 TABLESPACE example),
  69.                 sales_cust_bix    (PARTITION sales_jan_2007 TABLESPACE example),
  70.                 sales_channel_bix (PARTITION sales_jan_2007 TABLESPACE example),
  71.                 sales_prod_bix    (PARTITION sales_jan_2007 TABLESPACE example),
  72.   6                  sales_promo_bix   (PARTITION sales_jan_2007 TABLESPACE example));

  73. Table altered.

  74. SQL> /

  75. Table altered.

  76. SQL> ALTER INDEX sales_time_bix
  77.   2    REBUILD PARTITION FEB_07 TABLESPACE example;

  78. Index altered.

  79. CREATE TABLE sales_mar_2007_temp
  80.   NOLOGGING AS SELECT * FROM sales
  81.   3      PARTITION (sales_MAR_2007);

  82. Table created.

  83. SQL> select   count(*) from sales_mar_2007_temp;

  84.   COUNT(*)
  85. ----------
  86.      99326

  87. CREATE BITMAP INDEX sales_prod_mar_2007_bix
  88.                ON sales_mar_2007_temp (prod_id)
  89.                NOLOGGING COMPUTE STATISTICS ;ICS ;

  90. CREATE BITMAP INDEX sales_cust_mar_2007_bix
  91.                ON sales_mar_2007_temp (cust_id)
  92.                NOLOGGING COMPUTE STATISTICS ;

  93. CREATE BITMAP INDEX sales_time_mar_2007_bix
  94.                ON sales_mar_2007_temp (time_id)
  95.                NOLOGGING COMPUTE STATISTICS ;

  96. CREATE BITMAP INDEX sales_channel_mar_2007_bix
  97.                ON sales_mar_2007_temp (channel_id)
  98.                NOLOGGING COMPUTE STATISTICS ;

  99. CREATE BITMAP INDEX sales_promo_mar_2007_bix
  100.                ON sales_mar_2007_temp (promo_id)
  101.                NOLOGGING COMPUTE STATISTICS ;

  102. Index created.

  103. SQL> SQL>   2    3  
  104. Index created.

  105. SQL> SQL>   2    3  
  106. Index created.

  107. SQL> SQL>   2    3  
  108. Index created.

  109. SQL> SQL>   2    3  
  110. Index created.

  111. SQL>
  112. SQL>
复制代码
Screenshot.png


回复

使用道具 举报

2

主题

15

帖子

118

积分

版主

Rank: 7Rank: 7Rank: 7

积分
118
发表于 2017-9-5 17:03:23 | 显示全部楼层
唐老师,在做删除分区表数据(滚窗操作)的时候:
实验前提:
1. 创建普通分区表(没有nocompress参数)
  1. create table sales_old_q1_2003 nologging as select * from sales where 1=0;
复制代码


2.在sales_old_q1_2003 创建与SALES表上相同类型的索引
  1. CREATE BITMAP INDEX salesq1_prod_old_bix
  2.        ON sales_old_q1_2003 (prod_id)
  3.        NOLOGGING COMPUTE STATISTICS ;
  4. CREATE BITMAP INDEX salesq1_cust_old_bix
  5.        ON sales_old_q1_2003 (cust_id)
  6.        NOLOGGING COMPUTE STATISTICS ;
  7. CREATE BITMAP INDEX salesq1_time_old_bix
  8.        ON sales_old_q1_2003 (time_id)
  9.        NOLOGGING COMPUTE STATISTICS ;
  10. CREATE BITMAP INDEX salesq1_channel_old_bix
  11.        ON sales_old_q1_2003 (channel_id)
  12.        NOLOGGING COMPUTE STATISTICS ;
  13. CREATE BITMAP INDEX salesq1_promo_old_bix
  14.        ON sales_old_q1_2003 (promo_id)
  15.        NOLOGGING COMPUTE STATISTICS ;
复制代码
3. 检查SALES表的压缩情况和索引可用情况(检查结果为BASIC压缩和索引状态为USABLE
  1. select PARTITION_NAME,COMPRESSION,COMPRESS_FOR from dba_tab_partitions where TABLE_OWNER='SH' and TABLE_NAME='SALES';
复制代码
  1. select i.index_name , ip.partition_name , decode(ip.status , null,i.status, ip.status)
  2. , ip.tablespace_name
  3. from dba_indexes i , dba_ind_partitions ip
  4. where i.index_name=ip.index_name(+)
  5. and i.table_name='SALES' and i.owner='SH'
  6. order by 1,2;
复制代码
4.交换SALES表中SALES_Q1_2001与sales_old_q1_2003 表

  1. SQL> alter table sales exchange partition sales_q1_2001 with table sales_old_q1_2003 including indexes;
  2. alter table sales exchange partition sales_q1_2001 with table sales_old_q1_2003 including indexes
  3. *
  4. ERROR at line 1:
  5. ORA-14646: Specified alter table operation involving compression
  6. cannot be performed in the presence of usable bitmap indexes
复制代码
此时报错ORA-14646:

5. 删除2步骤中所创建的索引
  1. drop index salesq1_prod_old_bix;
  2. drop index salesq1_cust_old_bix;
  3. drop index salesq1_time_old_bix;
  4. drop index salesq1_channel_old_bix;
  5. drop index salesq1_promo_old_bix;
复制代码
6.再次执行交换分区操作(此时正常不报错)
  1. alter table sales exchange partition sales_q1_2001 with table sales_old_q1_2003
复制代码
7.再次创建2步骤中的索引
  1. CREATE BITMAP INDEX salesq1_prod_old_bix
  2. ON sales_old_q1_2003 (prod_id)
  3. NOLOGGING COMPUTE STATISTICS ;
  4. CREATE BITMAP INDEX salesq1_cust_old_bix
  5. ON sales_old_q1_2003 (cust_id)
  6. NOLOGGING COMPUTE STATISTICS ;
  7. CREATE BITMAP INDEX salesq1_time_old_bix
  8. ON sales_old_q1_2003 (time_id)
  9. NOLOGGING COMPUTE STATISTICS ;
  10. CREATE BITMAP INDEX salesq1_channel_old_bix
  11. ON sales_old_q1_2003 (channel_id)
  12. NOLOGGING COMPUTE STATISTICS ;
  13. CREATE BITMAP INDEX salesq1_promo_old_bix
  14. ON sales_old_q1_2003 (promo_id)
  15. NOLOGGING COMPUTE STATISTICS ;
复制代码
8. rebulid 分区sales_q1_2001上的索引
  1. alter index sales_prod_bix rebuild partition sales_q1_2001;
  2. alter index sales_cust_bix rebuild partition sales_q1_2001;
  3. alter index sales_promo_bix rebuild partition sales_q1_2001;
  4. alter index sales_time_bix rebuild partition sales_q1_2001;
  5. alter index sales_channel_bix rebuild partition sales_q1_2001;
复制代码
9.此时的状态
  1. sales_q1_2001 分区上已经没有数据
  2. sales 上所有的索引正常
  3. sales_old_q1_2003 上有数据
复制代码
10.再次交换分区(多次交换都可以正常)
  1. alter table sales exchange partition sales_q1_2001 with table sales_old_q1_2003 including indexes;
复制代码


问题:在第一次创建sales_old_q1_2003 表和创建了与SALES表相同的索引时,交换分区不成功报错ORA-14646



回复 支持 反对

使用道具 举报

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
 楼主| 发表于 2017-9-6 16:26:55 | 显示全部楼层
xiaoyu 发表于 2017-9-5 17:03
唐老师,在做删除分区表数据(滚窗操作)的时候:
实验前提:
1. 创建普通分区表(没有nocompress参数)
...

上课时,遇到时已经说过不是压缩引起的。是索引和约束引起。
回复 支持 反对

使用道具 举报

2

主题

15

帖子

118

积分

版主

Rank: 7Rank: 7Rank: 7

积分
118
发表于 2017-9-7 11:28:01 | 显示全部楼层
唐老师,我做实验得到的更准确的结论应该是:

如果要在具有位图索引的分区表上使用压缩的时候,则在第一次做分区原子操作时(exchange partition/split partition/add partition等),需要
1.将涉及到的位图索引给unusable(如果是exchange操作,则置换的目标表上的位图索引也需要unusable)
2.执行分区原子操作
3.重建位图索引
4.不断重复分区原子操作都不会报错ORA-14646
参考自 ORA-14646 with using bitmap indexes on partitioned compressed tables (文档 ID 256236.1)

下面我贴下我做的实验过程
回复 支持 反对

使用道具 举报

2

主题

15

帖子

118

积分

版主

Rank: 7Rank: 7Rank: 7

积分
118
发表于 2017-9-7 11:44:22 | 显示全部楼层
实验1:创建压缩分区表,创建bitmap索引,创建不压缩普通表,创建bitmap索引,做滚窗操作

1.创建压缩分区表test
  1. create table test (n number) partition by range (n)
  2. (partition p0 values less than (0) compress
  3. ,partition p1 values less than (1) nocompress)
  4. compress;


  5. SQL> select PARTITION_NAME,COMPRESSION,COMPRESS_FOR from dba_tab_partitions where TABLE_NAME='TEST';

  6. PARTITION_NAME                       COMPRESS COMPRESS_FOR
  7. ------------------------------ -------- ------------
  8. P0                               ENABLED        BASIC
  9. P1                               DISABLED
复制代码


2.对test 建立本地位图索引
  1. create bitmap index bm_test_n on test(n) local;

  2. SQL> select INDEX_NAME,STATUS from dba_indexes where INDEX_NAME='BM_TEST_N';

  3. INDEX_NAME                       STATUS
  4. ------------------------------ --------
  5. BM_TEST_N                       N/A

  6. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BM_TEST_N';

  7. INDEX_NAME                       PARTITION_NAME                      STATUS
  8. ------------------------------ ------------------------------ --------
  9. BM_TEST_N                       P0                              USABLE
  10. BM_TEST_N                       P1                              USABLE
复制代码


3.建立用于置换(exchange partition)的非分区非压缩temp表及索引
  1. create table temp (n number) ;

  2. create bitmap index bm_temp on temp(n) ;

  3. SQL> select INDEX_NAME,STATUS from dba_indexes where INDEX_NAME='BM_TEMP';

  4. INDEX_NAME                       STATUS
  5. ------------------------------ --------
  6. BM_TEMP                        VALID
复制代码


4.对test表添加分区
  1. alter table test add partition p2 values less than (2) ;

  2. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BM_TEST_N';

  3. INDEX_NAME                       PARTITION_NAME                      STATUS
  4. ------------------------------ ------------------------------ --------
  5. BM_TEST_N                       P0                              USABLE
  6. BM_TEST_N                       P1                              USABLE
  7. BM_TEST_N                       P2                              USABLE
复制代码


5.置换分区(报错ORA-14646)
  1. alter table test exchange partition p2 with table temp including indexes ;

  2. ERROR at line 1:
  3. ORA-14646: Specified alter table operation involving compression cannot be performed in the presence of usable bitmap indexes
复制代码


6.只将P2分区进行unusable操作
  1. SQL> alter index BM_TEST_N modify partition P2 unusable;

  2. Index altered.
  3. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BM_TEST_N';

  4. INDEX_NAME                       PARTITION_NAME                      STATUS
  5. ------------------------------ ------------------------------ --------
  6. BM_TEST_N                       P0                              USABLE
  7. BM_TEST_N                       P1                              USABLE
  8. BM_TEST_N                       P2                              UNUSABLE
复制代码


7.置换分区(报错ORA-14646)
  1. SQL> alter table test exchange partition p2 with table temp including indexes ;
  2. alter table test exchange partition p2 with table temp including indexes
  3. *
  4. ERROR at line 1:
  5. ORA-14646: Specified alter table operation involving compression cannot be performed in the presence of usable bitmap indexes
复制代码


8.测试重建P2分区索引,单独unusable 掉temp表的位图索引
  1. SQL> alter index BM_TEST_N rebuild partition P2;

  2. Index altered.
  3. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BM_TEST_N';

  4. INDEX_NAME                       PARTITION_NAME                      STATUS
  5. ------------------------------ ------------------------------ --------
  6. BM_TEST_N                       P0                              USABLE
  7. BM_TEST_N                       P1                              USABLE
  8. BM_TEST_N                       P2                              USABLE


  9. SQL> alter index bm_temp unusable;

  10. Index altered.


  11. SQL> select INDEX_NAME,STATUS from dba_indexes where INDEX_NAME='BM_TEMP';

  12. INDEX_NAME                       STATUS
  13. ------------------------------ --------
  14. BM_TEMP                        UNUSABLE
复制代码


9.置换分区(报错ORA-14642)
  1. SQL> alter table test exchange partition p2 with table temp including indexes ;
  2. alter table test exchange partition p2 with table temp including indexes
  3. *
  4. ERROR at line 1:
  5. ORA-14642: Bitmap index mismatch for tables in ALTER TABLE EXCHANGE PARTITION
复制代码


10.在temp表的位图索引unusable的前提下,unusable掉test表的P2分区的位图索引
  1. SQL> alter index BM_TEST_N modify partition P2 unusable;

  2. Index altered.

  3. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BM_TEST_N';

  4. INDEX_NAME                       PARTITION_NAME                      STATUS
  5. ------------------------------ ------------------------------ --------
  6. BM_TEST_N                       P0                              USABLE
  7. BM_TEST_N                       P1                              USABLE
  8. BM_TEST_N                       P2                              UNUSABLE
复制代码


11.置换分区(正常置换)
  1. TEST表P2分区交换至TEMP表
  2. SQL> alter table test exchange partition p2 with table temp including indexes ;

  3. Table altered.

  4. TEMP表交换回TEST表P2分区
  5. SQL> alter table test exchange partition p2 with table temp including indexes ;

  6. Table altered.
复制代码


12.重建test表p2分区的位图索引和temp表的位图索引
  1. SQL> alter index BM_TEMP rebuild;

  2. Index altered.

  3. SQL> alter index BM_TEST_N rebuild partition p2;

  4. Index altered.


  5. SQL> select INDEX_NAME,STATUS from dba_indexes where INDEX_NAME='BM_TEMP';

  6. INDEX_NAME                       STATUS
  7. ------------------------------ --------
  8. BM_TEMP                        VALID

  9. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BM_TEST_N';

  10. INDEX_NAME                       PARTITION_NAME                      STATUS
  11. ------------------------------ ------------------------------ --------
  12. BM_TEST_N                       P0                              USABLE
  13. BM_TEST_N                       P1                              USABLE
  14. BM_TEST_N                       P2                              USABLE
复制代码


13.多次置换
  1. SQL> alter table test exchange partition p2 with table temp including indexes ;

  2. Table altered.

  3. TEMP表交换回TEST表P2分区
  4. SQL> alter table test exchange partition p2 with table temp including indexes ;

  5. Table altered.
复制代码


以上实验验证了当位图索引的分区表上使用压缩的时候,则在第一次做分区原子操作时,需要先unusable表的位图索引,然后执行分区原子操作,重建索引后,就可以进行多次原子操作了。
回复 支持 反对

使用道具 举报

2

主题

15

帖子

118

积分

版主

Rank: 7Rank: 7Rank: 7

积分
118
发表于 2017-9-7 11:50:35 | 显示全部楼层
实验2:创建非压缩分区表test,创建bitmap索引,创建不压缩普通表,创建bitmap索引,做滚窗操作
1.清理实验1中的测试环境

  1. SQL> drop table temp ;

  2. Table dropped.

  3. SQL> drop table test;

  4. Table dropped.
复制代码


2.创建非压缩的表test
  1. create table test (n number) partition by range (n)
  2. (partition p0 values less than (0)  
  3. ,partition p1 values less than (1) ) ;


  4. SQL> select PARTITION_NAME,COMPRESSION,COMPRESS_FOR from dba_tab_partitions where TABLE_NAME='TEST';

  5. PARTITION_NAME                       COMPRESS COMPRESS_FOR
  6. ------------------------------ -------- ------------
  7. P0                               DISABLED
  8. P1                               DISABLED
复制代码

3.创建表test的位图索引
  1. SQL> create bitmap index bm_test_n on test(n) local;

  2. Index created.
  3. SQL> select INDEX_NAME,STATUS from dba_indexes where INDEX_NAME='BM_TEST_N';

  4. INDEX_NAME                       STATUS
  5. ------------------------------ --------
  6. BM_TEST_N                       N/A

  7. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BM_TEST_N';

  8. INDEX_NAME                       PARTITION_NAME                      STATUS
  9. ------------------------------ ------------------------------ --------
  10. BM_TEST_N                       P0                              USABLE
  11. BM_TEST_N                       P1                              USABLE
复制代码


4.创建用户置换的表temp,并创建位图索引
  1. SQL> create table temp (n number) ;

  2. Table created.

  3. SQL> create bitmap index bm_temp on temp(n) ;

  4. Index created.

  5. SQL> select INDEX_NAME,STATUS from dba_indexes where INDEX_NAME='BM_TEMP';

  6. INDEX_NAME                       STATUS
  7. ------------------------------ --------
  8. BM_TEMP                        VALID
复制代码


5.在test表上添加p2分区
  1. SQL> alter table test add partition p2 values less than (2) ;

  2. Table altered.

  3. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BM_TEST_N';

  4. INDEX_NAME                       PARTITION_NAME                      STATUS
  5. ------------------------------ ------------------------------ --------
  6. BM_TEST_N                       P0                              USABLE
  7. BM_TEST_N                       P1                              USABLE
  8. BM_TEST_N                       P2                              USABLE
复制代码


6.置换分区(多次置换都没问题)
  1. TEST表P2分区交换至TEMP表
  2. SQL> alter table test exchange partition p2 with table temp including indexes ;

  3. Table altered.

  4. TEMP表交换回TEST表P2分区
  5. SQL> alter table test exchange partition p2 with table temp including indexes ;

  6. Table altered.
复制代码
回复 支持 反对

使用道具 举报

2

主题

15

帖子

118

积分

版主

Rank: 7Rank: 7Rank: 7

积分
118
发表于 2017-9-7 11:54:10 | 显示全部楼层
实验3:创建压缩分区表,创建B-Tree索引,创建不压缩普通表,创建B-Tree索引,做滚窗操作
1.清理实验2的测试环境
  1. SQL> drop table temp ;

  2. Table dropped.

  3. SQL>  drop table test;

  4. Table dropped.
复制代码

2.创建压缩的分区表test
  1. create table test (n number) partition by range (n)
  2. (partition p0 values less than (0) compress
  3. ,partition p1 values less than (1) nocompress)
  4. compress;


  5. SQL> select PARTITION_NAME,COMPRESSION,COMPRESS_FOR from dba_tab_partitions where TABLE_NAME='TEST';

  6. PARTITION_NAME                       COMPRESS COMPRESS_FOR
  7. ------------------------------ -------- ------------
  8. P0                               ENABLED        BASIC
  9. P1                               DISABLED
复制代码


3.创建B-Tree索引(本地)
  1. SQL> create index bt_test_n on test(n) local;

  2. Index created.



  3. SQL> select INDEX_NAME,STATUS from dba_indexes where INDEX_NAME='BT_TEST_N';

  4. INDEX_NAME                       STATUS
  5. ------------------------------ --------
  6. BT_TEST_N                       N/A

  7. SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BT_TEST_N';

  8. INDEX_NAME                       PARTITION_NAME                      STATUS
  9. ------------------------------ ------------------------------ --------
  10. BT_TEST_N                       P0                              USABLE
  11. BT_TEST_N                       P1                              USABLE
复制代码


4.创建用于置换的表temp和temp上的B-Tree索引
  1. SQL> create table temp (n number) ;

  2. Table created.

  3. SQL> create  index bt_temp on temp(n) ;

  4. Index created.

  5. SQL> select INDEX_NAME,STATUS from dba_indexes where INDEX_NAME='BT_TEMP';

  6. INDEX_NAME                       STATUS
  7. ------------------------------ --------
  8. BT_TEMP                        VALID
复制代码


5.创建test表的p2分区
  1. SQL> alter table test add partition p2 values less than (2) ;

  2. Table altered.


  3. SQL>  select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where INDEX_NAME='BT_TEST_N';

  4. INDEX_NAME                       PARTITION_NAME                      STATUS
  5. ------------------------------ ------------------------------ --------
  6. BT_TEST_N                       P0                              USABLE
  7. BT_TEST_N                       P1                              USABLE
  8. BT_TEST_N                       P2                              USABLE
复制代码


6.置换分区表(多次置换都可以)
  1. SQL> alter table test exchange partition p2 with table temp including indexes ;

  2. Table altered.

  3. SQL> alter table test exchange partition p2 with table temp including indexes ;

  4. Table altered.
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-20 00:45 , Processed in 0.046938 second(s), 27 queries .

快速回复 返回顶部 返回列表