数据库Oracle数据库中分区表的使用(4)_Oracle数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

数据库Oracle中分区表的使用(4)

作者:黑客防线网安Oracle维护基地 来源:黑客防线网安Oracle维护基地 浏览次数:0

本篇关键词:Oracle数据库Oracle教程
黑客防线网安网讯:    4partition idx_1 tablespace dinya_space01,  5partition idx_2 tablespace dinya_space02,  6partition idx_3 tablespace dinya_space03  7  );  Index created.  SQL>  ...
    4partition idx_1 tablespace dinya_space01,
  5partition idx_2 tablespace dinya_space02,
  6partition idx_3 tablespace dinya_space03
  7  );
  Index created.
  SQL>
  看查询的执行计划从下面的执行计划可以看出系统已经使用了索引:
  SQL> select * from dinya_test partition(part_01) t where t.item_id=12;
  Execution Plan
  ----------------------------------------------------------
  0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=187)
  10   TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'DINYA_TEST' (Cost=
  2 Card=1 Bytes=187)
  21INDEX (RANGE SCAN) OF 'DINYA_IDX_T' (NON-UNIQUE) (Cost=1
  Card=1)
  Statistics
  ----------------------------------------------------------
  0  recursive calls
  0  db block gets
  4  consistent gets
  0  physical reads
  0  redo size
  334  bytes sent via SQL*Net to client
  309  bytes received via SQL*Net from client
  2  SQL*Net roundtrips to/from client
  1  sorts (memory)
  0  sorts (disk)
  2  rows processed
  SQL>
  
   3.2全局索引分区的建立
  全局索引建立时global 子句允许指定索引的范围值,这个范围值为索引字段的范围值:
  SQL> create index dinya_idx_t on dinya_test(item_id)
  2  global partition by range(item_id)
  3  (
  4partition idx_1 values less than (1000) tablespace dinya_space01,
  5partition idx_2 values less than (10000) tablespace dinya_space02,
  6partition idx_3 values less than (maxvalue) tablespace dinya_space03
  7  );
  Index created.
  SQL>
  本例中对表的item_id字段建立索引分区,当然也可以不指定索引分区名直接对整个表建立索引,如:
  SQL> create index dinya_idx_t on dinya_test(item_id);
  Index created.
  SQL>
  同样的,对全局索引根据执行计划可以看出索引已经可以使用:
  SQL> select * from dinya_test t where t.item_id=12;
  Execution Plan
  ----------------------------------------------------------
  0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=3 Bytes=561)
  10   TABLE ACCESS (BY GLOBAL INDEX ROWID) OF 'DINYA_TEST' (Cost
  =2 Card=3 Bytes=561)
  21INDEX (RANGE SCAN) OF 'DINYA_IDX_T' (NON-UNIQUE) (Cost=1
  Card=3)
  Statistics
  ----------------------------------------------------------
  5  recursive calls
  0  db block gets
  10  consistent gets
  0  physical reads
  0  redo size
  420  bytes sent via SQL*Net to client
  309  bytes received via SQL*Net from client
  2  SQL*Net roundtrips to/from client
  3  sorts (memory)
  0  sorts (disk)
  5  rows processed
  SQL>
  4分区表的维护:
  了解了分区表的建立、索引的建立、表和索引的使用后,在应用的还要经常对分区进行维护和管理日常维护和管理的内容包括:增加一个分区,合并一个分区及删除分区等等。下面以范围分区为例说明增加、合并、删除分区的一般操作:
  4.1增加一个分区:
  SQL> alter table dinya_test
  2  add partition part_04 values less than(to_date('2012-01-01','yyyy-mm-dd')) tablespace dinya_spa
  ce03;
  Table altered.
  SQL>
  增加一个分区的时候,增加的分区的条件必须大于现有分区的最大值,否则系统将提示ORA-14074 partition bound must collate higher than that of the last partition 错误。
  4.2合并一个分区:
  SQL> alter table dinya_test merge partitions part_01,part_02 into partition part_02;
  Table altered.
  SQL>
  在本例中将原有的表的part_01分区和part_02分区进行了合并,合并后的分区为part_02,如果在合并的时候把合并后的分区定为part_01的时候,系统将提示ORA-14275 cannot reuse lower-bound partition as resulting partition 错误。
  4.3删除分区:
  SQL> alter table dinya_test drop partition part_01;
  Table altered.
  SQL>
  删除分区表的一个分区后,查询该表的数据时显示,该分区中的数据已全部丢失,所以执行删除分区动作时要慎重,确保先备份数据后再执行,或将分区合并。
  5总结:
  需要说明的是,本文在举例说名分区表事务操作的时候,都指定了分区,因为指定了分区,系统在执行的时候则只操作该分区的记录,提高了数据处理的速度。不要指定分区直接操作数据也是可以的。在分区表上建索引及多索引的使用和非分区表一样。此外,因为在维护分区的时候可能对分区的索引会产生一定的影响,可能需要在维护之后重建索引,相关内容请参考分区表索引部分的文档。
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-13068-1.html
网站维护教程更新时间:2012-03-23 00:50:05  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer