Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92408494
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: Oracle

2008-04-12 17:56:30

来源:赛迪网技术社区    作者:meitian



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

1.3. 分区表索引的使用:

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

1.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>

1.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) 
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>
阅读(223) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~