日期:2014-05-19  浏览次数:20715 次

这条语句为何这么慢。。。(stuff 有4K条记录,datetimer 有5W条记录)没建索引

select   *   from  
(select   bianhao     from   stuff   where   loss=0   and   flid=38)   a
,(select   *   from   datetimer   where   rq> = '2007-06-01 '   and   rq <= '2007-06-28 ')   b
where   a.bianhao=b.bianhao  


如果要建索引应该怎么创建好点。

------解决方案--------------------
select a.bianhao,b.* from stuff a,datetimer,b where a.bianhao=b.bianhao and a.loss=0 and a.flid=38 and b.rq> = '2007-06-01 ' and b.rq <= '2007-06-28 '

------解决方案--------------------
stuff 在 loss,flid 建联合索引
datetimer 在rq上建立索引

select a.bianhao,b.* from stuff a inner join datetimer b on a.bianhao=b.bianhao
where a.loss=0 and b.flid=38 and b.rq> = '2007-06-01 ' and b.rq <= '2007-06-28 '