全局分区索引与局部分区索引(二)
tablespace tbs3 datafile '+DATA6_MIDG'; SQL> --创建一个range分区表 create table t_part(a int,b int,data char(20)) partition by range (a) (partition p1 values less than(2) tablespace tbs1, partition p2 values less than(3) tablespace tbs2 ); --插入一些数据 insert into t_part select mod(rownum-1,2)+1,rownum,'x' from all_objects; commit; SQL> select * from t_part where rownum<=10; --创建局部前缀索引与局部非前缀索引 create index local_prefixed on t_part(a,b) local; create index local_noprefixed on t_part(b) local; create index local_prefixed on t_part(a,b) local (partition ind1 tablespace tbs3, partition ind2 tablespace tbs2);
--为表收集统计信息 begin dbms_stats.gather_table_stats(user,'t_part',cascade=>TRUE);end; --把tbs2表空间下线,此时可以验证索引分区消除,将tbs1下线,可以验证表分区消除。 alter tablespace tbs3 offline; --再用这种命令来测试 select * from t_part where a=1 and b=1; select * from t_part where b=1; select /*+full(t_part)*/ * from t_part where a=1 and b=1;