简体   繁体   English

为什么要调用DatabaseInstance.ExecuteSprocAccessor <T> (...)这么简单的查询花了这么长时间?

[英]Why is a call to DatabaseInstance.ExecuteSprocAccessor<T>(…) taking so long for such a simple query?

Very odd slowdown when calling the Data Access Application block. 调用数据访问应用程序块时非常奇怪的减速。

The SP ("QuestionsToBeAnswered") it's calling returns 58 rows with three columns (two GUIDs and an integer: 21AF77DA-2E76-47DB-AB54-0E5C85CD9AD8, 21AF77DA-2E76-47DB-AB54-0E5C85CD9AF0, 2) in less than 1 second when executed directly on the server. 它调用的SP(“QuestionsToBeAnswered”)在不到1秒的时间内返回58行,包含三列(两个GUID和一个整数:21AF77DA-2E76-47DB-AB54-0E5C85CD9AD8,21AF77DA-2E76-47DB-AB54-0E5C85CD9AF0,2)直接在服务器上执行。 My SQL experience is pretty good, and I'm convinced the problem doesn't exist on the SQL server. 我的SQL经验非常好,我确信SQL服务器上不存在这个问题。

However, when it's called through DAAB, it's taking a very long time to return the collection of objects. 但是,当通过DAAB调用它时,返回对象集合需要很长时间。 ExecuteSprocAccessor(...) normally returns an IEnumerable, and the SP isn't executed until the collection is enumerated or otherwise consumed, so this problem doesn't show up until consumption occurs. ExecuteSprocAccessor(...)通常返回IEnumerable,并且在枚举或以其他方式消耗集合之前不会执行SP,因此在消费发生之前不会显示此问题。

DatabaseInstance.ExecuteSprocAccessor<T>(storedProcedure, rowMapper, args);

Given that the same code has no problem returning >200 rows of considerably more complex information, I am baffled as to why this code is taking so long (55 seconds!) to execute. 鉴于相同的代码没有问题返回> 200行相当复杂的信息,我感到困惑的是为什么这段代码需要这么长时间(55秒!)才能执行。

Any ideas would be welcomed... 任何想法都会受到欢迎......

You could try running SQL Profiler to see what the actual call looks like when it run using DAAB. 您可以尝试运行SQL事件探查器,以查看使用DAAB运行时实际调用的内容。 With that in hand take a look at the execution plan that it is using. 随着这一点,看看它正在使用的执行计划。

In the past I wrote some code that ran fine as a SQL query but was really slow as a stored procedure. 在过去,我编写了一些代码,这些代码在SQL查询中运行良好,但作为存储过程实际上很慢。 Turns out do to some duplicate indexes the query optimizer was using a different execution plan for the SQL Query then the stored procedure. 事实证明,查询优化器正在使用不同的SQL查询执行计划,然后是存储过程。 After getting the indexes sorted both ran at the same quick speed. 获取索引后,两者都以相同的快速速度运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM