A demo of nonprefix & prefix index

下面是我做的一个关于分区索引的一个实验,加深下对相关概念的理解:

关于相关的概念请参看我的blog:

http://blog.csdn.net/waterxcfg304/article/details/8509734

1,create a partition table

create table batch_usr.sales_history
(
 PROD_ID NUMBER not null,
 CUST_ID NUMBER not null,
 TIME_ID DATE   not null,
 CHANNEL_ID NUMBER not null,
 PROMO_ID NUMBER not null,
 QUANTITY_SOLD NUMBER(10,2) not null,
 AMOUNT_SOLD NUMBER(10,2) not null
)
partition by range(time_id)
(
partition P1998_1H values less than (to_date('1998-07-01','yyyy-mm-dd')) tablespace DATA1,
partition P1998_2H values less than (to_date('1999-01-01','yyyy-mm-dd')) tablespace DATA2,
partition P1999_1H values less than (to_date('1999-07-01','yyyy-mm-dd')) tablespace DATA3,
partition P1999_2H values less than (to_date('2000-01-01','yyyy-mm-dd')) tablespace DATA4,
partition P2000_1H values less than (to_date('2000-07-01','yyyy-mm-dd')) tablespace DATA5,
partition P2000_2H values less than (to_date('2001-01-01','yyyy-mm-dd')) tablespace DATA6,
partition P2001_1H values less than (to_date('2001-07-01','yyyy-mm-dd')) tablespace DATA7,
partition P2001_2H values less than (to_date('2002-01-01','yyyy-mm-dd')) tablespace DATA8
);

2,populate data into sales_history table
insert into batch_usr.sales_history select * from sh.sales where to_number(to_char(time_id,'yyyy')) in (1998,1999,2000,2001);

 

3,The followings are different types of indexes that will be created.

Firstly Global indexes:
可以
create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history(prod_id) global
partition by hash (prod_id)
partitions 8 store in (batch)
nologging
parallel;
drop index batch_usr.sales_hist_pid_idx;

不可以(global索引必须是prefix)
create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history(time_id) global
partition by hash (prod_id)
partitions 8 store in (batch)
nologging
parallel;
ERROR at line 2:
ORA-14038: GLOBAL partitioned index must be prefixed


可以
create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history(time_id) global
partition by hash (time_id)
partitions 8 store in (batch)
nologging
parallel;
drop index batch_usr.sales_hist_pid_idx;

不可以(global索引必须是prefix)
create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history(prod_id) global
partition by hash (time_id)
partitions 8 store in (batch)
nologging
parallel;

ERROR at line 2:
ORA-14038: GLOBAL partitioned index must be prefixed


Secondly local indexes:

无前缀(nonprefix)的索引(索引列和表分区一列不一样)

SQL> create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history(prod_id) local;

Index created.

SQL> drop index batch_usr.sales_hist_pid_idx;

Index dropped.

 

有前缀(prefix)的索引(索引列和表分区一列一样)

SQL> create index batch_usr.sales_hist_pid_idx on batch_usr.sales_history(time_id) local;

Index created.

SQL> drop index batch_usr.sales_hist_pid_idx;

Index dropped.

 

你可能感兴趣的:(index,index,prefix,nonprefix)