我有一个简单的Sql,外连接连接8个表 - 其中table6是空白的
通过
任何表上都没有索引。如果任何表上都没有索引,那么为什么这个表的列导致查询时间大幅增加?
只要我包含表6中的列(空白表/无行),查询执行时间就会从2秒跳到28秒。
只是从select中排除table6列仍保持外连接到table6,执行时间仍然是2/3秒。
可能是什么原因?
通过 Null Table ,我只是指空白表 - 更新主题以反映相同内容。
SELECT u.UserID,u.LastName,
CAST(t1.Hours as Int) as t1Hours
,CAST(t2.Hours as Int) as t2Hours
,CAST(t3.Hours_as Int) as t3Hours
,CAST(t4.Hours as Int) as t4Hours
,CAST(t5.Hours as Int) as t5Hours
,CAST(t6.Hours as Int) as t6Hours
,a.CYear
FROM Users u
LEFT OUTER JOIN table1 t1 ON u.UserID = t1.UserID
LEFT OUTER JOIN table2 t2 ON u.UserID = t2.UserID
LEFT OUTER JOIN table3 t3 ON u.UserID = t3.UserID
LEFT OUTER JOIN table4 t4 ON u.UserID = t4.UserID
LEFT OUTER JOIN table5 t5 ON u.UserID = t5.UserID
LEFT OUTER JOIN table6 t6 ON u.UserID = t6.UserID
LEFT OUTER JOIN A a ON u.UserID = a.Login
WHERE u.DepID = 1 and u.RoleID=1
Order By a.CYear desc , u.LastName asc
感谢。