--创建分区表
create table table1_NEW(...)
partition by range(col1)
( partition part1 values less than (...),
partition part2 values less than (...),
...
) as select * from table1_old where 1=0;
--创建用于分区的交换表
... 生成table1_exchange_1,table1_exchange_2 ... -- 交换数据:
alter table table1_new
exchange partition part1
with table table1_exchange_1
without validation ... --创建索引
Create index IX_table1_NEW on table1_NEW (col1)
local(
partition part1 tablespace tbs_indx,
partition part2 tablespace tbs_indx,
...
);
-- 查询(使用了分区索引):
select count(*) from table1_new partition(part1); 当分区中出现许多事务并且要保证所有分区中的数据记录的惟一性时
采用全局索引,在建立全局索引时,Global子句允许指定索引的范围
值,这个范围值可以不同于表分区的范围值。只有建立局部索引才
会使索引分区与表分区间建立起一一对应关系。 因此,在大多数情况下,应该使用局部索引分区。若使用了此索引,
分区就能够很容易地将索引分区与表分区建立关联,局部索引比全局
索引更易于管理。
应该注意的问题:
1. 弄清楚表究竟需不需要分区,主要看数据增长的频率 .
2. 合理地规划以什么列作为分区的标准
3. 合理地建立分区索引
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货