这条查询运行时间需要30秒,太长了,不知道怎样优化呢 ?
SELECT do.Order_ID as id, do.BriefNo, do.ReviseNo as Revise,do.Bid,price = do.grade + '/' + do.currency,et.Exhibition_en, et.Exhibition_cn, ct.Client_name as client, et.Start_Date, et.End_Date,ut.USERNAME as Sales, Designer = dbo.f_getorderdesigner(Do.Order_ID), do.Act_Start_Date, do.Act_End_Date,do.Summit_Time as Create_date FROM DesignOrder as do INNER JOIN Join_ID as ji ON do.Join_ID = ji.Join_id INNER JOIN USER_TABLE as ut ON do.UserID = ut.USERID INNER JOIN UserGroup as ug ON ut.USERGROUP_ID = ug.UserGroup_ID INNER JOIN Exhibition_Table as et ON ji.Exhibition_ID = et.Exhibition_ID INNER JOIN Client_Table as ct ON ji.Client_ID = ct.Client_ID INNER JOIN Company as cp ON ut.Company_id = cp.Company_id INNER JOIN Nature as na ON do.Nature_Id = na.Nature_id WHERE ( do.UserID = ut.USERID and dbo.f_designer_exist(Do.Order_ID,'jacky.jiang') like 'jacky.jiang' and ut.State = 'active' and et.Start_Date>='4/1/2011' and et.Start_Date<='6/1/2011' )
------解决方案--------------------
尽量将条件写到子查询中之后在进行连接查询.这样级数量要小的多.同时在关联的字段上加上索引.
------解决方案--------------------
你应该提供更详细的说明,比如哪个表的数据量比较大,1楼应该是高手,和楼主沟通起来有些脱节,哈哈。3楼说的很有道理,你的索引建的貌似有问题的。
------解决方案--------------------
查询条件中,有函数,是不是一个原因哪??如果这个自定义的函数效率很差,那你的SQL应该快不了
------解决方案--------------------
建議不要這麼多INNER JOIN 多用TEMP TABLE 表 試試 。。