我有一个表在我的数据库中有一个日期字段(VisitDate
)。当我执行下面的SQL查询,我收到1秒结果:GroupBy()运行非常缓慢
select year(VisitDate), month(visitDate)
from GABrowser
group by year(VisitDate), month(visitDate)
然而,在我的ASP.Net代码(在Visual Basic),后续需要12秒,执行:
Dim stats = db.GABrowsers.GroupBy(Function(s) New With {s.VisitDate.Value.Year, s.VisitDate.Value.Month})
'(Takes 12 seconds to enter in the For loop)
For Each stat In stats
Next
我不知道为什么需要这么长时间。这会导致我的网页加载速度非常慢。
必须查看SQL Server实际在做什么。你可以运行SQL分析器来查看你的应用程序发送到SQL Server的哪些命令?然后,你会看到什么是运行和多久。 –
为VisitDate创建聚簇索引并将您的SQL查询与EF Profiler相关 –
我从来没有听说过SQL分析器。我在哪里运行? – AskYous