<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Never Say Never &#187; Common Problems</title>
	<atom:link href="http://phelabaum.com/archive/tag/common-problems/feed/" rel="self" type="application/rss+xml" />
	<link>http://phelabaum.com</link>
	<description>MS SQL Server Development</description>
	<lastBuildDate>Thu, 29 Sep 2011 02:20:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Calculating ROI on Performance Tuning</title>
		<link>http://phelabaum.com/archive/2010/06/calculating-roi-on-performance-tuning/</link>
		<comments>http://phelabaum.com/archive/2010/06/calculating-roi-on-performance-tuning/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 05:09:45 +0000</pubDate>
		<dc:creator>Seth Phelabaum</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Common Problems]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://phelabaum.com/archive/2010/06/calculating-roi-on-performance-tuning/</guid>
		<description><![CDATA[Recently on the SSC forums, someone asked about how to measure the money in an actual dollar figure that they have saved the company with their performance tuning.&#160; I&#8217;ve often struggled with this myself, and so I started thinking about it a bit deeper.&#160; I started to respond in the thread; then decided I was [...]]]></description>
			<content:encoded><![CDATA[<p>Recently on the SSC forums, someone asked about how to measure the money in an actual dollar figure that they have saved the company with their performance tuning.&#160; I&#8217;ve often struggled with this myself, and so I started thinking about it a bit deeper.&#160; I started to respond in the thread; then decided I was going to be a bit too long winded so I moved it here.&#160;&#160; The following are some of my thoughts/opinions on the subject.</p>
<p>I think everyone will agree that it&#8217;s probably not worth the time to optimize a report that runs once a month at 3 AM on a Saturday to go from 10 minutes to 2 minutes.&#160; Most people would also agree that it&#8217;s worth optimizing a query that users have to wait on nonstop all day long to take it from 5 seconds to 2 seconds (or even 4.5 seconds depending on the amount of time it&#8217;d take to accomplish that change, 10% is still pretty huge for something being used constantly).&#160; For the latter, you can probably take the improvement percentage and multiply it by the salaries of all those affected and come up with a number&#8230; but is it fair to assume that that number goes straight to you? </p>
<p>Let&#8217;s take a data entry process for an example.&#160; We&#8217;ll say we have employees doing data entry and 50% of their time is spent entering things that rely on a stored procedure that takes 5 seconds to run.&#160; You improve that SP to run in 1s.&#160; While this is obviously an improvement, is it fair to take 80% of 50% of their pay and attribute it to your performance savings?&#160; I&#8217;d say not.&#160; For one thing, you have the keying in of the information before they hit save and wait on the query.&#160; Let&#8217;s say they spend half their time typing and half of it waiting on that query to run.&#160; We&#8217;re now talking about 80% of 25%.&#160; Then, factor in the rest of the process.&#160; Perhaps that 5 seconds that they spend &#8216;waiting&#8217; is really spent flipping to the next page of their data or tabbing to some other application which it takes them 3 seconds to do anyways.&#160; Now you&#8217;re only talking about 40% of 25%.&#160; </p>
<p>At the very least, you can *guess* at what number you saved there.&#160; The numbers are a lot harder to get for anything that users don&#8217;t directly wait on.&#160; A few examples of these types of queries might be: </p>
<p>Agent Jobs that run constantly throughout the day   <br />Pre-aggregated reports or data tables that run periodically and store that data for on demand usage    <br />Processes that take only milliseconds but might perform more reads or writes than necessary but are run hundreds of thousands of times a day. </p>
<p>Is there any direct ROI on improving these things?&#160; Maybe&#8230; maybe not.&#160; If that process that takes a few milliseconds but runs constantly takes more locks than it truly needs, it could lead to slowing everything else down by fractional amounts or cause blocking/deadlocking issues in your database that &#8216;freeze&#8217; users and force them to wait, thus wasting time and money.&#160; However, maybe it never would have gotten to that point.&#160; If you weren&#8217;t proactive with fixing that because it wasn&#8217;t causing any problems right now, it could end up costing the company tens or hundreds of thousands of dollars in lost productivity if and when it DID become a problem.&#160; You could measure that.&#160; But is it fair to measure it if you addressed the issue preemptively and it never happened?&#160; How do you come up with a number in this case?&#160; How do you decide what to count *for* yourself and what to count against yourself?&#160; </p>
<p>Going a completely different route, let&#8217;s look at bug fixing.&#160; Let&#8217;s say you identify a loophole in the invoicing process that only applies to .05% of invoices because of the rare criteria.&#160; Maybe that loophole only cost you a few hundred dollars for the 2 years it has existed, but it *could* have cost you thousands depending on which line items it happened to affect.&#160; Do you count the hundreds of dollars it already cost you, or the thousands of dollars it would have eventually cost? </p>
<p>Then you have the customers to take into account on things like a public facing website.&#160; This is also nearly impossible to measure.&#160; If your web queries are all inefficient and slow, it might make your website feel sluggish, unresponsive or broken.&#160; Your queries could also have bugs that return errors to the customers.&#160; Addressing either of these things is obviously going to improve your customers&#8217; experience while browsing your website, but how do you convert that into a physical dollar amount?&#160; Can you claim a percentage of the revenue from that customer because you improved their web viewing experience?&#160; I doubt the sales team would agree with whatever percentage you thought should be attributed to IT/development.&#160; What about additional features on the website that are the deciding factor in getting new customers?&#160; In most cases customers aren&#8217;t going to come right out and say &quot;You know, I was really on the fence about which company to go with, but seeing that I could just check my ___ on your website really made me choose you.&quot;&#160; </p>
<p>At the end of the day, if you really want to calculate a dollar value of the things you&#8217;ve done, I think you have to break things down to a very low level.&#160; Create a range for each thing you fix, improve or create and have that range readily available.&#160; Then when someone asks, you can present your numbers with a range for each item and they can make up their own mind at what is fair.&#160; </p>
<p>Unfortunately, most companies view IT/Development as a &#8216;necessary evil&#8217; that doesn&#8217;t produce anything.&#160; These numbers probably aren&#8217;t going to change their minds, but you should at least be able to keep the focus on &#8216;necessary&#8217; and off of &#8216;evil&#8217;.&#160; The irony is that just about everything work related you do potentially saves or makes the company money in some manner&#8230; everything except sitting around trying to calculate how much money you&#8217;ve saved them.</p>
]]></content:encoded>
			<wfw:commentRss>http://phelabaum.com/archive/2010/06/calculating-roi-on-performance-tuning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IN and NOT IN</title>
		<link>http://phelabaum.com/archive/2010/01/in-and-not-in/</link>
		<comments>http://phelabaum.com/archive/2010/01/in-and-not-in/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 14:03:35 +0000</pubDate>
		<dc:creator>Seth Phelabaum</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Common Problems]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://phelabaum.com/archive/2010/01/in-and-not-in/</guid>
		<description><![CDATA[One of the most common mistakes made in T-SQL is thinking that these behave identically.&#160; I&#8217;ve personally opened up a forum topic on it because I didn&#8217;t know what the difference was.&#160; This post will join a small army of other places on the net devoted to correcting this misunderstanding. They aren&#8217;t completely dissimilar; they [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most common mistakes made in T-SQL is thinking that these behave identically.&#160; I&#8217;ve personally opened up a forum topic on it because I didn&#8217;t know what the difference was.&#160; This post will join a small army of other places on the net devoted to correcting this misunderstanding. </p>
<p>They aren&#8217;t completely dissimilar; they behave exactly as you would expect them to&#8230; with the exception of NULL&#8217;s.&#160; Because nothing EQUALS NULL (Dependent upon settings, see below) the difference in the internal logic matters.&#160; Gail Shaw initially explained this to me when I asked the question on the forums and I wanted to use her explanation here, but I can’t seem to find it; so here&#8217;s my own version of an explanation: </p>
<p>When you use IN, you&#8217;re really saying &quot;WHERE myvalue = &#8216;A&#8217; OR myvalue = &#8216;B&#8217; OR myvalue = NULL&quot;    <br />Your NULLS won&#8217;t cause the entire statement to fail because it&#8217;s only an OR. </p>
<p>When you use NOT IN you&#8217;re really saying &#8216;WHERE myvalue &lt;&gt; &#8216;A&#8217; AND myvalue &lt;&gt; &#8216;B&#8217; AND myvalue &lt;&gt; NULL “    <br />This is where the problem arises.&#160; Since a NULL in SQL is an unknown value, you can&#8217;t test = or &lt;&gt; on it and you get no results.&#160; Without the NULL, you&#8217;d be fine. </p>
<p>Here&#8217;s a simple example to demonstrate. </p>
<pre class="csharpcode"><span class="kwrd">DECLARE</span> @T <span class="kwrd">TABLE</span>(
Val <span class="kwrd">varchar</span>(5)) 

<span class="kwrd">DECLARE</span> @T2 <span class="kwrd">TABLE</span>(
Val <span class="kwrd">varchar</span>(5)) 

INSERT <span class="kwrd">INTO</span> @T(Val)
<span class="kwrd">SELECT</span> <span class="str">'A'</span> <span class="kwrd">UNION</span> <span class="kwrd">ALL</span> <span class="kwrd">SELECT</span> <span class="str">'B'</span> <span class="kwrd">UNION</span> <span class="kwrd">ALL</span> <span class="kwrd">SELECT</span> <span class="str">'C'</span> <span class="kwrd">UNION</span> <span class="kwrd">ALL</span>
<span class="kwrd">SELECT</span> <span class="str">'D'</span> <span class="kwrd">UNION</span> <span class="kwrd">ALL</span> <span class="kwrd">SELECT</span> <span class="str">'E'</span> <span class="kwrd">UNION</span> <span class="kwrd">ALL</span> <span class="kwrd">SELECT</span> <span class="str">'F'</span> 

INSERT <span class="kwrd">INTO</span> @T2(Val)
<span class="kwrd">SELECT</span> <span class="str">'A'</span> <span class="kwrd">UNION</span> <span class="kwrd">ALL</span> <span class="kwrd">SELECT</span> <span class="str">'B'</span> <span class="kwrd">UNION</span> <span class="kwrd">ALL</span> <span class="kwrd">SELECT</span> <span class="str">'C'</span> <span class="kwrd">UNION</span> <span class="kwrd">ALL</span>
<span class="kwrd">SELECT</span> <span class="kwrd">NULL</span> 

<span class="kwrd">SET</span> ANSI_NULLS <span class="kwrd">ON</span>
<span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span> @T <span class="kwrd">WHERE</span> Val <span class="kwrd">IN</span> (<span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span> @T2)
<span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span> @T <span class="kwrd">WHERE</span> Val <span class="kwrd">NOT</span> <span class="kwrd">IN</span> (<span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span> @T2)
<span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span> @T <span class="kwrd">WHERE</span> Val <span class="kwrd">NOT</span> <span class="kwrd">IN</span> (<span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span> @T2 <span class="kwrd">WHERE</span> Val <span class="kwrd">IS</span> <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>) </pre>
<p>This issue is further complicated by the ANSI_NULLS setting.&#160; While I believe most people have this turned ON, the fact that it is an option introduces another variable into the mix.&#160; NOT IN will not fail in the same way if you have ANSI_NULLS set to OFF.&#160; (Try the above example again after changing ON to OFF)</p>
]]></content:encoded>
			<wfw:commentRss>http://phelabaum.com/archive/2010/01/in-and-not-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

