INFORMIX 分片表及索引

2021-05-09 05:20:52 字數 3603 閱讀 8989

在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-2009

10: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

informix 臨時表空間

informix臨時表空間 在 informix 資料庫中,我們經常會建立一些臨時表來處理應用中的臨時資訊。系統可以採用如下兩種方式建立臨時表 使用 select into temp 語句隱含地建立臨時表 使用 create temp table 語句顯示地建立臨時表 如果資料庫採用非日誌模式,db...

Informix系統表用途

systables 描述資料庫中的表 syscolumns 描述資料庫中表的列 sysindexes 描述資料庫中列的索引 sysfragments 儲存了分段索引的片段資訊 sysfragauth 表識別列級許可權 sysviews 描述了資料庫中定義的每個檢視 sysdpend 描述了檢視是如何...

informix 查詢 鎖表

在informix中查詢select,表有千百萬條資料,結構導致松鼠死掉,沒有理會!繼續在此表中查詢,但是一直查不出來,sql一直在執行。原來是上個select造成鎖表,導致這個查詢無法進行。1 查詢出執行select語句的sql onstat g sql grep select 4855470 s...