1、滾動窗口表rolling window tables介紹
(按時間/大小自動清除表,rolling purge)
Informix12.1版本在間隔分片的基礎上增加了滾動窗口表,在實際的應用中,可以用於歷史數據清除,不需要人工干預。
通過DDL實現自動摘除分片
基於間隔分片策略
可以指定表上激活的分片個數,當超過分片個數時,最小值的分片將被移走或刪除
也可以指定表的大小,當查過指定空間時,最小值的分片將被刪除
被摘除的片可用於掛載或者刪除掉
分片移動到歸檔表
非常適合於OEM的應用或者歷史數據清除,不需要人工干涉
索引上有相同的操作 (detach or drop),但必須使用本地索引
2、語法
FRAGMENT BY RANGE (<column list>)
INTERVAL (<value>)
[ [ROLLING(<integervalue>FRAGMENTS)]
[LIMIT TO <integervalue> <SIZEUNIT>] DETACH|DISCARD]
STORE IN (<dbspacelist> |<function_to_return_dbspacename()>) ;
SIZEUNIT: [ KB | KiB | MB | MiB | GB| GiB | TB|TiB ]§通過limit to語句,設置表的最大容量以kb |mb|gb |tb爲單位
§通過discard語句,分片將被刪除,它的空間將被返回到chunk/dbspace free list
§通過detach語句,分片將被摘除,創建一個新的獨立的表
–新表的名稱將繼承原表和表所包含的數據範圍的屬性
• 新表名稱是source_table_LowVal_HighVal
• 例如, orders表按月分片,老的分片被摘除之後,將創建以下面的表名命名的表:
• orders_1_2 包含1月份的數據
• orders_2_3 包含2月份的數據
§真正的清除並不是自動的,必須調用syspurge()
–掃描系統表,去查找超過限制的滾動窗口表
• 不帶任何參數
• 返回刪除的分片個數
–可以手工調用或者使用系統自帶調度器中的purge_tables任務
• 每天凌晨0:45運行,但可以修改爲不同的時間
3、舉例:
create table orders
(order_num serial(1001),
order_date date,
customer_num integer not null )
partition by range(order_date) interval(1 units month)
rolling (6 fragments) limit to 20 gb detach
store in (mydbs,rootdbsdbs)
partition prv_partition values < date(’01-01-2010’) inmydbs;
插入數據,分佈在7個不同的月份,會自動生成7個分片:
truncate table orders;
insert into orders(order_date,customer_num) values('01-01-2017',1);
insert into orders(order_date,customer_num) values('02-02-2017',2);
insert into orders(order_date,customer_num) values('03-03-2017',3);
insert into orders(order_date,customer_num) values('04-04-2017',4);
insert into orders(order_date,customer_num) values('05-05-2017',5);
insert into orders(order_date,customer_num) values('06-06-2017',6);
insert into orders(order_date,customer_num) values('07-07-2017',7);
4、確認分片數量和每個片上的記錄數:
update statistics for table orders;
unload to frag.out selectexprtext,nrows fromsysfragments
where tabid in (select tabid from systables wheretabname='orders’);
catfrag.out
|20.0|
order_date|0.0|
interval( 1) month(9) to month|0.0|
mydbs,rootdbsdbs|0.0|
VALUES< DATE ('01/01/2010' )|0.0|
VALUES>= DATE ('01/01/2017' ) AND VALUES < DATE ('02/01/2017' )|1.0|
VALUES>= DATE ('02/01/2017' ) AND VALUES < DATE ('03/01/2017' )|1.0|
VALUES>= DATE ('03/01/2017' ) AND VALUES < DATE ('04/01/2017' )|1.0|
VALUES>= DATE ('04/01/2017' ) AND VALUES < DATE ('05/01/2017' )|1.0|
VALUES>= DATE ('05/01/2017' ) AND VALUES < DATE ('06/01/2017' )|1.0|
VALUES>= DATE ('06/01/2017' ) AND VALUES < DATE ('07/01/2017' )|1.0|
VALUES >= DATE ('07/01/2017' )AND VALUES < DATE ('08/01/2017' )|1.0|5、查看任務的缺省定義,保存在sysadmin的ph_task表中
tk_id 37
tk_name purge_tables
tk_description Dailytask to ensure that rolling window tables stay within limits
tk_type TASK
tk_sequence 5
tk_result_table
tk_create
tk_dbs sysadmin
tk_execute rwt_purge_tables
tk_delete
tk_start_time 00:45:00
tk_stop_time
tk_frequency 100:00:00
tk_next_execution 2018-01-10 00:45:00 #下次的執行時間距離現在的時間太遠
tk_total_execution + 5
tk_total_time 1.502911129527
tk_monday t
tk_tuesday t
tk_wednesday t
tk_thursday t
tk_friday t
tk_saturday t
tk_sunday t
tk_attributes 412
tk_group TABLES
tk_enable t
tk_priority 06、當前的系統時間是1點30左右,爲了看到清除的效果,因此將定時任務的執行時間修改爲1點33;
updateph_task settk_start_time='01:33:00' wheretk_id=37
select* from ph_task wheretk_id=37
tk_id 37
tk_name purge_tables
tk_description Dailytask to ensure that rolling window tables stay within limits
tk_type TASK
tk_sequence 7
tk_result_table
tk_create
tk_dbs sysadmin
tk_execute rwt_purge_tables
tk_delete
tk_start_time 01:33:00
tk_stop_time
tk_frequency 100:00:00
tk_next_execution 2018-01-10 01:33:00
tk_total_executio+ 6 #執行次數由5增加到67、orders_01_01_2017_02_01_2017是detach之後新生成的
摘除的表:
INFO FOR TABLE >>
Choose a table with the Arrow Keys, orenter a name, then press Return.
----------------------- mydb@demo_on----------- Press CTRL-W for Help --------
orders
orders_01_01_2017+
'root'.t1
orders_01_01_2017_02_01_2017
作者:陸川