这个情况该怎么建立索引,谢谢!
一个视图 viewtest
SELECT dbo.AI_Info.AI_ID, dbo.AI_INfo.AI_Type,
dbo.AI_Info.AI_Postion, dbo.AI_Info.AI_PR_ID,
dbo.AI_Info.AI_Input, dbo.AI_Info.AI_Check,
dbo.AI_Info.AI_IsCheck, dbo.AI_Info.AI_Date,
dbo.AI_Info.AI_StartDate, dbo.AI_Info.AI_EndDate,
dbo.AI_Info.AI_Flag, dbo.BI_Info.BI_Name, dbo.BI_Info.BI_EName,
dbo.BigType.BT_Name, dbo.BI_Info.BI_Logo
FROM dbo.BigType RIGHT OUTER JOIN
dbo.AI_Info ON
dbo.BigType.BT_Serial = dbo.AI_Info.AI_Type LEFT OUTER JOIN
dbo.BI_Info ON dbo.AI_Info.AI_PR_ID = dbo.BI_Info.BI_ID
WHERE (dbo.AI_Info.AI_Flag = 1)
一个查询语句
Select * From viewtest
WHERE AI_StartDate <= GETDATE() AND AI_EndDate > = GETDATE()
and AI_Type = '01 '
And AI_IsCheck=1
Order by AI_Postion
AI_Info,BI_Info,BigType 3个表的数据都不是很多,为什么很慢?谢谢!
------解决方案----------------------try
Select * From viewtest
WHERE getdate() between AI_EndDate and AI_StartDate
and AI_Type = '01 '
And AI_IsCheck=1
Order by AI_Postion
------解决方案--------------------先确定视图viewtest没有where条件情况下返回的行数多少。所说的慢,使用的查询时间是多少?
------解决方案--------------------AI_Postion建个聚集索引吧,可以取消掉排序
如果数据少的话,可以AI_StartDate、AI_EndDate2个字段联合做聚集索引
------解决方案--------------------outer 连接能否修改?
你这样连接的数量太大。索引估计也难解决。