|
原帖由 Byte_X_ 于 2009-10-30 16:09 发表 ![]()
测试过很多次了,确是这样。
这个今天刚刚测试过。确实是这样的,占用空间其实一样,效率上也差不多。如果启用压缩的话。
a,b列的值分布不同,
列a的不同值个数较小,约20个
列b的不同值个数较大,约1000万
用a来作引导列当然可以更加节省空间。
最主要看你在应用过程中,是否有使用b作引导列。如果有诸如where b=?,则使用b,a会更好。此外,还应该考虑索引块竞争等因素。
TOM的编程艺术中有索引一节中对这个问题也有讲述,以下是测试的脚本。可以试下。
create table t
as
select * from all_objects;
create index t_idx_1 on t(owner,object_type,object_name);
create index t_idx_2 on t(object_name,object_type,owner);
select count(distinct owner), count(distinct object_type),
count(distinct object_name ), count(*)
from t;
analyze index t_idx_1 validate structure;
select btree_space, pct_used, opt_cmpr_count, opt_cmpr_pctsave
from index_stats;
analyze index t_idx_2 validate structure;
select btree_space, pct_used, opt_cmpr_count, opt_cmpr_pctsave
from index_stats;
alter session set sql_trace=true;
declare
cnt int;
begin
for x in ( select /*+FULL(t)*/ owner, object_type, object_name from t )
loop
select /*+ INDEX( t t_idx_1 ) */ count(*) into cnt
from t
where object_name = x.object_name
and object_type = x.object_type
and owner = x.owner;
select /*+ INDEX( t t_idx_2 ) */ count(*) into cnt
from t
where object_name = x.object_name
and object_type = x.object_type
and owner = x.owner;
end loop;
end;
/ |
|