公司有这样一段SQL多表多字段的模糊查询,我搞了很久都无法解决该问题!麻烦各位大哥帮我看一下!
/*2,教育经历*/
declare @p8 int
set @p8=NULL
exec UP_PagerData @Fields='P.UserID,P.RealName,P.Sex,P.ProvinceName,P.School,P.Diploma,P.Specialty,I.UpdateTime',@Tables='Personal_Info P left join Personal_Intent I on I.UserID=P.UserID left join
Personal_Education O on O.UserID=P.UserID ',@Sort='Order by I.UpdateTime desc',@Filter=' I.SiteID=''1015'' and (O.School like ''%地质%'' or O.Description like ''%地质%'' or O.Specialty like ''%地质%'') and
P.Secrecy=''0'' and P.SeniorTalent<>''2'' and (P.Shield01<>''客户测试帐号'' or P.Shield02<>''客户测试帐号'' or P.Shield03<>''客户测试帐号'')',@PrimaryKey='P.UserID',@CurrentPage=1,@PageSize=15,@lineCount=@p8
output
select @p8以上那个模糊查询条件那一节,像那样加3个or就会出现查询超时的问题,
如果只用一个or则不会出现! 请高手帮我看一下,看看能不能优化一下!
/*2,教育经历*/
declare @p8 int
set @p8=NULL
exec UP_PagerData @Fields='P.UserID,P.RealName,P.Sex,P.ProvinceName,P.School,P.Diploma,P.Specialty,I.UpdateTime',@Tables='Personal_Info P left join Personal_Intent I on I.UserID=P.UserID left join
Personal_Education O on O.UserID=P.UserID ',@Sort='Order by I.UpdateTime desc',@Filter=' I.SiteID=''1015'' and (O.School like ''%地质%'' or O.Description like ''%地质%'' or O.Specialty like ''%地质%'') and
P.Secrecy=''0'' and P.SeniorTalent<>''2'' and (P.Shield01<>''客户测试帐号'' or P.Shield02<>''客户测试帐号'' or P.Shield03<>''客户测试帐号'')',@PrimaryKey='P.UserID',@CurrentPage=1,@PageSize=15,@lineCount=@p8
output
select @p8以上那个模糊查询条件那一节,像那样加3个or就会出现查询超时的问题,
如果只用一个or则不会出现! 请高手帮我看一下,看看能不能优化一下!
( patindex(''%地质%'',O.School)>0 or .........)
看看行不!
另外like %%用不了索引 换成 patindex(%col%,...)试下
2.只要对列进行计算,该列的索引将不起作用,如:aa+10=20
3.某些情况下的LIKE操作,该列的索引将不起作用,如:aa LIKE '%10%'
4.某些情况使用反向操作,该列的索引将不起作用,如:aa <>2
5.在WHERE中使用OR时,有一个列没有索引,那么其它列的索引将不起作用
--------------------------------------------------------------------------------超时时间已到。在操作完成之前超时时间已过或服务器未响应。
I.SiteID=''1015'' and O.School like ''%地质%'' and
P.Secrecy=''0'' and P.SeniorTalent <>''2'' and (P.Shield01 <>''客户测试帐号'' or P.Shield02 <>''客户测试帐号'' or P.Shield03 <>''客户测试帐号'')'
group by...
order by...
union
select ... from ...where ...
I.SiteID=''1015'' and O.Description like ''%地质%''and
P.Secrecy=''0'' and P.SeniorTalent <>''2'' and (P.Shield01 <>''客户测试帐号'' or P.Shield02 <>''客户测试帐号'' or P.Shield03 <>''客户测试帐号'')'
group by...
order by...
union
select ... from ...where ...
I.SiteID=''1015'' and O.Specialty like ''%地质%'' and
P.Secrecy=''0'' and P.SeniorTalent <>''2'' and (P.Shield01 <>''客户测试帐号'' or P.Shield02 <>''客户测试帐号'' or P.Shield03 <>''客户测试帐号'')'
group by...
order by...