简体   繁体   English

SQL Server的奇怪行为-需要一些建议

[英]Strange behaviour of SQL Server - need some advice

I have some sophisticated query (just select with many nested joins and subqueries). 我有一些复杂的查询(只需选择许多嵌套的联接和子查询)。
I've noticed in SQL Profiler that when it is executed from .NET application by ADO it takes 30 seconds to complete and does 129 writes (???). 我在SQL事件探查器中注意到,当它由ADO从.NET应用程序执行时,需要30秒才能完成,并且会执行129次写入(???)。

When I've executed this same query (copied from Profiler) in SQL Server Management Studio it takes only 1.2 seconds and 0 writes (correct). 当我在SQL Server Management Studio中执行了相同的查询(从Profiler复制)后,只需1.2秒和0次写入(正确)。

Do you know why there is so different performance depending on execution method? 您知道为什么根据执行方法会有如此不同的性能吗?

And why select makes writes on DB? 以及为什么select在DB上进行写操作?

The query can be optimised differently depending on where it is run from. 可以根据查询的来源对查询进行不同的优化。 I had the same when running a stored proc vs. the actual query inside the proc in SSMS. 当运行存储的proc与SSMS中proc内部的实际查询时,我遇到了相同的问题。 The difference was that the one query was being optimised with certain JOIN hints and the other query wasn't which had a massive impact on performance. 不同之处在于,一个查询已使用某些JOIN提示进行了优化,而另一个查询并未对性能产生重大影响。

You may just need to manual add a join hint to the query. 您可能只需要手动向查询添加联接提示 Without seeing the query I can' tell you what change you need to make but try running the query in SSMS and then having a look at the execution plan. 在没有看到查询的情况下,我无法告诉您需要进行哪些更改,但是请尝试在SSMS中运行查询,然后查看执行计划。

此时序表明数据已缓冲,并导致了这种复杂的行为。

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

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