打印本文 打印本文 关闭窗口 关闭窗口
Oracle中分区表的使用
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1977  更新时间:2009/4/22 22:04:10  文章录入:mintao  责任编辑:mintao
transaction_id=4;

 

1 row deleted.

 

SQL> commit;

 

Commit complete.

 

SQL>

 

上面例子删除了第二个分区part_02中的交易记录ID为4的一条记录,和更新数据相同,如果指定了分区,而条件中的数据又不在该分区中时,将不会删除任何数据。

 

3         分区表索引的使用:

分区表和一般表一样可以建立索引,分区表可以创建局部索引和全局索引。当分区中出现许多事务并且要保证所有分区中的数据记录的唯一性时采用全局索引。

3.1     局部索引分区的建立:

SQL> create index dinya_idx_t on dinya_test(item_id)
  2  local
  3  (
  4     partition idx_1 tablespace dinya_space01,
  5     partition idx_2 tablespace dinya_space02,
  6     partition 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)

   1    0   TABLE ACCESS (BY LOCAL INDEX ROWID) OF ''''DINYA_TEST'''' (Cost=

          2 Card=1 Bytes=187)

   2    1     INDEX (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  (
  4     partition idx_1 values less than (1000) tablespace dinya_space01,
  5     partition idx_2 values less than (10000) tablespace dinya_space02,
  6     partition 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)

   1    0   TABLE ACCESS (BY GLOBAL INDEX ROWID) OF ''''DINYA_TEST'''' (Cost

          =2 Card=3 Bytes=561)

 

   2    1     INDEX (RANGE SCAN) OF ''''DINYA_IDX_T'''' (NON-UNIQUE) (Cost=1

           Card=3)

Statis

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口