Posts Tagged ‘inner join’

一个sql tuning的例子

今天同事遇到一个mysql语句执行慢的问题,叫我帮忙看看,具体语句如下:
select Products.ProductID,Name from Products 
where Products.ProductID in
(
 select ProductID from Price 
  INNER JOIN vendors ON (price.VendorID = vendors.VendorID)
 where (  price.ExpiryDate > now() or YEAR(Price.ExpiryDate) = 1 )
  and vendors.Status = ‘1′ 
  and Price.MemberID=@memberID and Price.Disable=’false’ and IsHistory=0
)
and Disable=’false’
他说单独执行括号内的子查询,速度很快,没有那个子查询速度也很快,但合并起来后速度就很慢!

Page 1 of 11

    搜索本站

    站点日历

    7月 2010
    « 4    
     1234
    567891011
    12131415161718
    19202122232425
    262728293031  

    订阅本站

    文章分类

    最新日志

    热点文章

    日志存档

    常用标签