Why is there a scan on my clustered index?

前端 未结 4 874
予麋鹿
予麋鹿 2021-01-01 16:44

SQL 2000
The NED table has a foreign key to the SIGN table NED.RowID to SIGN.RowID
The SIGN table has a foreign key to the NED table SIGN.SignID to NED.SignID
Th

4条回答
  •  情歌与酒
    2021-01-01 17:01

    You have several restrictions on the SIGN A table, if I read this correctly:

    WHERE  
            (A.DeptID = @DeptID OR   
            S.DeptID = @DeptID  
            AND   
            A.[EndTime] > @StartDateTime AND A.[StartTime] < @EndDateTime  
            AND   
            A.NEDStatusID = 2
    

    Are any of those restrictions (like DeptID, StartTime, EndTime, NEDStatusID) indexed? How well are those field selecting from your set of data?

    If you have 10 mio. rows and NEDStatusID has only 10 possible values, then any restriction on that field would always yield approx. 1 mio. rows - in that case, it might just be easier (and less costly) for SQL Server to do a full table scan (clustered index scan), especially if it also needs to check additional WHERE clauses on the same table that aren't indexed, either (StartTime, EndTIme etc.).

    Marc

提交回复
热议问题