oracle 分区表外键建索引,INFORMIX 表分区及索引

本文详细介绍了在INFORMIX中如何创建和管理分片表,包括创建带有本地索引的分片、数据分布、索引设计、分片调整(删除和增加)过程。重点展示了如何在不影响表使用的情况下维护索引,以及执行计划中的优化特性。
摘要由CSDN通过智能技术生成

在INFORMIX 中,分片表可以支持除了在分片主键上进行创建本地索引外,还可以创建多个其他非分片键字段的本地索引,而在对该表进行分片管理时(删除一个分片,增加一个分片)不影响表的使用,索引不需要重建。【oracle中需要重建index】。

1、创建分片表

create table t_fragment_test

(

customer_num integer,

call_dtime datetime year to minute,

user_id char(32)

default user,

call_code char(1),

call_descr char(240),

res_dtime datetime year to minute,

res_descr char(240)

)fragment by expression

(customer_num>=1 andcustomer_num<100000) in dbs11,

(customer_num>=100000 andcustomer_num<200000) in dbs12,

(customer_num>=200000 andcustomer_num<300000) in dbs13,

(customer_num>=300000 andcustomer_num<400000) in dbs14

extent size 102400 next size 10240;

2、生成数据

--产生很多280万条记录,分布在dbs11~dbs14

3、创建索引

create unique index idx_t_fragment_test1 on t_fragment_test(customer_num,call_dtime) ;

--该索引第一个字段为分片键customer_num,以便在查询中可以消除分片,提升效率。

create index idx_t_fragment_test2 on t_fragment_test(res_dtime);

create index idx_t_fragment_test3 on t_fragment_test(call_code);

--创建2个不包含分片键的索引,但这2个索引会自动创建为本地索引(索引与数据存储在相同的dbspace上)

--注意事项:对于需要动态进行分片表分片调整,即动态删除(detach )增加(attach)分片的分片表,我们需要注意: informix数据库会为表中的primary key,unique 约束自动创建全局索引,同时不要包含外键。考虑到性能估需要注意不要在create table中使用primary key,unique约束,请使用unique index来替代实现。

4、删除一个分片

alter fragment on table t_fragment_test detach dbs11 t_fragment_test_dbs11;

--小于 1 second完成

5、增加一个分片

--CASE 1增加一个空分片

alter fragment on table t_fragment_test add (customer_num < 500000and customer_num >= 400000 ) in dbs11

--小于1second完成

--CASE 2把一个表增加到分片表中

alter fragment on table t_fragment_test attach t_fragment_test_dbs11 as customer_num < 100000and customer_num >= 1in dbs11

--执行时间较长,若只有idx_t_fragment_test1情况,速度很快

总结:

以下是为在删除分片前、后、增加一个分片后的两个SQL语句的执行计划,从执行计划可以得知INFORMIX的分片表及索引的使用情况十分优异。

select * from t_fragment_test where customer_num >=100000 and

customer_num <=100010

Estimated Cost: 14

Estimated # of Rows Returned: 60

1) informix.t_fragment_test: INDEX PATH

(1) Index Name: informix.idx_t_fragment_test1

Index Keys: customer_num call_dtime(Serial, fragments: 0)

Fragments Scanned: (0) dbs12

Lower Index Filter: informix.t_fragment_test.customer_num >= 100000

Upper Index Filter: informix.t_fragment_test.customer_num <= 100010

QUERY: (OPTIMIZATION TIMESTAMP:10-21-200910:02:28)

------

select * from t_fragment_test where res_dtime>= current year to second

andres_dtime<= current year to second +interval(3) hour to hour

Estimated Cost: 9

Estimated # of Rows Returned: 1

1) informix.t_fragment_test: INDEX PATH

(1) Index Name: informix.idx_t_fragment_test2

Index Keys: res_dtime(Serial, fragments: ALL)

(fragments might be eliminated at runtime because filter contains

runtime constants)

Lower Index Filter:informix.t_fragment_test.res_dtime >= CURRENT year to second

Upper Index Filter:informix.t_fragment_test.res_dtime <= CURRENT year to second+ interval(3) hour to hour

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值