<?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>&#8235;Madeira &#187; נעם ברזיס&#8236;</title>	<atom:link href="http://www.madeira.co.il/author/noambresiz/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.madeira.co.il</link>
	<description>&#8235;SQL Server Services&#8236;</description>	<lastBuildDate>Sat, 19 May 2012 09:04:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>he</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&#8235;Update Statistics and the new TraceFlag 2371&#8236;</title>		<link>http://www.madeira.co.il/update-statistics-re-compilations-and-traceflag-2371/</link>
		<comments>http://www.madeira.co.il/update-statistics-re-compilations-and-traceflag-2371/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 23:11:06 +0000</pubDate>
		<dc:creator>&#8235;נעם ברזיס&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[כללי]]></category>
		<category><![CDATA[מקודמות]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=3748</guid>
		<description><![CDATA[&#8235;The new TraceFlag 2371 can be very effective if you have large tables, come and read all about it.&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/3748.gif&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr">What comes first &#8211; The Chicken or the Egg? What happens first – Update Statistics or Re-Compilations ?</p>
<h3 dir="ltr">The Statistics life cycle</h3>
<p dir="ltr">As a regular process of our DB life, data in our tables changes and hence statistics become less accurate. After a certain amount of changes (which I will discuss later in this post), SQL Server marks statistics to be non-valid.</p>
<p dir="ltr">This process marks the statistics as non-valid but doesn’t actually update them. Only when a query is compiled will SQL Server update the relevant statistics (if auto update statistics is on of course). After the statistics are updated, all the queries that rely on these statistics will be marked for re-compilation.</p>
<p dir="ltr">So actually the process is: </p>
<p dir="ltr">1. Many Changes (updates/ inserts/deletes) –&gt; Causes Non Valid Statistics </p>
<p dir="ltr">2. Query Compilation (happens Independently) –&gt; Causes Update Statistics –&gt; Causes All related queries to be re-compiled</p>
<p dir="ltr">&#160;</p>
<h3 dir="ltr">When are Statistics marked as non-valid</h3>
<p dir="ltr">After how many changes to the table are Statistics marked as non-valid?</p>
<p dir="ltr">After running the following <a href="http://www.madeira.co.il/wp-content/uploads/2012/01/AmountOfChangesForStatsAutoUpdate.sql" target="_blank">Script</a> you’ll find out that SQL Server marks statistics as non-valid if more than 20% of the rows were changed (counting changes only on columns related to the statistics).</p>
<p dir="ltr">&#160;</p>
<h3 dir="ltr">Trace Flag 2371</h3>
<p dir="ltr">20% of row changes sounds crazy high if the table has a lot of rows !</p>
<p dir="ltr">Consider for instance, a table containing data from the past 7 years. It would demand to wait a whole <b><u>1.4 year</u></b> of new data to have the statistics updated ! (assuming only inserts are done and same amount of inserts per year). So if you don’t update your statistics manually and have very large tables, you should have a close look at Trace Flag 2371. It actually changes the 20% threshold to be smaller according to the amount of rows in the table. The following chart shows the new thresholds:</p>
<p dir="ltr"><img src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-84-42-metablogapi/4370.clip_5F00_image002_5F00_thumb_5F00_64787B84.png" width="487" height="304" /></p>
<p dir="ltr">&#160;</p>
<p dir="ltr">The new Trace Flag is currently available on SQL Server 2008 R2 SP1 and on SQL Server 2012.</p>
<p dir="ltr">&#160;</p>
<p dir="ltr">I recommend reading 2 very interesting posts on Update Statistics:</p>
<p dir="ltr">1. <a href="http://sqlskills.com/BLOGS/KIMBERLY/category/Statistics.aspx" target="_blank">Filtered indexes and filtered stats might become seriously out-of-date</a> (<a href="http://www.sqlskills.com/blogs/Kimberly">Kimberly L. Tripp</a>)</p>
<p dir="ltr">2. <a href="http://blogs.msdn.com/b/saponsqlserver/archive/2011/09/07/changes-to-automatic-update-statistics-in-sql-server-traceflag-2371.aspx" target="_blank">Changes to automatic update statistics in SQL Server – traceflag 2371</a> (Juergen Thomas)</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/update-statistics-re-compilations-and-traceflag-2371/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8235;Pro and Cons of Parameter Sniffing&#8236;</title>		<link>http://www.madeira.co.il/pro-and-cons-of-parameter-sniffing-2/</link>
		<comments>http://www.madeira.co.il/pro-and-cons-of-parameter-sniffing-2/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 22:20:00 +0000</pubDate>
		<dc:creator>&#8235;נעם ברזיס&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[כללי]]></category>
		<category><![CDATA[מקודמות]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=3053</guid>
		<description><![CDATA[&#8235;Parameter Sniffing is all over, but you can't see it. Come and understand the pros and cons of this mechanism which can save you hours of performance tuning !&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/3053.gif&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr" align="left">Look at the following 3 scripts:
<pre dir="ltr" class="csharpcode"><span class="rem">-- 1. Hardcoded</span>
<span class="kwrd">SELECT</span>
    *
<span class="kwrd">FROM</span>
    Sales.Orders
<span class="kwrd">WHERE</span>
    DateAndTime &lt; <span class="str">'19900101'</span></pre>
<pre dir="ltr" class="csharpcode"><span class="rem"></span>&nbsp;</pre>
<pre dir="ltr" class="csharpcode"><span class="rem">-- 2. Variable</span>
<span class="kwrd">DECLARE</span> @FilterDate DATETIME = <span class="str">'19900101'</span>
<span class="kwrd">SELECT</span>
    *
<span class="kwrd">FROM</span>
    Sales.Orders
<span class="kwrd">WHERE</span>
    DateAndTime &lt; @FilterDate</pre>
<p dir="ltr">
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p>
<pre dir="ltr" class="csharpcode">
<span class="rem"></span></pre>
<pre dir="ltr" class="csharpcode"><span class="rem">-- 3. Stored Procedure</span>
<span class="kwrd">CREATE</span> <span class="kwrd">PROCEDURE</span> Sales.GetOrders
    @FilterDate DATETIME2(0)
<span class="kwrd">AS</span>

    <span class="kwrd">SELECT</span>
        *
    <span class="kwrd">FROM</span>
        Sales.Orders
    <span class="kwrd">WHERE</span>
        DateAndTime &lt; @FilterDate
<span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> Sales.GetOrders <span class="str">'19900101'</span></pre>
<p dir="ltr">&nbsp;</p>
<p dir="ltr">All three run the same query : The first uses a hard coded filter value, the second uses a variable, and the third uses a Stored Procedure.</p>
<p dir="ltr">Same logical process but they are compiled in a very different way leading to huge different performance outcomes.</p>
<h3 dir="ltr">What is parameter sniffing?</h3>
<p dir="ltr">When a query is compiled, the optimizer doesn’t know the value of variables. This is very important, so I’ll add some exclamation points !!!!!!&nbsp;
<p dir="ltr">For instance, in the following query:
<pre dir="ltr" class="csharpcode"><span class="rem">-- 2. Variable</span>
<span class="kwrd">DECLARE</span> @FilterDate DATETIME = <span class="str">'19900101'</span>
<span class="kwrd">SELECT</span>
    *
<span class="kwrd">FROM</span>
    Sales.Orders
<span class="kwrd">WHERE</span>
    DateAndTime &lt; @FilterDate</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p dir="ltr">the optimizer doesn’t know the value of @FilterDate. Only after compilation is finished and the execution plan is be executed, will SQL Server calculate the value of @FilterDate. </p>
<p dir="ltr">&nbsp;
<p dir="ltr">However, there are a few exclusions to the above rule (that the optimizer doesn’t know the value of variables) for instance: Stored Procedures, sp_executesql and a parameterized query.</p>
<p dir="ltr">In these special cases, SQL Server knows (<strong>sniffs</strong>) the values of the input <strong>parameters</strong> and uses these values when compiling the statements ! This process is called parameter sniffing. </p>
<p dir="ltr">For example, in the following query:
<pre dir="ltr" class="csharpcode"><span class="rem">-- Stored Procedure</span>
<span class="kwrd">CREATE</span> <span class="kwrd">PROCEDURE</span> Sales.GetOrders
    @FilterDate DATETIME2(0)
<span class="kwrd">AS</span>

    <span class="kwrd">SELECT</span>
        *
    <span class="kwrd">FROM</span>
        Sales.Orders
    <span class="kwrd">WHERE</span>
        DateAndTime &lt; @FilterDate
<span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> Sales.GetOrders <span class="str">'19900101'</span>
</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p dir="ltr"> the optimizer at compile time knows @FilterDate = '19900101'.</p>
<p dir="ltr">&nbsp;
<p dir="ltr">What happens if we run later on the Stored Procedure with a different input? For example:
<pre dir="ltr" class="csharpcode"><span class="kwrd">EXECUTE</span> Sales.GetOrders <span class="str">'20000101'</span></pre>
<p dir="ltr">This leads us to our second rule: </p>
<p dir="ltr">When parameter sniffing is applied, the same execution plan is used regardless of the input values. Therefore, the first run of a Stored Procedure is critical, the input parameters of the first run will dictate the values used at compile time and hence on the outcome execution plan which stays in cache for future run !! So in our case, SQL Server will use the same execution plan compiled for the first run and won’t create a new plan for the following runs.</p>
<h3 dir="ltr">Cons and Pros of Parameter sniffing:</h3>
<p dir="ltr"><b><u>Pro #1:</u></b></p>
<p dir="ltr">The obvious and most definite pro of parameter sniffing is that only one compilation is needed to serve a whole range of values – <u>we’re saving so many compilations!</u></p>
<p dir="ltr"><u></u>&nbsp;
<p dir="ltr"><b><u>Con #1:</u></b></p>
<p dir="ltr">That’s the con as well ! One compilation means one execution plan for any value passed. So we’re actually reusing the same execution plan <u>without optimizing it for that specific value</u>. Yes, in most cases it’s OK but sometimes that’s really bad!</p>
<p dir="ltr">Look at the following scenario:</p>
<p dir="ltr">Suppose the Orders table contains many orders from 2007 till 2011. The first run of the Stored Procedure (from above): Sales.GetOrders will dictate the execution plan. So let’s first run it with a very selective value (very few rows are returned):
<pre dir="ltr" class="csharpcode"><span class="kwrd">EXECUTE</span> Sales.GetOrders <span class="str">'20000101'</span></pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p dir="ltr">You can see in the Execution Plan that the optimizer estimated correctly that almost no rows would return.</p>
<p dir="ltr"><a href="http://www.madeira.co.il/wp-content/uploads/2012/01/Snif1.jpg" rel="wp-prettyPhoto[g3053]"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Snif1" border="0" alt="Snif1" src="http://www.madeira.co.il/wp-content/uploads/2012/01/Snif1_thumb.jpg" width="244" height="73"></a></p>
<p dir="ltr">However, when running the following:
<pre dir="ltr" class="csharpcode"><span class="kwrd">EXECUTE</span> Sales.GetOrders <span class="str">'20120101'</span></pre>
<p dir="ltr">The optimizer uses the same execution plan and therefore estimates miss correctly that 1 row would return. As you can see, the estimated number of rows is very different than the actual number of rows – causing the optimizer to use Lookup for many rows – a very destructive plan! </p>
<p dir="ltr"><a href="http://www.madeira.co.il/wp-content/uploads/2012/01/Snif2.jpg" rel="wp-prettyPhoto[g3053]"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Snif2" border="0" alt="Snif2" src="http://www.madeira.co.il/wp-content/uploads/2012/01/Snif2_thumb.jpg" width="244" height="70"></a></p>
<p dir="ltr"><b><u>Con #2:</u></b></p>
<p dir="ltr">When an input parameter value is changed inside the Stored Procedure, the optimizer isn’t aware of the change and refers to the original value prior to the change. Look at the following code:
<pre dir="ltr" class="csharpcode"><span class="kwrd">ALTER</span> <span class="kwrd">PROCEDURE</span> Sales.GetOrders
    @FilterDate DATETIME2(0)
<span class="kwrd">AS</span>

    <span class="kwrd">IF</span> (@FilterDate <span class="kwrd">IS</span> <span class="kwrd">NULL</span>)
        <span class="kwrd">SET</span> @FilterDate = SYSDATETIME()

    <span class="kwrd">SELECT</span>
        *
    <span class="kwrd">FROM</span>
        Sales.Orders
    <span class="kwrd">WHERE</span>
        DateAndTime &lt; @FilterDate
<span class="kwrd">GO</span>
<span class="kwrd">EXECUTE</span> Sales.GetOrders NULL</pre>
<p dir="ltr">At compile time, the optimizer isn’t aware of the change to @FilterDate. Therefore, when running the Stored Procedure with NULL, the optimizer compiles the SELECT statement evaluating @FilterDate to be NULL and not SYSDATETIME(). You can see in the Execution Plan, the optimizer estimates no rows to return although the whole table is returned.</p>
<p dir="ltr"><a href="http://www.madeira.co.il/wp-content/uploads/2012/01/Snif3.jpg" rel="wp-prettyPhoto[g3053]"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Snif3" border="0" alt="Snif3" src="http://www.madeira.co.il/wp-content/uploads/2012/01/Snif3_thumb.jpg" width="244" height="71"></a></p>
<p dir="ltr">Of course, there are many ways to surmount these cons, I’ll go over them in my next post. </p>
<p dir="ltr">Happy New Year !
<pre dir="ltr" class="csharpcode">&nbsp;</pre>
<p dir="ltr">
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p>
<p dir="ltr">
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style></p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/pro-and-cons-of-parameter-sniffing-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8235;Answer to the Quiz&#8236;</title>		<link>http://www.madeira.co.il/answer-to-the-quiz-sysdatetime-with-dateadd-reveals-an-error-in-estimated-number-of-rows/</link>
		<comments>http://www.madeira.co.il/answer-to-the-quiz-sysdatetime-with-dateadd-reveals-an-error-in-estimated-number-of-rows/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 21:43:02 +0000</pubDate>
		<dc:creator>&#8235;נעם ברזיס&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[DATEADD]]></category>
		<category><![CDATA[Estimated Number of Rows]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[SYSDATETIME]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=2154</guid>
		<description><![CDATA[&#8235;Find the answer to the Quiz why SYSDATETIME with DATEADD reveals an error in Estimated Number of Rows&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/2154.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr">Hi Everybody,</p>
<p dir="ltr">Congratulation to Yair Gutman who won a free ticket to the <a href="http://madeira.co.il/advanced-programming-in-sql-server-2008r2/" target="_blank"><span style="color: #0000ff;">Advanced Programming in SQL Server 2008 R2</span></a> Course !</p>
<p dir="ltr">Here’s the answer to the <a href="http://www.madeira.co.il/win-a-free-ticket-to-the-advanced-programming-in-sql-server-2008-r2-course/" target="_blank"><span style="color: #0000ff;">Quiz</span></a>:</p>
<p dir="ltr">Let’s first analyze the query without DATEADD:</p>
<div dir="ltr">
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">SELECT</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Orders.Id ,</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Orders.DateAndTime ,</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  OrderStatusId</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">FROM</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Sales.Orders <span style="color: #0000ff;">AS</span> Orders</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">WHERE</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Orders.DateAndTime &gt; SYSDATETIME()</pre>
<p><!--CRLF--></p>
</div>
</div>
</div>
<p dir="ltr">Since SYSDATETIME is a known value at compile time, the estimated number of rows is correct.</p>
<p dir="ltr">Let’s analyze the effect of DATEADD on a fixed expression:</p>
<div dir="ltr">
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; height: 150px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">SELECT</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Orders.Id ,</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Orders.DateAndTime ,</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  OrderStatusId</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">FROM</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Sales.Orders <span style="color: #0000ff;">AS</span> Orders</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">WHERE</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Orders.DateAndTime &gt; DATEADD (<span style="color: #0000ff;">YEAR</span> , -2 , <span style="color: #006080;">'20110801 22:47'</span>)</pre>
<p><!--CRLF--></p>
</div>
</div>
</div>
<p dir="ltr">You can see again that SQL Server calculates correctly the value of the DATEADD and thus estimates correctly the amount of rows.</p>
<p dir="ltr">However, when DATEADD is combined with SYSDATETIME(), as in the Quiz, SQL Server has a bug and estimates this expression to be SYSDATETIME() and ignores the DATEADD. This bug isn’t applied when GETDATE() is used.</p>
<p dir="ltr">If you need the DATETIME2 precision, a workaround this bug can be achieved by first calculating the value of the DATEADD function and then running the query with a Dynamic execution, here’s an example:</p>
<div dir="ltr">
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 103.14%; font-family: 'Courier New', courier, monospace; direction: ltr; height: 248px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">DECLARE</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    @ThresholdDate DATETIME2 = DATEADD (<span style="color: #0000ff;">YEAR</span> , -2 , SYSDATETIME())</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> <span style="color: #0000ff;">EXECUTE</span> sp_executesql N<span style="color: #006080;">'</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 89.8%; font-family: 'Courier New', courier, monospace; direction: ltr; height: 16px; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    SELECT</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Orders.Id ,</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Orders.DateAndTime ,</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      OrderStatusId</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    FROM</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Sales.Orders AS Orders</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    WHERE</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Orders.DateAndTime &gt; @ThresholdDate', N<span style="color: #006080;">'@ThresholdDate DATETIME2'</span>, @ThresholdDate</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
</div>
</div>
</div>
<p dir="ltr">As a result of our Quiz, Erland Sommarskog, has added the bug to connect:</p>
<p dir="ltr"><a href="https://connect.microsoft.com/SQLServer/feedback/details/685903/incorrect-estimate-when-sysdatetime-appear-in-a-dateadd-expression">https://connect.microsoft.com/SQLServer/feedback/details/685903/incorrect-estimate-when-sysdatetime-appear-in-a-dateadd-expression</a></p>
<p dir="ltr">Please vote, so Microsoft quickly fixes it!</p>
<p dir="ltr">I would like to thank <a href="http://www.madeira.co.il/author/guyglantser/">Guy Glantser</a> and Haim Fishner for their great contribution in finding this bug !</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/answer-to-the-quiz-sysdatetime-with-dateadd-reveals-an-error-in-estimated-number-of-rows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8235;Win a Ticket to the &quot;Advanced Programming&quot; Course&#8236;</title>		<link>http://www.madeira.co.il/win-a-free-ticket-to-the-advanced-programming-in-sql-server-2008-r2-course/</link>
		<comments>http://www.madeira.co.il/win-a-free-ticket-to-the-advanced-programming-in-sql-server-2008-r2-course/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 13:56:10 +0000</pubDate>
		<dc:creator>&#8235;נעם ברזיס&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[DATEADD]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[GETDATE]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SYSDATETIME]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=2044</guid>
		<description><![CDATA[&#8235;Here is an interesting "advanced programming" puzzle. The first one to solve the puzzle will win a free ticket to the course&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/2044.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr">We are opening another class of the &quot;Advanced Programming in SQL Server 2008 R2" course on 28/08. You can find all the details <a href="http://madeira.co.il/advanced-programming-in-sql-server-2008r2/"><span style="color: #0000ff;">here</span></a>.</p>
<p dir="ltr">Here is an interesting &quot;advanced programming&quot; puzzle. The first one to solve the puzzle will win a free ticket to the course.</p>
<p dir="ltr">Are you ready? Let's go…</p>
<p dir="ltr">Let’s first create a table and populate some data in it:</p>
<pre dir="ltr"><span style="color: #0000ff;">CREATE SCHEMA</span>
 Sales;
<span style="color: #0000ff;"> GO</span>
<span style="color: #0000ff;">CREATE TABLE</span>
 Sales.Orders
<span style="color: #999999;"> (</span>
 Id              <span style="color: #0000ff;">INT            <span style="color: #999999;"> </span></span><span style="color: #999999;">NOT NULL</span>   <span style="color: #0000ff;">IDENTITY</span><span style="color: #999999;">(</span>1,1<span style="color: #999999;">)</span> ,
 DateAndTime     <span style="color: #0000ff;">DATETIME2</span><span style="color: #999999;">(</span>7<span style="color: #999999;">)</span>    <span style="color: #999999;">NOT NULL</span> ,
 OrderStatusId   <span style="color: #0000ff;">TINYINT         </span><span style="color: #999999;">NOT NULL</span> ,
<span style="color: #0000ff;">CONSTRAINT</span>
 pk_Orders_nc_Id
<span style="color: #0000ff;"> PRIMARY KEY NONCLUSTERED</span>
 <span style="color: #999999;">(</span>Id <span style="color: #0000ff;">ASC</span><span style="color: #999999;">)</span>
 <span style="color: #999999;">)</span>
 <span style="color: #0000ff;">GO</span>
<span style="color: #0000ff;">CREATE NONCLUSTERED INDEX</span>
 ix_Orders_nc_nu_DateAndTime
 <span style="color: #0000ff;">ON</span>
 Sales.Orders <span style="color: #999999;">(</span>DateAndTime <span style="color: #0000ff;">ASC</span><span style="color: #999999;">)</span>;
 <span style="color: #0000ff;">GO</span>
<span style="color: #0000ff;">INSERT INTO</span>
 Sales.Orders <span style="color: #0000ff;">WITH </span><span style="color: #999999;">(</span><span style="color: #0000ff;">TABLOCK</span><span style="color: #999999;">)</span>
 <span style="color: #999999;">(</span>
 DateAndTime,
 OrderStatusId
 <span style="color: #999999;">)</span>
<span style="color: #0000ff;"> SELECT TOP</span> <span style="color: #999999;">(</span>10000<span style="color: #999999;">)</span>
 DateAndTime     <span style="color: #999999;">=</span> <span style="color: #ff00ff;">DATEADD</span> <span style="color: #999999;">(</span><span style="color: #0000ff;">MINUTE </span><span style="color: #999999;">, -</span> <span style="color: #ff00ff;">ABS </span><span style="color: #999999;">(</span><span style="color: #ff00ff;">CHECKSUM </span><span style="color: #999999;">(</span><span style="color: #ff00ff;">NEWID </span><span style="color: #999999;">())) % (</span>60 <span style="color: #999999;">*</span> 24 <span style="color: #999999;">*</span> 365 <span style="color: #999999;">*</span> 5<span style="color: #999999;">) , </span><span style="color: #ff00ff;">SYSDATETIME </span><span style="color: #999999;">()),</span>
 OrderStatusId   <span style="color: #999999;">=</span> <span style="color: #ff00ff;">ABS</span> <span style="color: #999999;">(</span><span style="color: #ff00ff;">CHECKSUM </span><span style="color: #999999;">(</span><span style="color: #ff00ff;">NEWID </span><span style="color: #999999;">())) % <span style="color: #333333;">8</span> + <span style="color: #333333;">1</span></span>
 <span style="color: #0000ff;">FROM</span>
<span style="color: #008000;"> sys.all_columns</span> t1
<span style="color: #999999;"> CROSS JOIN</span>
<span style="color: #008000;"> sys.all_columns</span> t2
<span style="color: #0000ff;"> ORDER BY</span>
 <span style="color: #ff00ff;">NEWID </span><span style="color: #999999;">()</span> <span style="color: #0000ff;">ASC</span>;
 <span style="color: #0000ff;">GO</span></pre>
<p dir="ltr">Let’s do a very common task as returning a subset of the data filtered according to the date. In these 2 examples I selected all the rows from the past 2 years. The only difference between the two SELECT statements is that the first uses SYSDATETIME whereas the second uses GETDATE.</p>
<pre dir="ltr"><span style="color: #0000ff;">SELECT
</span> Orders<span style="color: #999999;">.</span>Id <span style="color: #999999;">,</span>
 Orders<span style="color: #999999;">.</span>DateAndTime <span style="color: #999999;">,</span>
 OrderStatusId
<span style="color: #0000ff;"> FROM
</span> Sales<span style="color: #999999;">.</span>Orders <span style="color: #0000ff;">AS</span> Orders
<span style="color: #0000ff;"> WHERE
</span> Orders<span style="color: #999999;">.</span>DateAndTime <span style="color: #999999;">&gt;</span> <span style="color: #ff00ff;">DATEADD </span><span style="color: #999999;">(</span><span style="color: #ff00ff;">YEAR </span><span style="color: #999999;">,</span> -2 <span style="color: #999999;">,</span> <span style="color: #ff00ff;">SYSDATETIME </span><span style="color: #999999;">())</span><span style="color: #999999;">;</span>
<span style="color: #0000ff;"> GO
</span><span style="color: #0000ff;">SELECT
</span> Orders<span style="color: #999999;">.</span>Id <span style="color: #999999;">,</span>
 Orders<span style="color: #999999;">.</span>DateAndTime <span style="color: #999999;">,</span>
 OrderStatusId
 <span style="color: #0000ff;">FROM</span>
 Sales<span style="color: #999999;">.</span>Orders <span style="color: #0000ff;">AS </span>Orders
 <span style="color: #0000ff;">WHERE</span>
 Orders<span style="color: #999999;">.</span>DateAndTime <span style="color: #999999;">&gt;</span> <span style="color: #ff00ff;">DATEADD</span> <span style="color: #999999;">(</span><span style="color: #ff00ff;">YEAR </span><span style="color: #999999;">,</span> -2 <span style="color: #999999;">,</span> <span style="color: #ff00ff;">GETDATE </span><span style="color: #999999;">());</span>
 <span style="color: #0000ff;">GO</span></pre>
<p dir="ltr">Now check out the actual execution plan for these two statements. The optimizer estimates the first query to return only <strong><span style="text-decoration: underline;">one row</span></strong>:</p>
<p dir="ltr"><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/one-row.png" rel="wp-prettyPhoto[g2044]"><img class="alignnone size-thumbnail wp-image-2048" title="one row" src="http://www.madeira.co.il/wp-content/uploads/2011/08/one-row-150x150.png" alt="" width="150" height="150" /></a></p>
<p dir="ltr">While in the second query, the optimizer has no problem estimating a very close amount to the actual number of rows:</p>
<p dir="ltr"><a href="http://www.madeira.co.il/wp-content/uploads/2011/08/number-of-rows.png" rel="wp-prettyPhoto[g2044]"><img class="alignnone size-thumbnail wp-image-2049" title="number of rows" src="http://www.madeira.co.il/wp-content/uploads/2011/08/number-of-rows-150x150.png" alt="" width="150" height="150" /></a></p>
<p dir="ltr">The question is: why the hell is there a difference between the estimated number of rows in the two statements?</p>
<p dir="ltr">You are invited to send me your answers either by replying to this post or by emailing to (noam AT madeira.co.il). The first one to send the correct answer will win a free ticket to our <a href="http://madeira.co.il/advanced-programming-in-sql-server-2008r2/"><span style="color: #0000ff;">Advanced Programming in SQL Server 2008 R2 course</span></a>. In the course we are going to solve this puzzle as well as many other interesting programming techniques.</p>
<p dir="ltr">Good luck!</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/win-a-free-ticket-to-the-advanced-programming-in-sql-server-2008-r2-course/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>&#8235;Parameterization- כל מה שרציתם לדעת ולא העזתם לשאול&#8236;</title>		<link>http://www.madeira.co.il/parameterization-all-you-need-to-know/</link>
		<comments>http://www.madeira.co.il/parameterization-all-you-need-to-know/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 06:18:27 +0000</pubDate>
		<dc:creator>&#8235;נעם ברזיס&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[ADO]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[Optimizer]]></category>
		<category><![CDATA[Parameterization]]></category>
		<category><![CDATA[Plan Guide]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=1362</guid>
		<description><![CDATA[&#8235;תרחיש פופולרי מאוד מתקיים כשאותה השאילתא מורצת פעמים רבות עם ערכים שונים וה- Query Optimizer  לא מזהה שמדובר באותו מבנה, ומקמפל כל שאילתא מחדש.  כל מה שרציתם לדעת על החלופה כבר נמצא בפנים&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/1362.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="rtl">לא מכבר, נתבקשנו על ידי לקוח לערוך בדיקה מקיפה של ה Database-ים שברשותו. המטרה העיקרית של הבדיקה הייתה לזהות קונפיגורציות בשרת שאינן אופטימליות, ובכך להביא לשיפור ביצועים משמעותי במערכת. כחלק מהבדיקה עברנו על השאילתות הנמצאות ב Query Plan Cache , ולהלן חלק מהשאילתות שנשלפו: </p>
<table dir="rtl" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="400" valign="top">
<p dir="ltr">Query Text           </p>
</td>
<td width="121" valign="top">
<p dir="ltr">Execution Count           </p>
</td>
</tr>
<tr>
<td width="400" valign="top">
<pre dir="ltr"><span style="color: #0000ff;">SELECT</span> ClientId
<span style="color: #0000ff;">FROM</span> clients
<span style="color: #0000ff;">WHERE</span> <span style="color: #808080;">(</span>StateId <span style="color: #808080;">=</span> 2<span style="color: #808080;">) and (</span>TransactionId <span style="color: #808080;">=</span> 5<span style="color: #808080;">)</span></pre>
</td>
<td width="121" valign="top">
<p dir="ltr">1           </p>
</td>
</tr>
<tr>
<td width="400" valign="top">
<pre dir="ltr"><span style="color: #0000ff;">SELECT</span> ClientId
<span style="color: #0000ff;">FROM</span> clients
<span style="color: #0000ff;">WHERE</span> <span style="color: #808080;">(</span>StateId <span style="color: #808080;">=</span> 2<span style="color: #808080;">) and (</span>TransactionId <span style="color: #808080;">=</span> 6<span style="color: #808080;">)</span></pre>
</td>
<td width="121" valign="top">
<p dir="ltr">1           </p>
</td>
</tr>
<tr>
<td width="400" valign="top">
<pre dir="ltr"><span style="color: #0000ff;">SELECT</span> ClientId
<span style="color: #0000ff;">FROM</span> clients
<span style="color: #0000ff;">WHERE</span> <span style="color: #808080;">(</span>StateId <span style="color: #808080;">=</span> 2<span style="color: #808080;">) and (</span>TransactionId <span style="color: #808080;">=</span> 7<span style="color: #808080;">)</span></pre>
</td>
<td width="121" valign="top">
<p dir="ltr">1           </p>
</td>
</tr>
<tr>
<td width="400" valign="top">
<pre dir="ltr"><span style="color: #0000ff;">SELECT</span> ClientId
<span style="color: #0000ff;">FROM</span> clients
<span style="color: #0000ff;">WHERE</span> <span style="color: #808080;">(</span>StateId <span style="color: #808080;">=</span> 2<span style="color: #808080;">) and (</span>TransactionId <span style="color: #808080;">=</span> 8<span style="color: #808080;">)</span></pre>
</td>
<td width="121" valign="top">
<p dir="ltr">1           </p>
</td>
</tr>
</tbody>
</table>
<p dir="rtl">
<p dir="rtl">    </p>
<p dir="rtl">זהו תרחיש פופולרי מאוד.  אותה השאילתא מורצת פעמים רבות עם ערכים שונים.  כפי שניתן לראות בדוגמא, ה- Query Optimizer  לא מזהה שמדובר באותו מבנה שאילתה ולכן מקמפל כל שאילתא מחדש.  אולם, קיימת חלופה ובה ה Query Optimizer  ממיר את הערכים לפרמטרים, ובכך השאילתא הופכת לכללית ואין צורך לקמפל אותה כל פעם מחדש. חלופה זו נקראית  Parameterization, שכן הערכים מוחלפים בפרמטרים.  במקרה שבדוגמא השאילתא הכללית נראתה כך:           </p>
<pre dir="ltr"><span style="color: #0000ff;">DECLARE @a, @b int;</span></pre>
<pre dir="ltr"><span style="color: #0000ff;">SELECT</span> ClientId
<span style="color: #0000ff;">FROM</span> clients
<span style="color: #0000ff;">WHERE</span> <span style="color: #808080;">(</span>StateId <span style="color: #808080;">= @a) and (</span>TransactionId = @b<span style="color: #808080;">)</span><span style="color: #808080;">;</span></pre>
<p>  את הפוסט הנוכחי אחלק, כמו כל דבר בצבא <img src='http://www.madeira.co.il/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , לשלושה חלקים:           </p>
<ol>
<li>דיון קצר אודות שתי החלופות: קימפול מחדש לכל שאילתא בנפרד אל מול  Parameterization.</li>
<li>הגדרות Parameterization ב Database &#8211; יתרונות וחסרונות של כל אחת מהאופציות.</li>
<li>לבסוף, אחשוף דרכים לקביעה פרטנית של הגדרת הפרמטרזיציה לשאילתא מסוימת אשר נרצה שלא תפעל לפי ההגדרה ב Database.     </li>
</ol>
<p><span style="text-decoration: underline;">Parameterization</span><span style="text-decoration: underline;"> – בעד ונגד</span>           </p>
<p dir="rtl">במבט ראשון, נראה כי פרמטריזציה רק יכולה להועיל ולהטיב עם ביצועי המערכת, שכן עבור שאילתות בעלות מבנה זהה, מתבצע קימפול אחד במקום קימפול מחדש עבור כל שאילתא בנפרד. אולם, עלינו להבין את ההשלכות של פרמטריזציה לפני שנקבע מסקנות פזיזות אלו. קימפול השאילתא משמעו גם קביעת Execution Plan. האם באמת ה- Plan שנקבע עבור שאילתא בעלת פרמטר הוא בהכרח הטוב ביותר עבור כל הערכים של הפרמטר?           </p>
<p dir="rtl">למעשה, קיימים מצבים בהם ה- Execution Plan האופטימלי משתנה על פי הערכים שבשאילתא, להלן מספר דוגמאות:           </p>
<ol>
<li>מקרה בו עבור ערך מסוים של השאילתא, ה- Execution Plan  האופטימלי ישתמש ב- Indexed View אשר כלל לא מכיל את שאר הערכים עליהם אנו מבצעים את השאילתא.</li>
<li>שאילתא על טבלה בעלת Partitions גם יכולה להניב Execution Plan מאוד שונה עבור ערכים הנמצאים ב Partitionים שונים.</li>
<li>בנוסף, ייתכן מצב בו ערך מסוים של השאילתא מחזיר כמות קטנה של רשומות וה-Query Optimizer יעדיף שלא להשתמש ב Index, ועבור ערך אחר מוחזר אוסף גדול של רשומות אשר עבורו עדיף להשתמש ב Index.</li>
<li>כמובן שגם במצב של Filtered Index ה Execution Plan עלול להיות שונה מאוד פר ערך הפרמטר.</li>
</ol>
<p><span style="text-decoration: underline;">הגדרת </span><span style="text-decoration: underline;">Parameterization</span><span style="text-decoration: underline;"> ב </span><span style="text-decoration: underline;">Database</span>           </p>
<p dir="rtl">כפי שראינו, לא תמיד נרצה לבצע פרמטריזציה של השאילתות ועל כן קיימות שתי רמות של פרמטריזציה אשר ניתן לבחור מהן בDatabase . יש לציין שלא ניתן לבטל לחלוטין שימוש בפרמטריזציה. שתי האופציות הן:           </p>
<ol>
<li>Simple Parameterization – זוהי ההגדרה הדיפולטיווית בעת יצירת Database. הרעיון הוא לבצע פרמטריזציה לשאילתות כל עוד מובטח שבחירת ה Execution Plan לא נפגעת כתוצאה מהפרמטריזציה. בנוסף, התנאים לכך שתתקיים פרמטריזציה הם:</li>
<li>Forced Parameterization – כפי שניתן לראות, התנאים בהם מתקיימת פרמטריזציה תחת Simple Parameterization מחמירים מאוד, ולמעשה מעט שאילתות מקיימות תנאים אלו. לכן קיימת אופציה של Forced Parameterization אשר רחבה הרבה יותר ומכסה הרבה יותר שאילתות, אך מאידך החיסרון שבה הינו האפשרות שייבחר Plan מוצלח פחות עקב הפרמטריזציה. לכן חשוב מאוד לבדוק ששינוי הקונפיגורציה מ Simple ל Forced אכן מיטיב עם המערכת. גם ב Forced Parameterization יש תנאים בהם הפרמטריזציה לא מתקיימת, את הרשימה של תנאים אלו ניתן למצוא ב: <a href="http://technet.microsoft.com/en-us/library/ms175037.aspx">http://technet.microsoft.com/en-us/library/ms175037.aspx</a></li>
</ol>
<table border="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td valign="top">
<ul dir="ltr">
<li dir="ltr">Single Table – No JOINs</li>
<li dir="ltr">No IN clause</li>
<li dir="ltr">No UNION</li>
<li>No SELECT INTO</li>
<li>No Query Hints</li>
<li>No DISTINCT or TOP</li>
<li>No full-text, linked servers or table variables</li>
</ul>
</td>
<td valign="top">
<ul dir="ltr">
<li>No sub-queries</li>
<li>No GROUP BY</li>
<li>No &lt;&gt; in WHERE clause</li>
<li>No functions</li>
<li>No DELETE or UPDATE with FROM clause</li>
<li>Parameter values can’t affect plan</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p dir="rtl">
<p dir="rtl">
<p dir="rtl">
<p dir="rtl">
<p dir="rtl">
<p dir="rtl">
<div dir="rtl">
<p dir="rtl">באופן כללי מומלץ להגדיר Simple Parameterization ולדאוג באופן פרטני לשאילתות בעיתיות שתופעל עבורן פרמטריזציה (כפי שיוסבר בהמשך).  קיימים מספר Performance Counters אשר יכולים לרמוז על צורך בפרמטריזציה של שאילתות. לדוגמא, היחס שבין שני ה counters הללו נותן את אחוז השאילתות אשר עברו Parameterization.           </p>
<p dir="ltr">SQLServer : SQL Statistics: Auto-Param Attempts/Sec<br />
SQLServer : SQL Statistics: Batch Request / Sec          </p>
<p dir="rtl">בנוסף תוכלו לבחון את השאילתות ב Query Plan Cache ולראות האם יש צורך בהגדרת פרמטריזציה רחבה יותר.         </p>
<p dir="rtl"><span style="text-decoration: underline;">הגדרת </span><span style="text-decoration: underline;">Parameterization</span><span style="text-decoration: underline;"> לשאילתא בודדת (אם רוצים התנהגות שונה ממה שמוגדר ב </span><span style="text-decoration: underline;">database</span><span style="text-decoration: underline;">)</span>          </p>
<p dir="rtl">1.  פרמטריזציה דרך שימוש ב Plan Guide:<br />
ניתן להגדיר באיזה פרמטריזציה  (simple \ forced) להשתמש עבור שאילתא מסוימת, ללא קשר להגדרה ב Database. לשם כך יש שני שלבים שעליכם לבצע. ראשית, חילוץ ה- Query Template של השאילתא, לדוגמא:         </p>
<pre dir="ltr"><span style="color: #0000ff;">DECLARE </span>@statement <span style="color: #0000ff;">nvarchar</span><span style="color: #808080;">(</span><span style="color: #ff00ff;">max</span><span style="color: #808080;">);</span>
<span style="color: #0000ff;">DECLARE</span> @parameters <span style="color: #0000ff;">nvarchar</span><span style="color: #808080;">(</span><span style="color: #ff00ff;">max</span><span style="color: #808080;">);</span></pre>
<pre dir="ltr"><span style="color: #0000ff;">EXEC</span> <span style="color: #800000;">sp_get_query_template</span>
<span style="color: #ff0000;">N'SELECT ClientId FROM clients WHERE (StateId = 2) and (TransactionId = 8)',
  </span>             @statement <span style="color: #0000ff;">OUTPUT</span>,
                @parameters <span style="color: #0000ff;">OUTPUT</span><span style="color: #808080;">; </span>  </pre>
<p dir="rtl">    </p>
<p dir="rtl">(כמובן שעליכם לשנות את השאילתא הרשומה בדוגמא עם השאילתא שלכם)<br />
ושלב שני, הגדרת ה Plan Guide:   </p>
<p dir="rtl">    </p>
<p dir="rtl">    </p>
<p dir="rtl">
<pre dir="ltr"><span style="color: #0000ff;">EXEC </span><span style="color: #800000;">sp_create_plan_guide </span><span style="color: #ff0000;">N'ForceParameterizationPlanGuide'</span><span style="color: #808080;">, </span>
    @statement<span style="color: #808080;">, </span>
   <span style="color: #ff0000;"> N'TEMPLATE'</span><span style="color: #808080;">,</span>
    <span style="color: #808080;">NULL</span><span style="color: #808080;">,</span>
    @parameters<span style="color: #808080;">, </span>
   <span style="color: #ff0000;"> N'OPTION(PARAMETERIZATION FORCED)'</span><span style="color: #808080;">;</span>  </pre>
<p><span style="text-decoration: underline;">הערה:</span> ניתן באותה מידה גם להגדיר   PARAMETERIZATION SIMPLEעבור השאילתא שלכם.    </p>
<p dir="rtl">2.  פרמטריזציה דרך  ADO –<br />
למתכנתים שבינינו, או לאלה מאיתנו שיש דיבור עם המתכנתים שיושבים בחדר הסמוך, יש אפשרות להגדיר בקוד שהערכים בשאילתא יועברו כפרמטרים.<br />
להלן דוגמא פשוטה ב c# (לשפות אחרות ה Syntax טיפה שונה):   </p>
<pre dir="ltr"><span style="color: #33cccc;">SqlCommand</span> command = <span style="color: #0000ff;">new </span><span style="color: #33cccc;">SqlCommand</span>(<span style="color: #33cccc;">String</span>.Empty, connection);  </pre>
<pre dir="ltr"><span style="color: #008000;">// Instead of id = 4, use parameterization: id = @id  </span>
<span style="color: #0000ff;">string</span> query = <span style="color: #800000;">"SELECT Name, DateTaken FROM Test Where id = @id;"</span>;
command.CommandText = query</pre>
<pre dir="ltr"><span style="color: #008000;">// Enter value for parameter @id  </span>
command.Parameters.Add(<span style="color: #800000;">"@id"</span>, <span style="color: #33cccc;">SqlDbType</span>.Int).Value = 4;
command.ExecuteReader();</pre>
<p>         </p>
<p dir="rtl">       </p>
</div>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/parameterization-all-you-need-to-know/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8235;מה בין פסיכולוגיה לניהול מערכות מידע? חלק ב&#8236;</title>		<link>http://www.madeira.co.il/psychology-and-it-part2/</link>
		<comments>http://www.madeira.co.il/psychology-and-it-part2/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 10:48:38 +0000</pubDate>
		<dc:creator>&#8235;נעם ברזיס&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[Execution Plan]]></category>
		<category><![CDATA[Optimizer]]></category>
		<category><![CDATA[Problem Solving Techniques]]></category>
		<category><![CDATA[להיות DBA]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=1092</guid>
		<description><![CDATA[&#8235;כהנמן וטברסקי, שני חוקרים מאוד ידועים בפסיכולוגיה וכלכלה, קיבלו פרס נובל עבור עבודתם פורצת הדרך בתחום קבלת החלטות שאינן רציונליות.  המסקנות שלהם כראי לעבודתו של ה DBA&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/1092.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="rtl">כהנמן וטברסקי, שני חוקרים מאוד ידועים בפסיכולוגיה וכלכלה, קיבלו פרס נובל עבור עבודתם פורצת הדרך בתחום קבלת החלטות שאינן רציונליות. במחקר שלהם, בין היתר, הם מאפיינים מצבים בהם אנו, בני האדם, מקבלים החלטות דרך קיצורי דרך ומבלי שהתבססנו על כל הנתונים שבידינו, וכל זאת שלא במודע כמובן. הרעיון פשוט וכה גאוני: המוח שלנו קצר במשאבים (CPU, RAM) ועל כן קיימים מצבים בהם המוח מעדיף להסתמך על חלק מהמידע שברשותו תוך דגימה חלקית ועל בסיסה לקבל את ההחלטה. רגע, זה מזכיר לכם משהו מוכר? אה.. נכון, זה ממש דומה לתהליך בו ה Optimizer דוגם חלק מהמידע ועל בסיס כך בוחר את ה Execution Plan. אך על כך אפרט בפוסט אחר. הפעם, ברצוני להתמקד במה שהכי חשוב בתחום מערכות המידע, שהוא כמובן ה-DBA <img src='http://www.madeira.co.il/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   .</p>
<p dir="rtl">לעבודת המחקר של כהנמן וטברסקי גם השלכה חשובה עלינו. כאשר אנו באים לבחון פתרון לבעיה, פעמים רבות מבלי להיות מודעים, אנו עושים קיצורי אשר אמורים לעזור במציאת פתרון מהיר, אך לא בהכרח לפתרון הנכון! עקב קיצורי דרך אלו יכולים להווצר מצבים בהם שעות רבות מושקעות במאמץ רב למציאת הפתרון, אך לא בכיוון הנכון. כולכם בוודאי מכירים את התופעה, שעות של עבודה כשהפתרון בכלל נמצא במקום בו לא חיפשנו. אז מה עושים ? הנה כמה טיפים:</p>
<ol dir="rtl">
<li>
<div>תזכרו שהסיבה לקיצורי הדרך הינה חוסר במשאבים. אם תתנו למוח לנוח, אפילו לזמן קצר, תהיה באפשרותו לאגור כוחות לעבר מציאת כיוונים חדשים לפתרון הבעיה. לדוגמא, עשו הפסקת קפה, לכו לשירותים, תשלחו ס.מ.ס לאהובכם ותזכירו לו כמה הוא חשוב לכם (טוב, אולי נסחפתי קצת, זה לא מדור לייעוץ זוגי <img src='http://www.madeira.co.il/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). העיקר שהבנתם את הרעיון. המוח צריך מנוחה, תאמינו לי – זה עובד !</div>
</li>
<li>
<div>דבר נוסף שיכול לעזור מאוד הינו שיחה עם אדם בסביבה. כמובן ששיחה על הבעיה עצמה עשויה להניב רעיונות חדשים ואולי אפילו את הפתרון עצמו. אך גם שיחת חולין תוכל לעזור על ידי שיחרור משאבים ומנוחה למוח.</div>
</li>
<li>
<div>כתיבה או שרטוט של הבעיה. גם למוח מגבלה בכמות הזכרון, ובטח ובטח מגבלה בזכרון העבודה (לפי המחקרים, זהו הזיכרון אשר בעזרתו אנו עושים עיבוד מחשבתי, והוא מוגבל ב 5 עד 7 פריטים בלבד). לכן תעשו Download מהמוח לדף ובכך תאפשרו לשחרר מקום לנתונים נוספים שיעזרו בעיבוד ובקבלת ההחלטה.</div>
</li>
<li>
<div>במחקרם, כהנמן וטברסקי גם גילו כי הדגימה של המידע אינה מקרית (כפי שאולי היינו מצפים). קיימים מספר פרמטרים לפיהם המוח קובע איזה מידע לדגום. פרמטר מעניין הינו זמן. ככל שהאירוע קרה בזמן האחרון כך סיכויו להכנס ל pool  גבוהיים יותר. משמעות הדבר היא שאנחנו מאוד מושפעים מאירועים שקרו בימים האחרונים על דרכנו במציאת פתרון לבעיות וקבלת החלטות. לכן, תנסו לפשפש במוחיכם ולהיזכר מה קרה בימים האחרונים ולראות האם יכול להיות שאתם מושפעים מבעיה אחרת אשר חוסמת את מציאת הפתרון.</div>
</li>
</ol>
<p dir="rtl">ואם כל זה לא עזר לכם ועדיין לא מצאתם פתרון לבעיה, <a href="http://www.madeira.co.il/?page_id=119"><span style="color: #ff6600;">פנו</span></a> אלינו ל Madeira! אנו כקבוצת מומחים בעלי ניסיון רב, נוכל לעזור ולספק לכם את התשובות.</p>
<div><em> </em></div>
<p> </p>
<div><em> </em></div>
<p> </p>
<div><em> </em></div>
<p> </p>
<div><em></em></div>
<p> </p>
<p><em></p>
<div id="attachment_1096" class="wp-caption alignnone" style="width: 290px"><img class="size-full wp-image-1096" title="Nobel" src="http://www.madeira.co.il/wp-content/uploads/2010/02/Nobel.jpg" alt="כהנמן מקבל את פרס הנובל בשמו ובשם טברסקי ז&quot;ל" width="280" height="210" /><p class="wp-caption-text">כהנמן מקבל את פרס הנובל בשמו ובשם טברסקי ז&quot;ל</p></div>
<p dir="rtl"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></em></p>
<p dir="rtl"> </p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/psychology-and-it-part2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8235;Can a query performance be dependent on the client?&#8236;</title>		<link>http://www.madeira.co.il/can-a-query-performance-be-dependent-on-the-client/</link>
		<comments>http://www.madeira.co.il/can-a-query-performance-be-dependent-on-the-client/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 12:29:37 +0000</pubDate>
		<dc:creator>&#8235;נעם ברזיס&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[Management Studio]]></category>
		<category><![CDATA[Provider]]></category>
		<category><![CDATA[Session Settings]]></category>
		<category><![CDATA[שיפור ביצועים]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=938</guid>
		<description><![CDATA[&#8235;This question sounds really easy!  But before we start answering this question, I would like to share with you the scenario which led me to deal with this question.&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/938.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="ltr">This question sounds really easy! The query performance depends essentially on the execution plan, which in its turn isn't dependent on the client. Therefore, theoretically, running a query through two different clients (i.e. ASP.Net and SQL Server Management Studio) should reveal similar performances.</p>
<p dir="ltr">But before we start answering this question, I would like to share with you the scenario which led me to deal with this question. A client of ours asked for Madeira's help to deal with their very slow web site. We first used Profiler to identify the source of the problem. Our conclusions were clear but at the same time very confusing. The website (written in ASP.Net 2.0) called often a specific query which took almost a minute to return the data. However, running the same query directly through SQL Server Management Studio took only 15 seconds!</p>
<p dir="ltr">Let's try and analyze the different stages that lead from the client and until the Database engine returns the data in order to find the cause of our problem. As you all know clients don’t connect directly to the server, they use a provider to do so. Performance can change from one provider to another or even from two different versions of the same provider. Remember, for better resource management and performance, it's a good idea to use the latest versions of your provider. But yet, is it possible that two different clients running the same query and using the same provider would result with different performance?</p>
<p dir="ltr">You're right, the answer is yes! Let's continue and analyze the chain. The provider passes on the query to the Database Engine which verifies if a compiled version of the query residues in the memory. However, the process of which the Database Engine decides if it can use the compiled version is pretty complex. The motivation is of course to use the compiled version but the Engine must be sure the data returned is perfectly similar in both cases (compiled query and the current query). To do so, a set of criteria have to match in order to be sure the returned data is the same. Among those criteria, are the Session settings (ANSI_NULLS, ARITHABORT etc&#8230;) Thus, if a session runs a query with different session settings than the compiled version, the engine will have to recompile the query and maybe use a different execution plan and resulting with a different performance. This is exactly what happened in our case. SQL Server Management Studio has set by default ARITHABORT = 1 and ASP.Net has set ARITHABORT = 0. (for info on arithabort see: <a href="http://msdn.microsoft.com/en-us/library/aa259212(SQL.80).aspx">http://msdn.microsoft.com/en-us/library/aa259212(SQL.80).aspx</a>). All was left to do in order to fix the problem was to set ARITHABORT = 1 while calling the query through ASP.Net.</p>
<p dir="ltr">P.S<br />
You can check if ARITHABORT = 1 in SQL Server Management Studio's options (Query Execution &gt; SQL Server &gt; Advanced). In the current picture, you can see it's set to 1.</p>
<p dir="ltr"><a href="http://www.madeira.co.il/wp-content/uploads/2010/01/Managment-Studio-Options.jpg" rel="wp-prettyPhoto[g938]"><img class="alignnone size-medium wp-image-940" title="Managment Studio Options" src="http://www.madeira.co.il/wp-content/uploads/2010/01/Managment-Studio-Options-300x175.jpg" alt="Managment Studio Options" width="300" height="175" /></a></p>
<p>זקוקים להרחבה בנושא? <a href="http://www.madeira.co.il/?page_id=119">פנו אלינו</a> ונשמח לעזור</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/can-a-query-performance-be-dependent-on-the-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8235;מה בין פסיכולוגיה לניהול מערכות מידע?&#8236;</title>		<link>http://www.madeira.co.il/psychology-and-it-part1/</link>
		<comments>http://www.madeira.co.il/psychology-and-it-part1/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 17:38:22 +0000</pubDate>
		<dc:creator>&#8235;נעם ברזיס&#8236;</dc:creator>				<category><![CDATA[בלוגים]]></category>
		<category><![CDATA[מקודמות]]></category>
		<category><![CDATA[Data Types]]></category>
		<category><![CDATA[Data Warehouse]]></category>
		<category><![CDATA[OLAP]]></category>
		<category><![CDATA[OLTP]]></category>
		<category><![CDATA[להיות DBA]]></category>
		<category><![CDATA[שליפת נתונים]]></category>

		<guid isPermaLink="false">http://www.madeira.co.il/?p=334</guid>
		<description><![CDATA[&#8235;במבט ראשון השאלה מעוררת השתאות, אפילו תמיהה, כיצד ניתן לחבר בין נושאים כל כך שונים?  תתפלאו, הקשר חזק.  הנה כמה דוגמאות לכך..&#8236;]]></description>			<content:encoded><![CDATA[<div dir="rtl"><p><img src='http://www.madeira.co.il/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/wp-content/thumbnails/334.jpg&amp;w=214&amp;h=129&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p dir="rtl">במבט ראשון השאלה מעוררת השתאות, אפילו תמיהה, כיצד ניתן לחבר בין נושאים כל כך שונים? ברצוני לנסות ולשכנע אתכם כי אכן קיים קשר שכזה ובעבודתנו כמנהלי מערכות מידע, חשוב להתייחס אליו. בפוסט הנוכחי, אתייחס לשני היבטים שונים: קשרי ה &#8211; DBA עם סביבתו וניתוח הזיכרון האנושי במנוחים ידועים ממאגרי מידע. עם הזמן, אמשיך ואוסיף היבטים אחרים ושונים בקשר מעניין זה, אתם מוזמנים לבקר ולהתעדכן. </p>
<p dir="rtl"><span style="text-decoration: underline;">קשרי אנוש שבין ה </span><span style="text-decoration: underline;">DBA</span><span style="text-decoration: underline;"> לסביבתו</span></p>
<p dir="rtl">ציטוט ידוע של פרויד הינו &quot;אנו באים לעולם לבד, ועוזבים אותו לבד&quot;, אנו מנהלי מערכות המידע בטח ובטח שלא עובדים לבד. מסביבנו אנשים ממגוון רחב ביותר של תחומים; מנהלים בעלי רקע טכני ולפעמים לאו, מתכנתים, אנשי סיסטם ועוד ועוד.<br />
כאשר אנו באים לבחון בעיה טכנית, לא ניתן להתייחס בלעדית לפן הטכנולוגי. מאחורי כל בעיה קיים לקוח / משתמש אשר מוטרד מהבעיה ומחכה לעדכון. התקשורת עם הלקוח מורכבת תחילה מאפיון ברור של הבעיה והשלכותיה. מחקרים בפסיכולוגיה מזמן הראו כי חוסר אונים הינו מקור לפחד ולתסכול. במקרה דנן ניתן להבין מדוע לקוחות רבים חוששים ואף מתוסכלים כאשר עומדת בפניהם בעיה טכנית. תפקידנו אינו מסתכם במתן פתרון, אלא גם מורכב מליווי הלקוח תוך מתן הסבר מפורט למקור הבעיה, פתרונות אפשריים והצגת לוחות זמנים. אומנם, כל זה נשמע מאוד טריוויאלי אך לא מעט הם המקרים בהם אנשים טכניים לוקים בחסר כאשר מדובר במודעות לסביבתם ובכך אינם נותנים מענה כולל ללקוח.</p>
<p dir="rtl"><span style="text-decoration: underline;">זיכרון אנושי ומערכות מידע<br />
</span></p>
<p dir="rtl">נשמע אולי מפתיע, אך כבר מיליוני שנים שבני האדם מבצעים מחקר בתחום מערכות המידע. לשם הדיוק, המחקר התבצע ברמת הגנים שלנו ו/או על ידי גורם כל יכול עליון (כל אחד ואמונתו). ברור שכוונתי אינה למערכות מידע ממוחשבות, אלא למערכת הזיכרון הנמצאת במוח של כל אחד ואחד מאיתנו. אורגניזמים חיים מתמודדים בכל רגע נתון עם קלט עצום של מידע ולכן נוצרו פתרונות ומנגנונים מתוחכמים לקידוד, אגירה ושליפה של כמויות עצומות של מידע. אפרט מחקרים אשר שופכים מעט אור על מבנה המנגנון וצורת פעולתו.<br />
בדומה לסווג המוכר במערכות מידע ל OLTP, Data Warehouse ו OLAP קיים במוחנו סיווג לזיכרון סנסורי, לטווח קצר ולטווח הארוך. למשל, מטרת הזיכרון הסנסורי לתת מענה מהיר ביותר לקלט ראשוני של המידע. כמובן שקליטת המידע מבחוץ בהכרח מתבצעת באופן מהיר וללא איבוד של מידע. לצורך השעשוע, דמיונו כיצד היינו מתפקדים במקרה שבו ביצועי הזיכרון הסנסורי היו מדי פעם משתבשים (כפי שקורה לא פעם במערכות מחשוב).<br />
במוחנו קיים גם שימוש דומה ל Data Types. דהיינו, הזיכרון שלנו תומך בסוגי תכנים שונים. למשל: זיכרון סמנטי, אפיזודי,  זיכרון לכישורים מוטוריים, ועוד. חלוקה זו במוחנו עלולה לפעמים לייצור התנהגויות מוזרות אצל בני-אדם. לדוגמא, מקרה מפורסם של חולה בשם <a href="http://en.wikipedia.org/wiki/HM_(patient)">HM</a> אשר יכולת הזיכרון האפיזודי שלו נפגעה כתוצאה מתאונה, אך הזיכרון לכישורים מוטוריים לא נפגעה.  חוסר האיזון הזה יצר מצב שכאשר לימדו אותו לשחק שח הוא ידע לשחק למרות שלא זכר כלל שלימדו אותו.<br />
תופעה נוספת ומאוד מעניינת קשורה לשליפה א-סינכרונית. האם קרה לכם פעם שהשתדלתם מאוד להיזכר בשם של מכר ללא הצלחה, ולפתע מספר דקות מאוחר יותר השם קפץ לכם לראש ? אין זה במקרה שהשם לפתע הופיע במודע, הרי המוח המשיך להריץ את השליפה ברקע וכאשר התוצאה נמצאה, המידע הוחזר לחלקים המודעים של המוח.</p>
<p dir="rtl">לסיכום,<br />
המדע ממשיך למצוא מידע מרתק על מערכת הזיכרון האנושית. כולי תקווה שתחום מערכות המידע הממוחשבות יצליח בעתיד ללמוד להפיק מכך תועלת בבניית מערכות חכמות ועמידות יותר.</p>
</div>]]></content:encoded>			<wfw:commentRss>http://www.madeira.co.il/psychology-and-it-part1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

