Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

The query is a single select containing a lot of grouping levels and aggragate operations. With SET ARITHABORT ON is takes less than a second, otherwise it takes several minutes. We have seen this behavior on SQL Server 2000 and 2008.

share|improve this question

migrated from stackoverflow.com Dec 28 '11 at 12:26

3 Answers

up vote 13 down vote accepted

A little dated, but for anyone ending up here with a similar problem...

I had the same problem. For me it turned out to be parameter sniffing, which at first I didn't understand enough to care about. I added a 'set arithabort on' which fixed the problem but then it came back. Then I read:

http://www.sommarskog.se/query-plan-mysteries.html

It cleared -everything- up. Because I was using Linq to SQL and had limited options to fix the issue, I ended up using a query plan guide (see end of link) to force the query plan I wanted.

share|improve this answer

.NET applications connect with the option disabled by default, but it's enabled by default in Management Studio. The result is that the server actually caches 2 separate execution plans for most/all procedures. This affects how the server performs numerical calculations and as such you can get wildly different results depending on the procedure. This is really only one of 2 common ways a proc can get fed a terrible execution plan, the other being parameter sniffing.

Take a look at http://sqladvice.com/blogs/gstark/archive/2008/02/12/Arithabort-Option-Effects-Stored-Procedure-Performance.aspx for a little more discussion on it.

share|improve this answer
I agree with half of this answer. Am very sceptical about the numerical calculation claim though! – Martin Smith Jul 18 '10 at 9:31
1  
@Martin: I think I was unclear. I was just saying the ARITHABORT ON makes SQL Server will error out on any div/0 or arithmetic overflow error. When it is off it keeps going and for whatever reason can cause all kinds of horrible problems. – RandomBen Jul 19 '10 at 13:27
@Ben - Yes sorry I didn't want to particularly attack your answer I was just pointing out that it would be very easy to change a SET option get a better plan and misdiagnose this as being the Option itself that is at fault. I'm not convinced the guy in your link hasn't done this. – Martin Smith Jul 19 '10 at 13:37
@Martin - Not a problem, I didn't think you were attacking me. The other discussion I linked could be a little unclear. I was just trying to give supporting evidence. – RandomBen Jul 19 '10 at 14:08
@Martin In retrospect I believe that you are correct. – Jonathan Allen Jul 27 '11 at 17:06

I would argue that this was almost certainly parameter sniffing.

It is often stated that SET OPTIONS can affect performance in this way but I have yet to see a single authoritative source for this claim except for the case where you are using indexed Views / persisted computed columns.

In this case (for SQL2005+ and unless your database is in SQL2000 compatibility mode). If you have both ARITHABORT and ANSI_WARNINGS OFF then you will find the index not being used so may have a scan rather than the desired seek (and some overhead as the persisted calculation result can not be used). ADO.NET seems to default to having ANSI_WARNINGS ON from a quick test I just did.

The claim in Ben's answer that "the way the server performs numerical calculations" can add minutes to a result that would otherwise take less than a second just doesn't seem credible to me. I think what tends to happen is that upon investigating a performance performance problem Profiler is used to identify the offending query. This is pasted into management studio and run and returns results instantly. The only apparent difference between connections is the ARITH_ABORT option.

A quick test in a management studio window shows that when SET ARITHABORT OFF is turned on and the query is run that the performance problem recurs so that is apparently case closed. Indeed this seems to be the troubleshooting methodology used in the Gregg Stark link.

However that ignores the fact that with that option set you will end up getting the exact same bad plan from the cache. Even if you are logged in as a different user than the application connection uses.

I tested this by executing a test query first from a web application then from management studio with SET ARITHABORT OFF and could see the usecounts going up from the below query.

SELECT usecounts, cacheobjtype, objtype, text ,query_plan
FROM sys.dm_exec_cached_plans 
CROSS APPLY sys.dm_exec_sql_text(plan_handle) 
CROSS APPLY sys.dm_exec_query_plan(plan_handle) 
share|improve this answer
I think you may be right that plan caching may obfuscate the exact contribution of this option, but I recently ran across almost exactly this same problem (i.e. a query [stored procedure] that runs orders-of-magnitude faster in SSMS versus .NET SqlClient Data provider) and I did notice that subsequent executions were faster (which supports your plan caching hypothesis), but still significantly slower than executing the stored procedure (with the same parameter values) via SSMS. Has anyone systematically tested the performance of these options? – Kenny Evitt Sep 14 '10 at 19:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.