在ORACLE中的分析函數都是基於某幾個字段劃分計算窗口
第一步
create table t_partition_hash(
object_name varchar
subobject_name varchar
object_id number
data_object_id number
object_type varchar
created date
last_ddl_time date
timestamp varchar
status varchar
temporary varchar
generated varchar
secondary varchar
)
partition by hash(object_type)(
partition t_hash_p
partition t_hash_p
partition t_hash_p
partition t_hash_p
partition t_hash_p
partition t_hash_p
partition t_hash_p
partition t_hash_p
);
create table t_big_hash(
object_name varchar
subobject_name varchar
object_id number
data_object_id number
object_type varchar
created date
last_ddl_time date
timestamp varchar
status varchar
temporary varchar
generated varchar
secondary varchar
);
第二步
insert into t_partition_hash select * from dba_objects;
insert into t_partition_hash select * from dba_objects;
第三步
begin
insert into t_rank
select object_id
rank() over (partition by object_type order by object_id) r_object_id
rank() over (partition by object_type order by subobject_name) r_subobject_name
rank() over (partition by object_type order by created) r_created
rank() over (partition by object_type order by last_ddl_time) r_last_ddl_time
rank() over (partition by object_type order by status) r_object_type
from t_partition_hash;
end;
使用hash分區表總共執行
begin
insert into t_rank
select object_id
rank() over (partition by object_type order by object_id) r_object_id
rank() over (partition by object_type order by subobject_name) r_subobject_name
rank() over (partition by object_type order by created) r_created
rank() over (partition by object_type order by last_ddl_time) r_last_ddl_time
rank() over (partition by object_type order by status) r_object_type
from t_big_table;
end;
使用非分區表執行
由此可見采用有效的HASH分區表可以有效提升分析函數在oracle中的執行效率
From:http://tw.wingwit.com/Article/program/Oracle/201311/17539.html