又有个棘手的问题。
3个表关联取值,索引怎么建提高效率?3个表的数据量都约在4000万左右。普通服务器,做了2个多小时(没建索引)。
在trandate上建索引,Join操作就用不了索引,在col1或col2上建索引,数据量太多,不知道结果如何。
若将join 改成函数操作,效率怎么样?
select a.*, c.cusno from tab1 a, tab2 b, tab3 c
where
a.col1=b.col1 and b.col2=c.col2
and a.trandate='2009-03-31'
and b.trandate='2009-03-31'
and c.trandate='2009-03-31'
在tab2的col1,tab3的col2上建低聚基索引,
函数写成:
func(in_col)
select col2 into var_str from tab2 where col1=in_col;
select custno into var_custno from tab3 where col2=var_str;
return var_custno
调用:
select a.*, func(col1) as custnofrom tab1 a where
trandate ='2009-03-31'