<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Journey to SQL Authority with Pinal Dave &#187; SQL Performance</title>
	<atom:link href="http://blog.sqlauthority.com/category/sql-performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 01:30:19 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='blog.sqlauthority.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/08e35387c05b61340e885b1763a69d9f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Journey to SQL Authority with Pinal Dave &#187; SQL Performance</title>
		<link>http://blog.sqlauthority.com</link>
	</image>
			<item>
		<title>SQL SERVER &#8211; Understanding Table Hints with Examples</title>
		<link>http://blog.sqlauthority.com/2009/11/19/sql-server-understanding-table-hints-with-examples/</link>
		<comments>http://blog.sqlauthority.com/2009/11/19/sql-server-understanding-table-hints-with-examples/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 01:30:41 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7113</guid>
		<description><![CDATA[Introduction
Today we have a very interesting subject to look at. I tried to look for help online but have not found any other documentation besides what we have from the Book Online.
Let us try to understand what are the different kinds of hints available in SQL Server and how they are helpful.
What is a Hint?
Hints [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7113&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3 style="text-align:justify;">Introduction</h3>
<p style="text-align:justify;">Today we have a very interesting subject to look at. I tried to look for help online but have not found any other documentation besides what we have from the Book Online.</p>
<p style="text-align:justify;">Let us try to understand what are the different kinds of hints available in SQL Server and how they are helpful.</p>
<h3 style="text-align:justify;">What is a Hint?</h3>
<p style="text-align:justify;"><em>Hints </em> are options and strong suggestions specified for enforcement by the SQL Server query processor on DML statements. The hints override any execution plan the query optimizer might select for a query.</p>
<p style="text-align:justify;">Before we continue to explore this subject, we need to consider one very important fact and say some words of caution. SQL Server Query optimizer is a very smart tool and it makes a best selection of execution plan. Suggesting hints to the Query Optimizer should be attempted when absolutely necessary and by experienced developers who know exactly what they are doing (or in development as a way to experiment and learn).</p>
<p style="text-align:justify;">There are three different kinds of hints. Let us understand the basics of each of them separately.</p>
<h4 style="text-align:justify;">Join Hint</h4>
<p style="text-align:justify;">This hint is used when more than one table is used in a query. Two or more tables can be joined using different kinds of joins. This hint forces the type of join algorithm that is used. Joins can be used in <code>SELECT</code>, <code>UPDATE </code> and <code>DELETE </code> statements.</p>
<h4 style="text-align:justify;">Query Hint</h4>
<p style="text-align:justify;">This hint is used when certain kind of logic has to be applied to a whole query. Any hint used in the query is applied to the complete query, as opposed to part of it. There is no way to specify that only a certain part of a query should be used with the hint. After any query, the <code>OPTION </code> clause is specified to apply the logic to this query. A query always has any of the following statements: <code>SELECT</code>, <code>UPDATE</code>, <code>DELETE</code>, <code>INSERT </code> or <code>MERGE </code> (SQL 2K8); and this hint can be applied to all of them.</p>
<h4 style="text-align:justify;">Table Hint</h4>
<p style="text-align:justify;">This hint is used when certain kind of locking mechanism of tables has to be controlled. SQL Server query optimizer always puts the appropriate kind of lock on tables, when any of the Transact SQL operations <code>SELECT</code>, <code>UPDATE</code>, <code>DELETE</code>, <code>INSERT </code> or <code>MERGE </code> are used. There are certain cases when the developer knows when and where to override the default behavior of the locking algorithm and these hints are useful in those scenarios.</p>
<p style="text-align:justify;">Let us run the following simple query with different kinds of query hints and observe the actual execution plan. The analysis of execution plan is not part of this article and will be covered in future.</p>
<div id="highlighter_563028" style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">/* No Query Hint */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Production.Product </span><span style="color:blue;">AS </span><span style="color:black;">p<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">Sales.SalesOrderDetail </span><span style="color:blue;">AS </span><span style="color:black;">sod </span><span style="color:blue;">ON </span><span style="color:black;">p.ProductID </span><span style="color:blue;">= </span><span style="color:black;">sod.ProductID<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">Weight </span><span style="color:blue;">= </span><span style="color:black;">20.77<br />
GO<br />
</span><span style="color:green;">/* Merge Join Query Hint */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Production.Product </span><span style="color:blue;">AS </span><span style="color:black;">p<br />
</span><span style="color:blue;">INNER </span><span style="color:black;">MERGE </span><span style="color:blue;">JOIN </span><span style="color:black;">Sales.SalesOrderDetail </span><span style="color:blue;">AS </span><span style="color:black;">sod </span><span style="color:blue;">ON </span><span style="color:black;">p.ProductID </span><span style="color:blue;">= </span><span style="color:black;">sod.ProductID<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">Weight </span><span style="color:blue;">= </span><span style="color:black;">20.77<br />
GO<br />
</span><span style="color:green;">/* Hash Join Query Hint */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Production.Product </span><span style="color:blue;">AS </span><span style="color:black;">p<br />
</span><span style="color:blue;">INNER </span><span style="color:black;">HASH </span><span style="color:blue;">JOIN </span><span style="color:black;">Sales.SalesOrderDetail </span><span style="color:blue;">AS </span><span style="color:black;">sod </span><span style="color:blue;">ON </span><span style="color:black;">p.ProductID </span><span style="color:blue;">= </span><span style="color:black;">sod.ProductID<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">Weight </span><span style="color:blue;">= </span><span style="color:black;">20.77<br />
GO<br />
</span><span style="color:green;">/* Loop Join Query Hint */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Production.Product </span><span style="color:blue;">AS </span><span style="color:black;">p<br />
</span><span style="color:blue;">INNER </span><span style="color:black;">LOOP </span><span style="color:blue;">JOIN </span><span style="color:black;">Sales.SalesOrderDetail </span><span style="color:blue;">AS </span><span style="color:black;">sod </span><span style="color:blue;">ON </span><span style="color:black;">p.ProductID </span><span style="color:blue;">= </span><span style="color:black;">sod.ProductID<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">Weight </span><span style="color:blue;">= </span><span style="color:black;">20.77<br />
GO<br />
</span><span style="color:green;">/* Remote Join Query Hint */<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Production.Product </span><span style="color:blue;">AS </span><span style="color:black;">p<br />
</span><span style="color:blue;">INNER </span><span style="color:black;">REMOTE </span><span style="color:blue;">JOIN </span><span style="color:black;">Sales.SalesOrderDetail </span><span style="color:blue;">AS </span><span style="color:black;">sod </span><span style="color:blue;">ON </span><span style="color:black;">p.ProductID </span><span style="color:blue;">= </span><span style="color:black;">sod.ProductID<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">Weight </span><span style="color:blue;">= </span><span style="color:black;">20.77<br />
GO </span></code></div>
<p style="text-align:justify;">The above query will produce the following query execution plan.</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/sql-join.png" alt="" width="550" height="557" /></p>
<p style="text-align:justify;">In this article we will focus mainly on Join Hints. We will discuss other kinds of hints and their usage in a different article. There are a total of four kinds of join hints available.</p>
<h3 style="text-align:justify;">Loop Join</h3>
<p style="text-align:justify;">This join is also commonly known as <em>nested iteration</em>. This kind of join is composed by an outer loop and an inner loop. When the query runs for each row of the outer loop, the inner loop is executed completely. This join is effective only when the outer loop query is small and the inner loop query has all the proper optimizations applied. This join method is very useful with small transactions.</p>
<h3 style="text-align:justify;">Merge Join</h3>
<p style="text-align:justify;">This join has the unique requirement for tables involved in the operation to be sorted. This join keeps both of the tables sorted in parallel and compares each table row by row simultaneously with each other. It compares one row of the first table with one row of the second table. If they are equal, that row qualifies; otherwise, this join determines which row of each table has the lower value. Once the lowest value of the table is figured out, it moves on to next row of that table and compares that to the original row. This operation keeps going on until all rows from each table are completely examined. This operation can be very expensive when tables are not sorted and it’s required to sort them before they are joined. If tables have non clustered indexes over them and joins are using the same conditions, there are pretty good chances that this join performs better than other kinds of joins.</p>
<h3 style="text-align:justify;">Hash Join</h3>
<p style="text-align:justify;">This is the most complex of all the other joins. There are two major components of this kind of join &#8211; build query and probe query. First, a smaller table is assigned as build query and a hash table for the same is created. This hash table is compared with the probe table. This comparison of input table and probe table is done one row at a time. One row of the probe table is hashed and compared against the other row, and qualifying rows are checked.</p>
<p style="text-align:justify;">There are three different kinds of hash joins:  in-memory hash join, grace hash join, and recursive hash join. Let us look in more detail at these three kinds of joins.</p>
<h4 style="text-align:justify;">In-Memory Hash Join</h4>
<p style="text-align:justify;">This kind of hash join is used when tables are very small and a complete table can be hashed and loaded in memory.</p>
<h4 style="text-align:justify;">Grace Hash Join</h4>
<p style="text-align:justify;">This kind of hash join is used when tables are comparatively large and don’t fit in memory. Tables will be partitioned at input levels and processed in steps.</p>
<h4 style="text-align:justify;">Recursive Hash Join</h4>
<p style="text-align:justify;">This kind of join is used for complex tables and for tables which are very large and require multilevel of table partitions.</p>
<p style="text-align:justify;">SQL Server query optimizer is a smart tool and it knows when to use the right kind of join. When it comes to hash join, the query optimizer starts conservatively with in-memory hash join. If join is larger than in-memory it moves up to Grace hash join or Recursive hash join. Sometimes the optimizer makes a mistake in identifying a smaller table and it reverses the role of the build and probe table: this is called <em>role reversal</em>.</p>
<h4 style="text-align:justify;">Remote Join</h4>
<p style="text-align:justify;">This is least-used tabled join ever. There is no example for it given in Book On Line. Every Join has two tables associated with it: Left Table and Right Table. The join usually happens on the Left Table. When Remote close is used, joins are performed on the site of Right Join. This join can only be performed on INNER JOIN as in case of OUTER join there may be NULL values on the right table which makes concept of joining on right table logically incorrect.</p>
<h3 style="text-align:justify;">Summary</h3>
<p style="text-align:justify;">We have closely observed different kinds of Join Hints in this article. We will cover the remaining concepts in another article.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>), </strong><a href="http://dotnetslackers.com/articles/sql/SQL-Server-Understanding-Table-Hints-with-examples.aspx" target="_blank">DNS</a></p>
<p style="text-align:justify;">
Posted in Pinal Dave, SQL, SQL Authority, SQL Joins, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7113&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/19/sql-server-understanding-table-hints-with-examples/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/sql-join.png" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2005 2008 &#8211; Backup, Integrity Check and Index Optimization By Ola Hallengren</title>
		<link>http://blog.sqlauthority.com/2009/11/17/sql-server-2005-2008-backup-integrity-check-and-index-optimization-by-ola-hallengren/</link>
		<comments>http://blog.sqlauthority.com/2009/11/17/sql-server-2005-2008-backup-integrity-check-and-index-optimization-by-ola-hallengren/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 01:30:27 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[SQLAuthority Website Review]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7410</guid>
		<description><![CDATA[Script of Backup, Integrity Check and Index Optimization are the most important scripts for any developer. SQL Expert and true SQL enthusiast Ola Hallengren is known for his excellent scripts.
Please try it out and let me  know what you think. The documentation is available on http://ola.hallengren.com/Documentation.html and the script can be downloaded from http://ola.hallengren.com.
Here [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7410&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Script of Backup, Integrity Check and Index Optimization are the most important scripts for any developer. SQL Expert and true SQL enthusiast Ola Hallengren is known for his excellent scripts.</p>
<p style="text-align:justify;">Please try it out and let me  know what you think. The documentation is available on <a href="http://ola.hallengren.com/Documentation.html" target="_blank">http://ola.hallengren.com/Documentation.html</a> and the script can be downloaded from <a href="http://ola.hallengren.com/" target="_blank">http://ola.hallengren.com</a>.</p>
<p style="text-align:justify;">Here is brief documentation sent by Ola himself for his script in his own words.</p>
<h2 style="text-align:justify;">Backup Maintenance</h2>
<p style="text-align:justify;">I  think that most of you have experienced the error messages &#8220;BACKUP  LOG cannot be performed because there is no current database backup.&#8221;  and &#8220;Cannot perform a differential backup for database &#8220;&#8221;,  because a current database backup does not exist.&#8221;.</p>
<p style="text-align:justify;">This usually happens when you  have created a new database or when you have changed recovery model  of a database from Simple to Full.</p>
<p style="text-align:justify;">The consequence is that the  database is not getting backed up, until a full backup (or a differential  backup for the BACKUP LOG error message if that can be done) has been  performed. It will also create some noise in your monitoring system.</p>
<p style="text-align:justify;">The solution is to check if  a differential or transaction log backup can be performed before doing  the backup. This can be done by checking sys.master_files.differential_base_lsn  and sys.database_recovery_status.last_log_backup_lsn.</p>
<p style="text-align:justify;">The backup solution that I  have developed has a parameter called @ChangeBackupType.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">EXECUTE </span><span style="color:black;">dbo.DatabaseBackup </span><span style="color:#434343;">@Databases </span><span style="color:blue;">= </span><span style="color:red;">'USER_DATABASES'</span><span style="color:gray;">, </span><span style="color:#434343;">@Directory </span><span style="color:blue;">= </span><span style="color:red;">'C:\Backup'</span><span style="color:gray;">, </span><span style="color:#434343;">@BackupType </span><span style="color:blue;">= </span><span style="color:red;">'LOG'</span><span style="color:gray;">, </span><span style="color:#434343;">@ChangeBackupType </span><span style="color:blue;">= </span><span style="color:red;">'Y'</span></code></p>
<p style="text-align:justify;">If it&#8217;s a new database in Full  recovery model, the backup type for that database and job run will be  changed to full. If it&#8217;s a database that was newly changed to Full recovery  model, then the backup type for that database and job run will be changed  to differential. The next time the job runs a transaction log backup  will be performed for that database.</p>
<p style="text-align:justify;">New databases start getting  backed up quickly and no more &#8220;BACKUP LOG cannot be performed because  there is no current database backup.&#8221; and &#8220;Cannot perform  a differential backup for database &#8220;&#8221;, because a current database  backup does not exist.&#8221;.</p>
<h2 style="text-align:justify;">Index Optimization</h2>
<p style="text-align:justify;">The design idea is categorize all indexes based on their fragmentation level (High, Medium or Low) and whether there are columns with LOB (Large Object) data types. For each category you can define an action. The possible actions are to rebuild indexes online or offline, reorganize indexes, update statistics, reorganize indexes and update statistics or to do nothing.</p>
<p style="text-align:justify;">Here’s an example.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">EXECUTE </span><span style="color:black;">dbo.IndexOptimize<br />
</span><span style="color:#434343;">@Databases </span><span style="color:blue;">= </span><span style="color:red;">'USER_DATABASES'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationHigh_LOB </span><span style="color:blue;">= </span><span style="color:red;">'INDEX_REBUILD_OFFLINE'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationHigh_NonLOB </span><span style="color:blue;">= </span><span style="color:red;">'INDEX_REBUILD_ONLINE'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationMedium_LOB </span><span style="color:blue;">= </span><span style="color:red;">'INDEX_REORGANIZE'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationMedium_NonLOB </span><span style="color:blue;">= </span><span style="color:red;">'INDEX_REORGANIZE'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationLow_LOB </span><span style="color:blue;">= </span><span style="color:red;">'NOTHING'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationLow_NonLOB </span><span style="color:blue;">= </span><span style="color:red;">'NOTHING'</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationLevel1 </span><span style="color:blue;">= </span><span style="color:black;">5</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@FragmentationLevel2 </span><span style="color:blue;">= </span><span style="color:black;">30</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@PageCountLevel </span><span style="color:blue;">= </span><span style="color:black;">1000<br />
</span></code></p>
<p style="text-align:justify;">Indexes with a fragmentation above 30% are to be rebuilt, online if possible (no LOB columns), otherwise offline (LOB columns). Indexes with a fragmentation between 5% and 30% are to be reorganized. Indexes with a fragmentation below 5% or a size below 1000 pages are not to be touched.</p>
<p style="text-align:justify;">If you are using partitioning IndexOptimize has a parameter, @PartitionLevel to do index rebuilds and reorganizations on the partition level. If you prefer to do sort operations in tempdb you can do that with the parameter @SortInTempdb and if you would like to set a fillfactor you can do that with the parameter @FillFactor.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;text-align:justify;"><span style="font-family:Times New Roman;font-size:small;">Please try it out and let me  know what you think. The documentation is available on <a href="http://ola.hallengren.com/Documentation.html" target="_blank">http://ola.hallengren.com/Documentation.html</a> and the script can be downloaded from <a href="http://ola.hallengren.com/" target="_blank">http://ola.hallengren.com</a>.</span></div>
Posted in Pinal Dave, SQL, SQL Authority, SQL Documentation, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQLAuthority News, SQLAuthority Website Review, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7410/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7410/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7410/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7410&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/17/sql-server-2005-2008-backup-integrity-check-and-index-optimization-by-ola-hallengren/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Authority News &#8211; Training MS SQL Server 2005/2008 Query Optimization And Performance Tuning</title>
		<link>http://blog.sqlauthority.com/2009/11/10/sql-authority-news-training-ms-sql-server-20052008-query-optimization-and-performance-tuning/</link>
		<comments>http://blog.sqlauthority.com/2009/11/10/sql-authority-news-training-ms-sql-server-20052008-query-optimization-and-performance-tuning/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 01:30:30 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Training]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7357</guid>
		<description><![CDATA[This is very short note announcing details about my course details for &#8216;MS SQL Server 2005/2008 Query Optimization And Performance Tuning&#8216;.
The course is scheduled to be delivered from 19th Nov, 2009 and 21st Nov, 2009 in Pune, India.
This three day course is an intensive course designed to give attendees an in-depth look at the query [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7357&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This is very short note announcing details about my course details for &#8216;<strong>MS SQL Server 2005/2008 Query Optimization And Performance Tuning</strong>&#8216;.</p>
<p style="text-align:justify;">The course is scheduled to be delivered from <strong><em>19th Nov, 2009 and 21st Nov, 2009</em></strong> in <em><strong>Pune, India</strong></em>.</p>
<p style="text-align:justify;">This three day course is an intensive course designed to give attendees an in-depth look at the query optimization and performance tuning concepts and methods found in SQL Server 2005/2008. This course is designed to prepare the SQL Server developers and administrators for a transition to SQL Server 2005/2008 while discussing best practices for a variety of topics.</p>
<p style="text-align:justify;"><strong>Day 1 : Strengthen the basics along with SQL Server 2005/2008 New Features</strong></p>
<p style="padding-left:30px;text-align:justify;">Module 01: Subqueries, Ranking Functions, Joins and Set Operations<br />
Module 02: Table Expressions<br />
Module 03: TOP and APPLY<br />
Module 04: SQL Server 2008 Enhancements</p>
<p style="text-align:justify;"><strong>Day 2: Query Optimization &amp; Performance Tuning 1</strong></p>
<p style="padding-left:30px;text-align:justify;">Module 05: Logical Query Processing<br />
Module 06: Query Tuning<br />
Module 07:  Introduction to the Query Processor<br />
Module 08:  Review of common query coding which causes poor performance</p>
<p style="text-align:justify;"><strong>Day 3: Query Optimization &amp; Performance Tuning 2</strong></p>
<p style="padding-left:30px;text-align:justify;">Module 09:  SQL Server Indexing and index maintenance<br />
Module 10:  Plan Guides, query hints, UDFs, and Computed Columns<br />
Module 11:  Understanding SQL Server Execution Plans<br />
Module 12: Real World Index and Optimization Tips</p>
<p style="text-align:justify;">The space are limited and I encourage you to register as soon as possible.</p>
<p style="text-align:justify;"><strong>Call to register</strong> &#8211; +91 98817 95739, +91 98508 43664, +91 99229 33319</p>
<p style="text-align:justify;"><strong>Email to register</strong> &#8211; workshop &#8220;at&#8221; seedinfotech.com</p>
<p style="text-align:justify;">If due to any reason, you can not attend this course, please call or email on details above for future schedule for the course and location.</p>
<div class="wp-caption alignnone" style="width: 510px"><a href="http://www.pinaldave.com/bimg/MSQOPT.jpg"><img title="Click to Enlarge" src="http://www.pinaldave.com/bimg/MSQOPT.jpg" alt="" width="500" height="955" /></a><p class="wp-caption-text">Click to Enlarge</p></div>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQL Training, SQLAuthority News, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7357/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7357/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7357/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7357/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7357/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7357/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7357&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/10/sql-authority-news-training-ms-sql-server-20052008-query-optimization-and-performance-tuning/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/MSQOPT.jpg" medium="image">
			<media:title type="html">Click to Enlarge</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Removing Key Lookup &#8211; Seek Predicate &#8211; Predicate &#8211; An Interesting Observation Related to Datatypes</title>
		<link>http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/</link>
		<comments>http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 01:30:12 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7088</guid>
		<description><![CDATA[Recently, I have been working on Query Optimization project. While working on it, I found the following interesting observation. This entire concept may appear very simple, but if you are working in the area of query optimization and server tuning, you will find such useful hints.
Before we start, let us understand the difference between Seek [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7088&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Recently, I have been working on Query Optimization project. While working on it, I found the following interesting observation. This entire concept may appear very simple, but if you are working in the area of query optimization and server tuning, you will find such useful hints.</p>
<p style="text-align:justify;">Before we start, let us understand the difference between Seek Predicate and Predicate. Seek Predicate is the operation that describes the b-tree portion of the Seek. Predicate is the operation that describes the additional filter using non-key columns. Based on the description, it is very clear that Seek Predicate is better than Predicate as it searches indexes whereas in Predicate, the search is on non-key columns – which implies that the search is on the data in page files itself.</p>
<p style="text-align:justify;">Earlier, I had posted regarding how to remove key lookup and bookmark lookup in the following:</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup – Remove Key Lookup &#8211; Part 3</a></p>
<p style="text-align:justify;">Let us see an example where we will remove the bookmark lookup first using the covering index. On removing the bookmark lookup, it resulted in Index Scan, which is not good for performance. When Index Scan is converted to Index Seek, it provides  a significant improvement in performance.</p>
<p style="text-align:justify;">Run following SELECT, which is based on the database AdventureWorks.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">-- CTRL + M Enforces Key Lookup<br />
-- Try 1<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:black;">14417807<br />
GO</span></code></p>
<p style="text-align:justify;">Let us check the execution plan for the same. The execution plan consists of the key lookup because there are columns that we are trying to retrieve in SELECT as well in WHERE clause.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseek1.jpg" alt="" width="500" height="217" /></p>
<p style="text-align:justify;">Let us create a covering index on this table HumanResources.Employee.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Create Non clustered Index<br />
</span><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_HumanResources_Employee_Example] </span><span style="color:blue;">ON </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">ASC</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">After creating above index, let us run the same SELECT statement again.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- CTRL + M Removes Key Lookup, but it still enforces Index Scan<br />
-- Try 2<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:black;">14417807<br />
GO</span></code></p>
<p style="text-align:justify;">Due to non-clustered index, Key Lookup is removed along with Nested Loops but <em>Index Scan</em> still remains, and this is not good for performance.<span style="color:black;"> </span></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseek2.jpg" alt="" width="500" height="131" /></p>
<p style="text-align:justify;">I tried to remove the scan, but my attempts were unsuccessful. I finally looked at the datatype of the NationalIDNumber. All this time, I was assuming that this datatype is INT, but on a careful check, I found that the datatype of NationalIDNumber is nvarchar(15).</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseekdt.jpg" alt="" width="327" height="175" /></p>
<p style="text-align:justify;">In the SELECT statement, we were comparing the datatype of NVARCHAR to INT, and this was forcing the <strong>predicate </strong>operation while executing the query.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseekpre.jpg" alt="" width="492" height="668" /></p>
<p style="text-align:justify;">As discussed earlier, due to predicate operation, there has to be explicit conversion on the side of NationalIDNumber, which forces the query optimizer to not use the index and instead it has to scan the complete data in table to get the necessary data. This is not the desired solution. Index Scan reduces performance. The reason for this conversion is because I am using INT value in WHERE clause instead of NVARCHAR.</p>
<p style="text-align:justify;">I changed my WHERE clause and passed STRING as the parameter instead of INT.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- CTRL + M Removes Key Lookup and it enforces Index Seek<br />
-- Try 3<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:red;">'14417807'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">After running the query with the changed WHERE clause, the Index Scan is now converted into Index Seek.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseek3.jpg" alt="" width="500" height="145" /></p>
<p style="text-align:justify;">Index Seek is definitely the most optimal solution in this particular scenario.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseekpre1.jpg" alt="" width="510" height="584" /></p>
<p style="text-align:justify;">When the detail execution plan was checked, I found the following two notable points. First, the predicate is converted to seek predicate, which is the reason for performance improvement, as described earlier. Instead of scanning data in the table, Index Seek is performed. Second, as the datatype of the NationalIDNumber is NVARCHAR and the parameters are passed as VARCHAR, the conversion happens on the parameters instead of NationalIDNumber column, and this forces Index Scan to Index Seek.</p>
<p style="text-align:justify;">If we pass the parameter as NVARCHAR instead of VARCHAR, the execution plan will remain the same, but CONVERT_IMPLICIT will not be required any more. Let us run the following query, which has NVARCHAR as the parameter.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- CTRL + M Removes Key Lookup and it enforces Index Seek and no CONVERT_IMPLICIT<br />
-- Try 4<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:red;">N'14417807'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">The execution plan of the above query is very similar to that in which we had passed the parameter as VARCHAR.</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/bimg/klseek3.jpg" alt="" width="500" height="145" /></p>
<p style="text-align:justify;">Now let us check the execution plan for the same.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseekpre2.jpg" alt="" width="502" height="675" /></p>
<p style="text-align:justify;">In the WHERE condition, the operators we have on both the sides of &#8220;=&#8221; are of NVARCHAR. NationalIDNumber and parameter passed – both are NVARCHAR, which has removed CONVERT_IMPLICIT. However, there are no changes in the execution plan.</p>
<p style="text-align:justify;"><strong>In summary, when Key Lookup is removed and index seek replaces index scan, the performance is tuned up. </strong>Let us quickly compare the execution plan of the above four options. I have included the complete code here for easy reference.</p>
<p><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:green;">-- CTRL + M Enforces Key Lookup<br />
-- Try 1<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:black;">14417807<br />
GO<br />
</span><span style="color:green;">-- Create Non clustered Index<br />
</span><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_HumanResources_Employee_Example] </span><span style="color:blue;">ON </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">ASC</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO<br />
</span><span style="color:green;">--WAITFOR DELAY '00:00:30'<br />
-- CTRL + M Removes Key Lookup, but it still enforces Index Scan<br />
-- Try 2<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:black;">14417807<br />
GO<br />
</span><span style="color:green;">-- CTRL + M Removes Key Lookup and it enforces Index Seek<br />
-- Try 3<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:red;">'14417807'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- CTRL + M Removes Key Lookup and it enforces Index Seek and no CONVERT_IMPLICIT<br />
-- Try 4<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">NationalIDNumber</span><span style="color:gray;">, </span><span style="color:black;">HireDate</span><span style="color:gray;">, </span><span style="color:black;">MaritalStatus<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">NationalIDNumber </span><span style="color:blue;">= </span><span style="color:red;">N'14417807'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">/* What is the reason for difference between Try 2 and Try 3?<br />
Check the exeuction plan<br />
*/<br />
-- Drop Index<br />
</span><span style="color:blue;">DROP INDEX </span><span style="color:black;">[IX_HumanResources_Employee_Example] </span><span style="color:blue;">ON </span><span style="color:black;">HumanResources.Employee </span><span style="color:blue;">WITH </span><span style="color:gray;">( </span><span style="color:black;">ONLINE </span><span style="color:blue;">= OFF </span><span style="color:gray;">)<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">Let us look at the execution plan.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/klseek.jpg" alt="" width="500" height="521" /></p>
<p style="text-align:justify;">Summary points:</p>
<ul style="text-align:justify;">
<li>In      general, Index Seek is better than Index Scan (I am not talking about it      depends conditions)</li>
<li>Understand      Predicates and Seek Predicates and see if you have only Seek Predicates.</li>
<li>In      case of key lookup or bookmark lookup, see if you can create a covering      index or included column index.</li>
<li>Use      the datatype wisely even though there is no change in the resultset.</li>
</ul>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7088/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7088/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7088/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7088&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/klseek1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseek2.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseekdt.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseekpre.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseek3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseekpre1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseek3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseekpre2.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/klseek.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Tuning the Performance of Change Data Capture in SQL Server 2008</title>
		<link>http://blog.sqlauthority.com/2009/10/28/sql-server-tuning-the-performance-of-change-data-capture-in-sql-server-2008/</link>
		<comments>http://blog.sqlauthority.com/2009/10/28/sql-server-tuning-the-performance-of-change-data-capture-in-sql-server-2008/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 01:30:59 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL White Papers]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7062</guid>
		<description><![CDATA[Change data capture (CDC) is a new feature in SQL Server 2008 designed to capture insert, update, merge, and delete activities applied to SQL Server tables and to avail those changes in an easy-to-understand format.
Conventionally, detecting changes in a source database to transfer these changes to a data warehouse required any of the following:

Special  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7062&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><strong>Change data capture (CDC)</strong> is a new feature in SQL Server 2008 designed to capture insert, update, merge, and delete activities applied to SQL Server tables and to avail those changes in an easy-to-understand format.</p>
<p style="text-align:justify;">Conventionally, detecting changes in a source database to transfer these changes to a data warehouse required any of the following:</p>
<ul style="text-align:justify;">
<li>Special      columns in the source tables (time stamps, row versions).</li>
<li>Triggers      that capture changes.</li>
<li>Comparison      of the source and the destination systems.</li>
</ul>
<p style="text-align:justify;">The above methods can have significant disadvantages: special columns require a change in the source database schema, and in many cases, a change in the application logic. Triggers must be implemented manually, and this can lead to significant additional overhead on DML commands to the source system. Comparing the source and target databases can also place a heavy load on both systems.</p>
<p style="text-align:justify;">CDC offers a win-win alternative that allows the transfer of changes without forcing the DBA to either place a heavy load on the server or add the above change-detection steps. CDC enables the capture of changes by asynchronously reading the transaction log of the source database and then recording the changes in those logs in special change tables for uploading later into the target database. Therefore, no comparison between the source and target systems is needed for changes.</p>
<p style="text-align:justify;"><strong><a href="http://technet.microsoft.com/en-us/library/dd266396.aspx" target="_blank">Read white paper of Tuning the Performance of Change Data Capture in SQL Server 2008</a></strong></p>
<p style="text-align:justify;"><strong> </strong><strong><a href="http://www.pinaldave.com/best-sql-server-download.cfm?Download=cdc" target="_blank">Download Script of Change Data Capture (CDC)</a></strong></p>
<p style="text-align:justify;"><strong><a href="http://www.simple-talk.com/sql/learn-sql-server/introduction-to-change-data-capture-%28cdc%29-in-sql-server-2008/" target="_blank">Introduction to Change Data Capture (CDC)</a></strong></p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in SQL, SQL Authority, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQL White Papers, SQLAuthority News, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7062/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7062/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7062/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7062/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7062/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7062/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7062&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/28/sql-server-tuning-the-performance-of-change-data-capture-in-sql-server-2008/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQLAuthority News &#8211; PASS 2009 Sessions on Query Optimization and Performance Tuning</title>
		<link>http://blog.sqlauthority.com/2009/10/20/sqlauthority-news-pass-2009-sessions-on-query-optimization-and-performance-tuning/</link>
		<comments>http://blog.sqlauthority.com/2009/10/20/sqlauthority-news-pass-2009-sessions-on-query-optimization-and-performance-tuning/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 01:30:56 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLAuthority Author Visit]]></category>
		<category><![CDATA[SQLAuthority News]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[SQL PASS]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7169</guid>
		<description><![CDATA[PASS Summit 2009 is now only 10 days away and I am very excited for the same. I can not wait to attend the summit as this is the most awaited conference of SQL Server in world. Everybody will be there and there will be something for everybody. My core expertise is in Query Optimization [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7169&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/" target="_blank">PASS Summit 2009</a> is now only 10 days away and I am very excited for the same. I can not wait to attend the summit as this is the most awaited conference of SQL Server in world. Everybody will be there and there will be something for everybody. My core expertise is in Query Optimization and Performance Tuning area, and when I see the list of PASS session on the subject, I am totally speechless. There are so many great speaker at PASS who are there to talk on the subject.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/2009PASS_Signature02.gif" alt="" width="400" height="140" /></p>
<p style="text-align:justify;">It is absolutely not possible to attend all of them many of them are running parallel to each other. In any case, I strongly suggest if you are the expert who try till last bit to optimize the query and performance, I expect you to attend many of the following session. There is always option to get recorded DVD for the sessions afterwords.</p>
<p style="text-align:justify;">You can read my article here regarding <strong><a href="http://blog.sqlauthority.com/2009/09/11/sqlauthority-news-why-i-am-going-to-attend-pass-summit-unite-2009-seattle/" target="_blank">Why I am Going to Attend PASS Summit Unite 2009- Seattle</a></strong>.</p>
<p style="text-align:justify;">Here is my list of the sessions related to performance tuning and query optimization.</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/SpotlightSessions/MakingEffectiveUseofthePlanCache.aspx" target="_blank">Making Effective Use of the Plan Cache</a><br />
Greg Low (Solid Q Australia)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/SpotlightSessions/CapturingandAnalyzingFileWaitStats.aspx" target="_blank">Capturing and Analyzing File &amp; Wait Stats</a><br />
Andrew Kelly (Solid Quality Mentors)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/SpotlightSessions/TSQLTipsTricks.aspx" target="_blank">T-SQL Tips &amp; Tricks</a><br />
Itzik Ben-Gan (Solid Quality Mentors)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/SpotlightSessions/BestPracticesforWorkingWithExecutionPlans.aspx" target="_blank">Best Practices for Working With Execution Plans</a><br />
Grant Fritchey (FM Global)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/DMVsasaShortcuttoProcedureTuning.aspx" target="_blank">DMV&#8217;s as a Shortcut to Procedure Tuning</a><br />
Grant Fritchey (FM Global)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/SpotlightSessions/Liesdamnedliesandstatistics.aspx" target="_blank">Lies, damned lies and statistics</a><br />
Gail Shaw (XpertEase)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/InsightintoIndexes.aspx" target="_blank">Insight into Indexes</a><br />
Gail Shaw (XpertEase)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/EnhanceyourTSQLtoperformbetter.aspx" target="_blank">Enhance your T-SQL to perform better</a><br />
Joe Webb (WebbTech Solutions, LLC)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/SpotlightSessions/InsidetheManagementDataWarehouse.aspx" target="_blank">Exploring Index Internals</a><br />
Kalen Delaney (SQLearning)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/SuperBowlSuperLoadALookatPerformance.aspx" target="_blank">Super Bowl, Super Load &#8211; A Look at Performance Tuning for VLDB&#8217;&#8217;s</a><br />
Michelle Ufford (GoDaddy)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/OptimizingSQLServer2008ApplicationsusingTabl.aspx" target="_blank">Optimizing SQL Server 2008 Applications using Table Valued Parameters, XML and MERGE</a><br />
Tobias Ternstrom (Microsoft Corp.)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/SQLServerExecutionPlansFromCompilationTo.aspx" target="_blank">SQL Server Execution Plans From Compilation To Caching To Reuse</a><br />
Maciej Pilecki (Project Botticelli Ltd.)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/UsingSQLServer2008forPerformanceTuning.aspx" target="_blank">Using SQL Server 2008 for Performance Tuning</a><br />
Buck Woody (Microsoft Corp.)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/SQLCATDesigningHighPerformanceIOforSQLSer.aspx" target="_blank">SQLCAT: Designing High Performance I/O for SQL Server (90 Mins)</a><br />
Thomas Kejser (Microsoft Corp.)<br />
Mike Ruthruff (Microsoft SQL CAT)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/SpotlightSessions/SQLServer20052008PerformanceTuningandOpti.aspx" target="_blank">SQL Server 2005 / 2008 Performance Tuning and Optimization Techniques (90 Mins)</a><br />
David Pless (Microsoft CSS)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/DrDMVHowtoUseDynamicManagementViews.aspx" target="_blank">Dr. DMV: How to Use Dynamic Management Views to Monitor and Diagnose Performance Issues With High Volume OLTP Workloads</a><br />
Glenn Berry (NewsGator Technologies)</p>
<p style="text-align:justify;"><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/HowtheQueryOptimizerWorks.aspx" target="_blank">How the Query Optimizer Works</a><br />
Ben Nevarez (AIG)</p>
<p style="text-align:justify;"><strong>I will personally try to attend many of the above listed sessions. Here are two sessions not from above list, which I will be sure attending. You are encouraged to meet me and attend this two rock star sessions.</strong></p>
<p style="text-align:justify;"><strong><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/OvercomingSSISDeploymentandConfigurationChall.aspx" target="_blank">Overcoming SSIS Deployment and Configuration Challenges</a></strong><br />
Rushabh Mehta (Solid Quality Learning)</p>
<p style="text-align:justify;"><strong><a href="http://summit2009.sqlpass.org/Agenda/ProgramSessions/SQLServer2008CreatepowerfulXMLSchema.aspx" target="_blank">SQL Server 2008 &#8211; Create powerful XML Schema collections to validate your XML documents</a></strong><br />
Jacob Sebastian (beyondrelational.com)</p>
<p style="text-align:justify;">Let me know what sessions you will be sure attending by leaving your comment here. It would be good idea to create the list of the session which one is confident about attending.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Best Practices, Database, MVP, SQL, SQL Authority, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQLAuthority Author Visit, SQLAuthority News, T SQL, Technology Tagged: PASS, SQL PASS <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7169/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7169&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/20/sqlauthority-news-pass-2009-sessions-on-query-optimization-and-performance-tuning/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/2009PASS_Signature02.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup &#8211; Part 3</title>
		<link>http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3/</link>
		<comments>http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 01:30:16 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7057</guid>
		<description><![CDATA[Earlier I have written two different articles on the subject Remove Bookmark Lookup. This article is as part 3 of original article. Please read first two articles here before continuing reading this article.
SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup
SQL SERVER – Query Optimization – Remove [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7057&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Earlier I have written two different articles on the subject Remove Bookmark Lookup. This article is as part 3 of original article. Please read first two articles here before continuing reading this article.</p>
<p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></strong></p>
<p style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></strong></p>
<p style="text-align:justify;">We read in above articles that we can remove bookmark lookup using covering index. Covering Index is the index, which contains all the columns used in SELECT as well in JOINs and WHERE conditions. In our example we have created clustered index first.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Create Clustered Index<br />
</span><span style="color:blue;">CREATE CLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_ID] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">[ID] </span><span style="color:blue;">ASC<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Based on clustered index we have created following non clustered index. Please note that we do not have to create both the index together. We can create either covering index or included column index along with it. Please note, I am suggesting to create either of it, not both of it.</p>
<p style="text-align:justify;">In earlier article I have suggested to include all columns but in reality in any non clustered index there is no need to include columns included in clustered index. All non clusteredindex automatically contains pointers to clustered index any way.</p>
<p style="text-align:justify;">We should create index described in earlier article as following.</p>
<p style="text-align:justify;"><strong>Method 1: Creating covering non-clustered index.</strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Cover] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City</span><span style="color:gray;">, </span><span style="color:black;">FirstName</span><span style="color:black;"><br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;"><strong>Method 2: Creating included column non-lustered index.</strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Include] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City<br />
</span><span style="color:gray;">) </span><span style="color:black;">INCLUDE </span><span style="color:gray;">(</span><span style="color:black;">FirstName</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Let us examine the execution plan and compare the query costs and also verify that if both the index usages are forcing index seek instead of index scan.</p>
<p style="text-align:justify;"><span style="color:black;"><img src="http://www.pinaldave.com/bimg/keylook6.jpg" alt="" width="500" height="294" /></span></p>
<p style="text-align:justify;">As discussed in the example, any non clustered index does not need to include columns which are included in the clustered index.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;"><strong>Related Post:</strong></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup – Remove Key Lookup &#8211; Part 3</a></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/7057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/7057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/7057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/7057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/7057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/7057/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=7057&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/keylook6.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Queries Waiting for Memory Allocation to Execute</title>
		<link>http://blog.sqlauthority.com/2009/10/09/sql-server-queries-waiting-for-memory-allocation-to-execute/</link>
		<comments>http://blog.sqlauthority.com/2009/10/09/sql-server-queries-waiting-for-memory-allocation-to-execute/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 01:30:46 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL Memory]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6989</guid>
		<description><![CDATA[In one of the recent projects, I was asked to create a report of queries that are waiting for memory allocation. The reason was that we were doubtful regarding whether the memory was sufficient for the application. The following query can be useful in similar case. Queries that do not have to wait on a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6989&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">In one of the recent projects, I was asked to create a report of queries that are waiting for memory allocation. The reason was that we were doubtful regarding whether the memory was sufficient for the application. The following query can be useful in similar case. Queries that do not have to wait on a memory grant will not appear in the resultset of following query.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT TEXT</span><span style="color:gray;">, </span><span style="color:black;">query_plan</span><span style="color:gray;">, </span><span style="color:black;">requested_memory_kb</span><span style="color:gray;">,<br />
</span><span style="color:black;">granted_memory_kb</span><span style="color:gray;">,</span><span style="color:black;">used_memory_kb</span><span style="color:gray;">, </span><span style="color:black;">wait_order<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_exec_query_memory_grants MG<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">sql_handle</span><span style="color:gray;">)<br />
CROSS </span><span style="color:black;">APPLY sys.dm_exec_query_plan</span><span style="color:gray;">(</span><span style="color:black;">MG.plan_handle</span><span style="color:gray;">)</span></code></p>
<p style="text-align:justify;">Please note that wait_order will give order of query waiting on memory to execute. This is a very important script, I suggest that you keep it in the permanent list of queries. If ever you notice that your queries are running slow and think that memory is the culprit, do run this query. If there are lots of rows in the result, please try to optimize the queries or increase the memory capacity.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology Tagged: SQL Memory <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6989/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6989/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6989/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6989&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/09/sql-server-queries-waiting-for-memory-allocation-to-execute/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup &#8211; Part 2</title>
		<link>http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/</link>
		<comments>http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 01:30:53 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6967</guid>
		<description><![CDATA[This article is follow up of my previous article SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup. Please do read my previous article before continuing further.
I have described there two different methods to reduce query execution cost. Let us compare the performance of the SELECT statement [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6967&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">This article is follow up of my previous article <strong><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup</a></strong>. Please do read my previous article before continuing further.</p>
<p style="text-align:justify;">I have described there two different methods to reduce query execution cost. Let us compare the performance of the SELECT statement of the previous query.</p>
<p style="text-align:justify;">We have created two different indexes on the table.</p>
<p style="text-align:justify;"><strong>Method 1: Creating covering non-clustered index.</strong></p>
<p style="text-align:justify;">In this method, we will create a non-clustered index that contains the columns used in the SELECT statement along with the column used in the WHERE clause.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Cover] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City</span><span style="color:gray;">, </span><span style="color:black;">FirstName</span><span style="color:gray;">, </span><span style="color:black;">ID<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;"><strong>Method 2: Creating included column non-lustered index.</strong></p>
<p style="text-align:justify;">In this method, we will create a nonclustered index that includes the columns used in the SELECT statement along with the column used in the WHERE clause. Here, we will use new syntax introduced in SQL Server 2005. An index with included nonkey columns can significantly improve query performance when all the columns in the query are included in the index.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Include] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City<br />
</span><span style="color:gray;">) </span><span style="color:black;">INCLUDE </span><span style="color:gray;">(</span><span style="color:black;">FirstName</span><span style="color:gray;">,</span><span style="color:black;">ID</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Let us compare the performance of our query by running the following query with two different indexes.</p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex </span><span style="color:blue;">WITH </span><span style="color:gray;">(</span><span style="color:blue;">INDEX</span><span style="color:gray;">(</span><span style="color:black;">IX_OneIndex_Cover</span><span style="color:gray;">))<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex </span><span style="color:blue;">WITH </span><span style="color:gray;">(</span><span style="color:blue;">INDEX</span><span style="color:gray;">(</span><span style="color:black;">IX_OneIndex_Include</span><span style="color:gray;">))<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">Let us examine the execution plan and compare the query costs.</p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook6.jpg" alt="" width="500" height="294" /><br />
</span></p>
<p style="text-align:justify;">In fact, in this example, the performance of both the queries is quite same. In this case, we can use either of the query and obtain the same performance.</p>
<p style="text-align:justify;">I have mentioned in my previous article that I prefer the Method 2. The reason is that method 2 has many advantages over method 1.</p>
<p style="text-align:justify;">1) Index can exceed the 900-byte limitation of the index key.</p>
<p style="text-align:justify;">2) Index can include datatypes that are not allowed as key columns – varchar(max), nvarchar(max) or XML.</p>
<p style="text-align:justify;">3) Size of the key index can be reduced, which improves the overall performance of the index operation.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;"><strong>Related Post:</strong></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup – Remove Key Lookup &#8211; Part 3</a></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6967/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6967&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/keylook6.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup &#8211; Remove Key Lookup</title>
		<link>http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/</link>
		<comments>http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 01:30:49 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6960</guid>
		<description><![CDATA[Today, I would like to share one very quick tip about how to remove bookmark lookup or RID lookup. Let us first understand Bookmark lookup or RID lookup. Please note that from SQL Server 2005 SP1 onwards, Bookmark look up is known as Key look up.
When a small number of rows are requested by a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6960&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Today, I would like to share one very quick tip about how to remove bookmark lookup or RID lookup. Let us first understand Bookmark lookup or RID lookup. Please note that from SQL Server 2005 SP1 onwards, Bookmark look up is known as Key look up.</p>
<p style="text-align:justify;">When a small number of rows are requested by a query, the SQL Server optimizer will try to use a non-clustered index on the column or columns contained in the WHERE clause to retrieve the data requested by the query. If the query requests data from columns not present in the non-clustered index, SQL Server must go back to the data pages to get the data in those columns. Even if the table has a clustered index or not, the query will still have to return to the table or clustered index to retrieve the data.</p>
<p style="text-align:justify;">In the above scenario, if table has clustered index, it is called <strong>bookmark lookup</strong> (or key lookup); if the table does not have clustered index, but a non-clustered index, it is called <strong>RID lookup</strong>. This operation is very expensive. To optimize any query containing bookmark lookup or RID lookup, it should be removed from the execution plan to improve performance. There are two different ways to remove bookmark/RID lookup.</p>
<p style="text-align:justify;">Before we understand these two methods, we will create sample table without clustered index and simulate RID lookup. RID Lookup is a bookmark lookup on a heap that uses a supplied row identifier (RID).</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">tempdb<br />
GO<br />
</span><span style="color:green;">-- Create Table OneIndex with few columns<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">OneIndex </span><span style="color:gray;">(</span><span style="color:black;">ID </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">FirstName </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">),<br />
</span><span style="color:black;">LastName </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">),<br />
</span><span style="color:black;">City </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">))<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Insert One Hundred Thousand Records<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:black;">OneIndex </span><span style="color:gray;">(</span><span style="color:black;">ID</span><span style="color:gray;">,</span><span style="color:black;">FirstName</span><span style="color:gray;">,</span><span style="color:black;">LastName</span><span style="color:gray;">,</span><span style="color:black;">City</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT TOP </span><span style="color:black;">100000 ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">) </span><span style="color:black;">RowID</span><span style="color:gray;">,<br />
</span><span style="color:red;">'Bob'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE </span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">2 </span><span style="color:blue;">= </span><span style="color:black;">1 </span><span style="color:blue;">THEN </span><span style="color:red;">'Smith'<br />
</span><span style="color:blue;">ELSE </span><span style="color:red;">'Brown' </span><span style="color:blue;">END</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">1000 </span><span style="color:blue;">= </span><span style="color:black;">1 </span><span style="color:blue;">THEN </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">10 </span><span style="color:blue;">= </span><span style="color:black;">1 </span><span style="color:blue;">THEN </span><span style="color:red;">'New York'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">10 </span><span style="color:blue;">= </span><span style="color:black;">5 </span><span style="color:blue;">THEN </span><span style="color:red;">'San Marino'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">)%</span><span style="color:black;">10 </span><span style="color:blue;">= </span><span style="color:black;">3 </span><span style="color:blue;">THEN </span><span style="color:red;">'Los Angeles'<br />
</span><span style="color:blue;">ELSE </span><span style="color:red;">'Houston' </span><span style="color:blue;">END<br />
FROM </span><span style="color:black;">sys.all_objects a<br />
</span><span style="color:gray;">CROSS </span><span style="color:blue;">JOIN </span><span style="color:black;">sys.all_objects b<br />
GO</span></code></p>
<p style="text-align:justify;">Now let us run following select statement and check the execution plan.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook1.jpg" alt="" width="472" height="295" /></span></p>
<p style="text-align:justify;"><span style="color:black;">As there is no index on table, scan is performed over the table. We will create a clustered index on the table and check the execution plan once again. </span></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Create Clustered Index<br />
</span><span style="color:blue;">CREATE CLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_ID] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">[ID] </span><span style="color:blue;">ASC<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Now, run following select on the table once again.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook2.jpg" alt="" width="473" height="274" /></p>
<p><!--[if gte mso 9]&gt;  800x600  &lt;![endif]--></p>
<p><!--[if gte mso 9]&gt;  Normal 0     false false false  EN-US X-NONE X-NONE            MicrosoftInternetExplorer4              &lt;![endif]--><!--[if gte mso 9]&gt;                                                                                                                                             &lt;![endif]--></p>
<p style="text-align:justify;">It is clear from execution plan that as a clustered index is created on the table, table scan is now converted to clustered index scan. In either case, base table is completely scanned and there is no seek on the table.</p>
<p style="text-align:justify;">Now, let us see the WHERE clause of our table. From our basic observation, if we create an index on the column that contains the clause, a performance improvement may be obtained. Let us create non-clustered index on the table and then check the execution plan.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">-- Create Index on Column City As that is used in where condition<br />
</span><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_City] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">[City] </span><span style="color:blue;">ASC<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">After creating the non-clustered index, let us run our select statement again and check the execution plan.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook3.jpg" alt="" width="486" height="351" /></p>
<p><!--[if gte mso 9]&gt;  800x600  &lt;![endif]--></p>
<p style="text-align:justify;">As we have an index on the WHERE clause, the SQL Server query execution engine uses the non-clustered index to retrieve data from the table. However, the columns used in the SELECT clause are still not part of the index, and to display those columns, the engine will have to go to the base table again and retrieve those columns. This particular behavior is known as bookmark lookup or key lookup.</p>
<p style="text-align:justify;">There are two different methods to resolve this issue. I have demonstrated both the methods together; however, it is recommended that you use any one of these methods for removing key lookup. I prefer Method 2.</p>
<p style="text-align:justify;"><strong>Method 1: Creating non-clustered cover index.</strong></p>
<p style="text-align:justify;">In this method, we will create non-clustered index containing the columns, which are used in the SELECT statement, along with the column which is used in the WHERE clause.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Cover] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City</span><span style="color:gray;">, </span><span style="color:black;">FirstName</span><span style="color:gray;">, </span><span style="color:black;">ID<br />
</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">Once the above non-clustered index, which covers all the columns in query, is created, let us run the following SELECT statement and check our execution plan.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">From the execution plan, we can confirm that key lookup is removed the only index seek is happening. As there is no key lookup, the SQL Server query engine does not have to go to retrieve the data from data pages and it obtains all the necessary data from index itself.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook4.jpg" alt="" width="469" height="262" /></p>
<p style="text-align:justify;"><strong>Method 2: Creating an included column non-clustered index.</strong></p>
<p style="text-align:justify;">Here, we will create non-clustered index that also includes the columns, which are used in the SELECT statement, along with the column used in the WHERE clause. In this method, we will use new syntax introduced in SQL Server 2005. An index with included nonkey columns can significantly improve query performance when all columns in the query are included in the index.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE NONCLUSTERED INDEX </span><span style="color:black;">[IX_OneIndex_Include] </span><span style="color:blue;">ON </span><span style="color:black;">[dbo].[OneIndex]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">City<br />
</span><span style="color:gray;">) </span><span style="color:black;">INCLUDE </span><span style="color:gray;">(</span><span style="color:black;">FirstName</span><span style="color:gray;">,</span><span style="color:black;">ID</span><span style="color:gray;">) </span><span style="color:blue;">ON </span><span style="color:black;">[PRIMARY]<br />
GO</span></code></p>
<p style="text-align:justify;">From the execution plan, it is very clear that this method  also removes the key lookup as well.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/keylook5.jpg" alt="" width="467" height="263" /></p>
<p style="text-align:justify;">In summary, Key lookup, Bookmark lookup or RID lookup reduces the performance of query, and we can improve the performance of query by using included column index or cover index.</p>
<p style="text-align:justify;">I will cover few additional concepts related to the optimal method in another article.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;"><strong>Related Post:</strong></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2009/10/08/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-2/" target="_blank">SQL SERVER – Query Optimization – Remove Bookmark Lookup – Remove RID Lookup – Remove Key Lookup – Part 2</a></p>
<p><a href="http://blog.sqlauthority.com/2009/10/12/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup-part-3" target="_blank">SQL SERVER &#8211; Query Optimization &#8211; Remove Bookmark Lookup &#8211; Remove RID Lookup – Remove Key Lookup &#8211; Part 3</a></p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:2058px;width:1px;height:1px;text-align:justify;">
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">FirstName<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">OneIndex<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">City </span><span style="color:blue;">= </span><span style="color:red;">'Las Vegas'<br />
</span><span style="color:black;">GO</span></code></p>
</div>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6960/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6960/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6960/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6960/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6960/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6960/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6960&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/07/sql-server-query-optimization-remove-bookmark-lookup-remove-rid-lookup-remove-key-lookup/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/keylook1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/keylook2.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/keylook3.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/keylook4.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/keylook5.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Interesting Observation &#8211; Query Hint &#8211; FORCE ORDER</title>
		<link>http://blog.sqlauthority.com/2009/10/06/sql-server-interesting-observation-query-hint-force-order/</link>
		<comments>http://blog.sqlauthority.com/2009/10/06/sql-server-interesting-observation-query-hint-force-order/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 01:30:17 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6916</guid>
		<description><![CDATA[SQL Server never stops to amaze me. As regular readers of this blog already know that besides conducting corporate training, I work on large-scale projects on query optimizations and server tuning projects. In one of the recent projects, I have noticed that a Junior Database Developer used the query hint Force Order; when I asked [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6916&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">SQL Server never stops to amaze me. As regular readers of this blog already know that besides conducting corporate training, I work on large-scale projects on query optimizations and server tuning projects. In one of the recent projects, I have noticed that a Junior Database Developer used the query hint Force Order; when I asked for details, I found out that the basic concept was not properly understood by him.</p>
<p style="text-align:justify;">Today, let us try to understand its working and the effect of this hint. Further, we will see the extent of difference in performance created by this one query hint. I also have one interesting question for all of you as well; I will give the answer in one of my later posts.</p>
<p style="text-align:left;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:black;">CountEmployee </span><span style="color:green;">-- 290 Rows<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:black;">CountEmployeeAddress </span><span style="color:green;">-- 290 Rows<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.EmployeeAddress<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">COUNT</span><span style="color:gray;">(*) </span><span style="color:black;">CountEmployeeDepartmentHistory </span><span style="color:green;">-- 296 Rows<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.EmployeeDepartmentHistory<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee e<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">HumanResources.EmployeeAddress ea </span><span style="color:blue;">ON </span><span style="color:black;">ea.EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">e.EmployeeID<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">HumanResources.EmployeeDepartmentHistory edh </span><span style="color:blue;">ON </span><span style="color:black;">edh.EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">e.EmployeeID<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">HumanResources.Employee e<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">HumanResources.EmployeeAddress ea </span><span style="color:blue;">ON </span><span style="color:black;">ea.EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">e.EmployeeID<br />
</span><span style="color:blue;">INNER JOIN </span><span style="color:black;">HumanResources.EmployeeDepartmentHistory edh </span><span style="color:blue;">ON </span><span style="color:black;">edh.EmployeeID </span><span style="color:blue;">= </span><span style="color:black;">e.EmployeeID<br />
</span><span style="color:blue;">OPTION </span><span style="color:gray;">(</span><span style="color:black;">FORCE </span><span style="color:blue;">ORDER</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code></p>
<p style="text-align:justify;">In above example, I have used three tables and their row count is listed as well. Employee and EmployeeAddress – both have same number rows, and EmployeeDepartmentHistory table has around 6 rows more than the other two tables. Now let us run the query without using OPTION (FORCE ORDER) and run it along with the query hint and check the execution plan. You will find a difference in the query cost.</p>
<p style="text-align:justify;">We all accept that the table with least number of rows should be listed as the base table, and the same is done here. We have two such tables with the least number of rows, which are listed as base tables. Now before we further explain this, let us see the execution plan for the same.</p>
<p style="text-align:justify;">
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/forceorder.jpg" alt="" width="500" height="404" /></p>
<p style="text-align:justify;">It is very clear from the above execution plan that when I order is forced the query cost goes high. This proves that the SQL Server has already made a good decision with regard to the optimized query plan. When plan is forced in the case of the joins more than 2 table the performance matters. Let us see the execution order of the table in both the cases.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/forceorder1.jpg" alt="" width="500" height="618" /></p>
<p style="text-align:justify;">Now, from the example, it is very clear when you force order the query, it evaluates the table Employee first and when it is not forced, it evaluates EmployeeAddress first. Even though both the tables have same number of rows, the query optimizer processes them differently and uses different types of join logic. When the order is not forced, it uses hash join; further, in case of forced order, it uses nested loop – this creates a significant difference in the query cost.</p>
<p style="text-align:justify;">The conclusion of this whole exercise is very simple.</p>
<ul style="text-align:justify;">
<li>SQL      Server Query Execution Engine is pretty smart to decide the best execution      plan with least query cost for any query.</li>
<li>Order      of the tables in any query can make a significant impact on the query.</li>
</ul>
<p style="text-align:justify;">Now the question for you: We have seen that using query hint of OPTION (FORCE ORDER) reduces the performance; give an example wherein we can use this hint to improve the performance?</p>
<p style="text-align:justify;">Please leave your comment here. I will publish the answer to this question with due credit and with my own example in a later post.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL Index, SQL Joins, SQL Optimization, SQL Performance, SQL Puzzle, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6916/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6916&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/10/06/sql-server-interesting-observation-query-hint-force-order/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/forceorder.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/forceorder1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Outer Join in Indexed View &#8211; Question to Readers</title>
		<link>http://blog.sqlauthority.com/2009/09/25/sql-server-outer-join-in-indexed-view-question-to-readers/</link>
		<comments>http://blog.sqlauthority.com/2009/09/25/sql-server-outer-join-in-indexed-view-question-to-readers/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 01:30:46 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL White Papers]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL View]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6910</guid>
		<description><![CDATA[Today I have question for you. Just a day ago I was reading whitepaper Improving Performance with SQL Server 2008 Indexed Views. Following is question and answer I read in the white paper.
Q. Why can&#8217;t I use OUTER JOIN in an indexed view?
A. Rows can logically disappear from an indexed view based on OUTER JOIN [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6910&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Today I have question for you. Just a day ago I was reading whitepaper <a href="http://msdn.microsoft.com/en-us/library/dd171921.aspx" target="_blank">Improving Performance with SQL Server 2008 Indexed Views</a>. Following is question and answer I read in the white paper.</p>
<p style="padding-left:30px;text-align:justify;"><em><strong>Q. Why can&#8217;t I use OUTER JOIN in an indexed view?</strong></em></p>
<p style="padding-left:30px;text-align:justify;"><em>A. Rows can logically disappear from an indexed view based on OUTER JOIN when you insert data into a base table. This makes incrementally updating OUTER JOIN views relatively complex to implement, and the performance of the implementation would be slower than for views based on standard (INNER) JOIN.</em></p>
<p style="text-align:justify;">Here I would like to ask you one question, do you have example for kind of OUTER JOIN where you insert data into base table, it will make a row disappear from query?</p>
<p style="text-align:justify;">Please post your answer as comment.</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Joins, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, SQL White Papers, SQLServer, T SQL, Technology Tagged: SQL View <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6910/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6910/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6910/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6910/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6910/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6910/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6910&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/25/sql-server-outer-join-in-indexed-view-question-to-readers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Interesting Observation &#8211; Index on Index View Used in Similar Query</title>
		<link>http://blog.sqlauthority.com/2009/09/24/sql-server-interesting-observation-index-on-index-view-used-in-similar-query/</link>
		<comments>http://blog.sqlauthority.com/2009/09/24/sql-server-interesting-observation-index-on-index-view-used-in-similar-query/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 01:30:36 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL White Papers]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6895</guid>
		<description><![CDATA[Recently, I was working on an optimization project for one of the large organizations. While working on one of the queries, we came across a very interesting observation. We found that there was a query on the base table and when the query was run, it used the index, which did not exist in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6895&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Recently, I was working on an optimization project for one of the large organizations. While working on one of the queries, we came across a very interesting observation. We found that there was a query on the base table and when the query was run, it used the index, which did not exist in the base table. On careful examination, we found that the query was using the index that was on another view. This was very interesting as I have personally never experienced a scenario like this. In simple words, &#8220;Query on the base table can use the index created on the indexed view of the same base table.&#8221;</p>
<p style="text-align:justify;">If you have skipped the first paragraph, I suggest you go over the first paragraph one more time and try to understand the intended meaning. According to me, this is a very interesting observation and we rarely come across such an instance. I have made very small attempt to recreate this particular behavior.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">tempdb<br />
GO<br />
</span><span style="color:green;">-- Create Table<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">IndexViewAggr </span><span style="color:gray;">(</span><span style="color:black;">ID </span><span style="color:blue;">INT</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Insert One Hundred Thousand Records<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:black;">IndexViewAggr </span><span style="color:gray;">(</span><span style="color:black;">ID</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT TOP </span><span style="color:black;">100000 ROW_NUMBER</span><span style="color:gray;">() </span><span style="color:blue;">OVER </span><span style="color:gray;">(</span><span style="color:blue;">ORDER BY </span><span style="color:black;">a.name</span><span style="color:gray;">) </span><span style="color:black;">RowID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.all_objects a<br />
</span><span style="color:gray;">CROSS </span><span style="color:blue;">JOIN </span><span style="color:black;">sys.all_objects b<br />
GO<br />
</span><span style="color:green;">-- Create View on the table<br />
</span><span style="color:blue;">CREATE VIEW </span><span style="color:black;">ViewAggr </span><span style="color:blue;">WITH </span><span style="color:black;">SCHEMABINDING<br />
</span><span style="color:blue;">AS<br />
SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">COUNT_BIG</span><span style="color:gray;">(*) </span><span style="color:black;">CountID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.IndexViewAggr<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">ID </span><span style="color:gray;">BETWEEN </span><span style="color:black;">1 </span><span style="color:gray;">AND </span><span style="color:black;">1000<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">ID<br />
GO<br />
</span><span style="color:green;">-- Following query is very identical to View<br />
-- Run the query on base table<br />
-- Please note that in execution plan there is Table Scan<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">COUNT_BIG</span><span style="color:gray;">(*) </span><span style="color:black;">CountID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.IndexViewAggr<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">ID </span><span style="color:gray;">BETWEEN </span><span style="color:black;">1 </span><span style="color:gray;">AND </span><span style="color:black;">1000<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">ID<br />
GO<br />
</span><span style="color:green;">-- Create Index on the View<br />
-- Please note that this index is on View and not on table<br />
</span><span style="color:blue;">CREATE UNIQUE CLUSTERED INDEX </span><span style="color:black;">IndexView </span><span style="color:blue;">ON </span><span style="color:black;">ViewAggr</span><span style="color:gray;">(</span><span style="color:black;">ID</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:green;">-- Run the query on base table again<br />
-- Please note that in execution plan there is Index Scan<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">ID</span><span style="color:gray;">, </span><span style="color:black;">COUNT_BIG</span><span style="color:gray;">(*) </span><span style="color:black;">CountID<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.IndexViewAggr<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">ID </span><span style="color:gray;">BETWEEN </span><span style="color:black;">1 </span><span style="color:gray;">AND </span><span style="color:black;">1000<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">ID<br />
GO<br />
</span><span style="color:green;">-- Please note that there are difference in "Query Cost"<br />
-- Clean up Database<br />
</span><span style="color:blue;">DROP VIEW </span><span style="color:black;">ViewAggr<br />
GO<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">IndexViewAggr<br />
GO</span></code>
</p>
<p style="text-align:justify;">Now let us quickly observe two performance comparison of two of the selects. One object is created before the creation of the index over the view, and the other object is created after the creation of the index over the view. Please note that we are talking about two different objects here. Let me explain this schematically.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/queryindex.jpg" alt="" width="500" height="513" /></p>
<p style="text-align:justify;">This is a very interesting behavior as the index created on view affects the query that runs on the base table. Let me show you the execution plan of the query before and after index creation.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/indexview1.jpg" alt="" width="500" height="285" /></p>
<p style="text-align:justify;">From this example, it is very clear that there is a very big difference between the query costs when the index is created on the table. In fact, there is a very simple explanation of this behavior in the white paper <a href="http://msdn.microsoft.com/en-us/library/dd171921.aspx" target="_blank">Improving Performance with SQL Server 2008 Indexed Views</a>.</p>
<p style="text-align:justify;">The reason for this behavior is that the query optimizer works when it checks for the index on view and finds that the execution plan of the query is similar to that of the view.</p>
<p style="text-align:justify;">Let me know your thoughts about this article. I do understand that this concept is slightly complicated. Further, this type of behavior is rarely encountered in real world. I hope that this article will give you a better insight to such a situation.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;">
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Optimization, SQL Performance, SQL Puzzle, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQL White Papers, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6895/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6895/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6895/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6895/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6895/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6895&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/24/sql-server-interesting-observation-index-on-index-view-used-in-similar-query/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/queryindex.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/indexview1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Execution Plan and Results of Aggregate Concatenation Queries Depend Upon Expression Location</title>
		<link>http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/</link>
		<comments>http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 01:30:11 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6786</guid>
		<description><![CDATA[I was reading the blog of Ward Pond, and I came across another note of Microsoft. I really found it very interesting. The given explanation was very simple; however, I would like to rewrite it again.
Let us execute the following script. This script inserts two values &#8216;A&#8217; and &#8216;B&#8217; in the table and outputs a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6786&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I was reading the blog of <a href="http://blogs.technet.com/wardpond/archive/2009/09/07/database-programming-a-new-string-concatenation-contender-for-sql-server-2008.aspx" target="_blank">Ward Pond</a>, and I came across <a href="http://support.microsoft.com/default.aspx?scid=287515" target="_blank">another note</a> of Microsoft. I really found it very interesting. The given explanation was very simple; however, I would like to rewrite it again.</p>
<p style="text-align:justify;">Let us execute the following script. This script inserts two values &#8216;A&#8217; and &#8216;B&#8217; in the table and outputs a simple code to concatenate each other to produce the result &#8216;AB&#8217;.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">IF </span><span style="color:gray;">EXISTS( </span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sysobjects </span><span style="color:blue;">WHERE </span><span style="color:black;">name </span><span style="color:blue;">= </span><span style="color:red;">'T1' </span><span style="color:gray;">)<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">T1<br />
GO<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">T1</span><span style="color:gray;">( </span><span style="color:black;">C1 </span><span style="color:magenta;">NCHAR</span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">)  )<br />
</span><span style="color:blue;">INSERT </span><span style="color:black;">T1 </span><span style="color:blue;">VALUES</span><span style="color:gray;">( </span><span style="color:red;">'A' </span><span style="color:gray;">)<br />
</span><span style="color:blue;">INSERT </span><span style="color:black;">T1 </span><span style="color:blue;">VALUES</span><span style="color:gray;">( </span><span style="color:red;">'B' </span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Str0 </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">4</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Str0 </span><span style="color:blue;">= </span><span style="color:red;">''<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Str0 </span><span style="color:blue;">= </span><span style="color:#434343;">@Str0 </span><span style="color:gray;">+ </span><span style="color:black;">C1 </span><span style="color:blue;">FROM </span><span style="color:black;">T1 </span><span style="color:blue;">ORDER BY </span><span style="color:black;">C1<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Str0 </span><span style="color:blue;">AS </span><span style="color:black;">Result<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">T1</span></code>
</p>
<p style="text-align:justify;">The code to concatenating any two string is very simple which is used three times in following example.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">IF </span><span style="color:gray;">EXISTS( </span><span style="color:blue;">SELECT </span><span style="color:gray;">* </span><span style="color:blue;">FROM </span><span style="color:black;">sysobjects </span><span style="color:blue;">WHERE </span><span style="color:black;">name </span><span style="color:blue;">= </span><span style="color:red;">'T1' </span><span style="color:gray;">)<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">T1<br />
GO<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">T1</span><span style="color:gray;">( </span><span style="color:black;">C1 </span><span style="color:magenta;">NCHAR</span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">)  ) </span><span style="color:blue;"><br />
INSERT </span><span style="color:black;">T1 </span><span style="color:blue;">VALUES</span><span style="color:gray;">( </span><span style="color:red;">'A' </span><span style="color:gray;">)<br />
</span><span style="color:blue;">INSERT </span><span style="color:black;">T1 </span><span style="color:blue;">VALUES</span><span style="color:gray;">( </span><span style="color:red;">'B' </span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Str0 </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">4</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Str1 </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">4</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Str2 </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">4</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Str0 </span><span style="color:blue;">= </span><span style="color:red;">''<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Str1 </span><span style="color:blue;">= </span><span style="color:red;">''<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Str2 </span><span style="color:blue;">= </span><span style="color:red;">''<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Str0 </span><span style="color:blue;">= </span><span style="color:#434343;">@Str0 </span><span style="color:gray;">+ </span><span style="color:black;">C1 </span><span style="color:blue;">FROM </span><span style="color:black;">T1 </span><span style="color:blue;">ORDER BY </span><span style="color:black;">C1<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Str1 </span><span style="color:blue;">= </span><span style="color:#434343;">@Str1 </span><span style="color:gray;">+ </span><span style="color:black;">C1 </span><span style="color:blue;">FROM </span><span style="color:black;">T1 </span><span style="color:blue;">ORDER BY </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">( </span><span style="color:magenta;">RTRIM</span><span style="color:gray;">( </span><span style="color:black;">C1 </span><span style="color:gray;">) )<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Str2 </span><span style="color:blue;">= </span><span style="color:#434343;">@Str2 </span><span style="color:gray;">+ </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">( </span><span style="color:magenta;">RTRIM</span><span style="color:gray;">( </span><span style="color:black;">C1 </span><span style="color:gray;">) ) </span><span style="color:blue;">FROM </span><span style="color:black;">T1 </span><span style="color:blue;">ORDER BY </span><span style="color:black;">C1<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Str0 </span><span style="color:red;">'No functions applied to column.'<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Str1 </span><span style="color:red;">'LTRIM() and RTRIM() applied to ORDER BY clause.'<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Str2 </span><span style="color:red;">'SELECT list with LTRIM(RTRIM()) (Workaround)'<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:black;">T1 </span></code>
</p>
<p style="text-align:justify;">Resultset of the above query is as follows.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/orderbyfun.jpg" alt="" width="500" height="276" /></p>
<p style="text-align:justify;">From this result, it is evident that the resultset where function is applied in ORDER BY clause gives the wrong result. When the same function is moved to SELECT clause, it gives the correct result. That is in one way very strange; however, this is how it is defined in SQL Server standard. The behavior of the function in ORDER BY is not defined anywhere in SQL documentation.</p>
<p style="text-align:justify;">The best practice is to avoid the usage of function in ORDER BY clause when string concatenation operations are executed.</p>
<p style="text-align:justify;">The reason for this behavior is that the use of function in ORDER BY clause will change the order of query execution and create an unexpected output.</p>
<p style="text-align:justify;">
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/orderbyfun1.jpg" alt="" width="488" height="240" /></p>
<p style="text-align:justify;">Let me know if you have any other example for the same or a better explanation.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Documentation, SQL Performance, SQL Puzzle, SQL Query, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6786/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6786/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6786/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6786&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/20/sql-server-execution-plan-and-results-of-aggregate-concatenation-queries-depend-upon-expression-location/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/orderbyfun.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/orderbyfun1.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Converting Stored Procedure into Table Valued Function</title>
		<link>http://blog.sqlauthority.com/2009/09/17/sql-server-converting-stored-procedure-into-table-valued-function/</link>
		<comments>http://blog.sqlauthority.com/2009/09/17/sql-server-converting-stored-procedure-into-table-valued-function/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 01:30:27 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6798</guid>
		<description><![CDATA[In one of my recent articles, I mentioned the use of Table Valued Function (TVF) instead of Stored Procedure (SP). I received a follow up email asking what type of SP can be converted into a TVF. This is indeed a very interesting question! In fact, not all the SPs qualify to be converted to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6798&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">In one of my recent articles, I mentioned the use of Table Valued Function (TVF) instead of Stored Procedure (SP). I received a follow up email asking what type of SP can be converted into a TVF. This is indeed a very interesting question! In fact, not all the SPs qualify to be converted to a TVF.</p>
<p style="text-align:justify;">Please note that I am not encouraging to convert all the SPs to TVFs. Each SPs have their own usage and need. Here, I shall discuss about the type of SP that can be converted to a TVF.</p>
<p style="text-align:justify;">First of all, you need to convert the SP that you are using to retrieve data and to insert it into any other table. Please read my original post wherein I have explained the scenario for the same. If you do not have to insert the data from the SP into another table, then there is no need to convert the SP to a TVF. This conversion will not necessarily enhance the performance.</p>
<p style="text-align:justify;">In general, SP that returns only one resultset qualifies for conversion to TVF. If there are more than one resultset, then the SP cannot be converted to TVF as the TVF always returns one resultset. Moreover, if the SP has DML statements such as DELETE, UPDATE, INSERT or MERGE, it cannot be converted to a TVF. The usage of TVF is limited to the SELECT statement only. If the SP must be executed by using EXEC, it cannot be converted to TVF.</p>
<p style="text-align:justify;">Do you know any other reason why a SP needs to be converted to a TVF?</p>
<p style="text-align:justify;">Reference: <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Function, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Stored Procedure, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6798/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6798&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/09/17/sql-server-converting-stored-procedure-into-table-valued-function/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Index Seek vs. Index Scan &#8211; Diffefence and Usage &#8211; A Simple Note</title>
		<link>http://blog.sqlauthority.com/2009/08/24/sql-server-index-seek-vs-index-scan-diffefence-and-usage-a-simple-note/</link>
		<comments>http://blog.sqlauthority.com/2009/08/24/sql-server-index-seek-vs-index-scan-diffefence-and-usage-a-simple-note/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 01:30:18 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6648</guid>
		<description><![CDATA[In this article we shall examine the two modes of data search and retrieval using indexes- index seeks and index scans, and the differences between the two.
Firstly, let us revisit indexes briefly. An index in a SQL Server database is analogous to the index at the start of a book. That is, its function is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6648&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">In this article we shall examine the two modes of data search and retrieval using indexes- index seeks and index scans, and the differences between the two.</p>
<p style="text-align:justify;">Firstly, let us revisit indexes briefly. An index in a SQL Server database is analogous to the index at the start of a book. That is, its function is to allow you to quickly find the data you are searching for inside the book; in the case of a database, the “book” is a table.</p>
<p style="text-align:justify;">An index scan means that SQL Server reads all rows in a table, and then returns only those rows that satisfy the search criteria. When an index scan is performed, all the rows in the leaf level of the index are scanned. This essentially means that all of the rows of the index are examined instead of the table directly. This is sometimes contrasted to a table scan, in which all the table data is read directly. However, there is usually little difference between an index scan and a table scan.</p>
<p style="text-align:justify;">You may wonder why the Query Optimizer may choose to do an index or table scan. Surely it is much faster to first look up data using an index than to go through all the rows in a table? In fact, for small tables data retrieval via an index or table scan is faster than using the index itself for selection. This is because the added overhead of first reading the index, then reading the pages containing the rows returned by the index, does not offer any performance improvement for a table with only a few rows.</p>
<p style="text-align:justify;">Other reasons to use an index scan would be when an index is not selective enough, and when a query will return a large percentage (greater than 50%) of rows from the table. In such cases the additional overhead of first using the index may result in a small degradation of performance.</p>
<p style="text-align:justify;">An index seek, on the other hand, means that the Query Optimizer relies entirely on the index leaf data to locate rows satisfying the query condition. An index seek will be most beneficial in cases where a small percentage (less than 10 or 15%) of rows will be returned. An index seek will only affect the rows that satisfy a query condition and the pages that contain these qualifying rows; this is highly beneficial, in performance terms, when a table has a very large number of rows.</p>
<p style="text-align:justify;">It is also worth noting that it is usually not worthwhile to create indexes on low-cardinality columns as they would rarely be used by the Query Optimizer. A low-cardinality column is one that contains a very small range of distinct values, for example a ‘Gender’ column would have only two distinct values- Male or Female. An example of a high-cardinality column is of course the primary key column, in which each value is distinct.</p>
<p style="text-align:justify;">In summary, the Query Optimizer generally tries to perform an index seek. If this is not possible or beneficial (for example when the total number of rows is very small) then an index scan is used instead.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Index, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6648/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6648/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6648/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6648/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6648/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6648/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6648&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/24/sql-server-index-seek-vs-index-scan-diffefence-and-usage-a-simple-note/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Get Query Plan Along with Query Text and Execution Count</title>
		<link>http://blog.sqlauthority.com/2009/08/21/sql-server-get-query-plan-along-with-query-text-and-execution-count/</link>
		<comments>http://blog.sqlauthority.com/2009/08/21/sql-server-get-query-plan-along-with-query-text-and-execution-count/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 01:30:15 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6619</guid>
		<description><![CDATA[Quite often, we need to know how many any particular objects have been executed on our server and what their execution plan is. I use the following handy script, which I use when I need to know the details regarding how many times any query has ran on my server along with its execution plan. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6619&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Quite often, we need to know how many any particular objects have been executed on our server and what their execution plan is. I use the following handy script, which I use when I need to know the details regarding how many times any query has ran on my server along with its execution plan. You can add an additional WHERE condition if you want to learn about any specific object.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">cp.objtype </span><span style="color:blue;">AS </span><span style="color:black;">ObjectType</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">OBJECT_NAME</span><span style="color:gray;">(</span><span style="color:black;">st.objectid</span><span style="color:gray;">,</span><span style="color:black;">st.dbid</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">ObjectName</span><span style="color:gray;">,<br />
</span><span style="color:black;">cp.usecounts </span><span style="color:blue;">AS </span><span style="color:black;">ExecutionCount</span><span style="color:gray;">,<br />
</span><span style="color:black;">st.</span><span style="color:blue;">TEXT AS </span><span style="color:black;">QueryText</span><span style="color:gray;">,<br />
</span><span style="color:black;">qp.query_plan </span><span style="color:blue;">AS </span><span style="color:black;">QueryPlan<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_exec_cached_plans </span><span style="color:blue;">AS </span><span style="color:black;">cp<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_query_plan</span><span style="color:gray;">(</span><span style="color:black;">cp.plan_handle</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">qp<br />
</span><span style="color:gray;">CROSS </span><span style="color:black;">APPLY sys.dm_exec_sql_text</span><span style="color:gray;">(</span><span style="color:black;">cp.plan_handle</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">st<br />
</span><span style="color:green;">--WHERE OBJECT_NAME(st.objectid,st.dbid) = 'YourObjectName'</span></code>
</p>
<p style="text-align:justify;">In result set, you will find the last column QueryPlan with XML text in it. Click on it, and it will open a new tab displaying the graphical execution plan.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/explan1.jpg" alt="" width="500" height="508" /></p>
<p style="text-align:justify;">You can also save the newly opened tab in XML format with the extension .sqlplan. When this new file is opened in SQL Server Management Studio, it will automatically display the graphical representation of the XML Plan.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/explan2.jpg" alt="" width="500" height="170" /></p>
<p style="text-align:justify;">It is a quite simple script, but it works all the time.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;">
Posted in Pinal Dave, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, SQLServer, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6619/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6619/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6619/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6619&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/21/sql-server-get-query-plan-along-with-query-text-and-execution-count/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/explan1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/explan2.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Measure CPU Pressure &#8211; CPU Business</title>
		<link>http://blog.sqlauthority.com/2009/08/17/sql-server-measure-cpu-pressure-cpu-business/</link>
		<comments>http://blog.sqlauthority.com/2009/08/17/sql-server-measure-cpu-pressure-cpu-business/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 01:30:35 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL System Table]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=6601</guid>
		<description><![CDATA[Many a time, DBAs face the following question: can the CPU handle the current transaction? I have seen many DBAs getting confused on whether they should get a CPU with higher clock speed or more number of CPUs when it is time to upgrade system. As we all know, the CPU (or the Central Processing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6601&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Many a time, DBAs face the following question: can the CPU handle the current transaction? I have seen many DBAs getting confused on whether they should get a CPU with higher clock speed or more number of CPUs when it is time to upgrade system. As we all know, the CPU (or the Central Processing Unit) is the core of any system. The CPU is responsible for not only SQL Server operations but also all the OS (Operating System) tasks related to the CPU on the server.</p>
<p style="text-align:justify;">It is quite possible that although we are running very few operations on our SQL Server, we still do not obtain the expected results. This is when the SQL Server CPU has to be checked. Again, please note that I am not suggesting that the CPU is the root cause of poor performance in this case. There are ample chances that the Memory, Input/Output or Tempdb can be responsible for performance degradation. However, to find out the “real” culprit, we must run a test; here, we intend to start running tests on the CPU.</p>
<p style="text-align:justify;">Let us understand the simple meaning of CPU pressure. <strong><em>CPU pressure is a state wherein the CPU is fully occupied with currently assigned tasks and there are more tasks in the queue that have not yet started.</em></strong></p>
<p style="text-align:justify;">We can run several different types of queries to test the CPU. However, my personal favorite is the following one. The resultset will contain as many rows as those being used by the CPU SQL Server.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT<br />
</span><span style="color:black;">scheduler_id</span><span style="color:gray;">,<br />
</span><span style="color:black;">cpu_id</span><span style="color:gray;">,<br />
</span><span style="color:black;">current_tasks_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">runnable_tasks_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">current_workers_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">active_workers_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">work_queue_count</span><span style="color:gray;">,<br />
</span><span style="color:black;">pending_disk_io_count<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_schedulers<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">scheduler_id </span><span style="color:gray;">&lt; </span><span style="color:black;">255</span><span style="color:gray;">;</span></code>
</p>
<p style="text-align:justify;">Above query will give result something like following.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/cpupress.jpg" alt="" width="494" height="308" /></p>
<p style="text-align:justify;">Before we go ahead, let us familiarize ourselves with the terms. First of all, we should understand what a “scheduler” refers to in the SQL Server. Each SQL Server instance behaves and acts like any OS internally. It has schedules and also it synchronizes concurrent tasks by itself without going to OS. Each instance can handle many concurrent requests. However, there is a point at which the instance cannot accept any more requests. SQL Servers have dynamic management view (DMV), which in fact keeps a log of all the scheduler-related tasks and also it provides a good idea about the CPU pressure.</p>
<p style="text-align:justify;">current_tasks_count is the number of counts of the currently running task. However, we should give utmost consideration to runnable_tasks_count. If this number is higher, it indicates that a large number of queries, which are assigned to the scheduler for processing, are waiting for its turn to run. This gives a clear indication of the CPU pressure. Additionally, count pending_disk_io_count displays the tasks that are yet to be processed in the scheduler. For better processing, this count is expected not to be very high.</p>
<p style="text-align:justify;">When we say that the numbers are high or low, it does not make any sense unless we compare it to a standard or any other known count. Therefore, here, these numbers are compared to the worker counts (current_worker_count). If current_worker_count is 24 and there are 1000 tasks in queue, then this is not a good scenario. Thus, you can always look at the numbers and make your own judgement here.</p>
<p style="text-align:justify;">Well, in this article, I have done a lot of talking with very little script. Please do let me know your opinions regarding whether this was simple enough to convey the message regarding CPU pressure.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<p style="text-align:justify;">
Posted in Pinal Dave, SQL, SQL Authority, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL System Table, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/6601/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/6601/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/6601/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=6601&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/17/sql-server-measure-cpu-pressure-cpu-business/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/cpupress.jpg" medium="image" />
	</item>
		<item>
		<title>SQL Server &#8211; Understanding Table Hints with Examples</title>
		<link>http://blog.sqlauthority.com/2009/06/20/sql-server-%e2%80%93understanding-table-hints-with-examples/</link>
		<comments>http://blog.sqlauthority.com/2009/06/20/sql-server-%e2%80%93understanding-table-hints-with-examples/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 01:30:44 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Query Hint]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5645</guid>
		<description><![CDATA[Today we have a very interesting subject to look at. I tried to look for help online but have not found any other documentation besides what we have from the Book Online.
Let us try to understand what are the different kinds of hints available in SQL Server and how they are helpful.
What is a Hint?
Hints [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5645&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Today we have a very interesting subject to look at. I tried to look for help online but have not found any other documentation besides what we have from the Book Online.</p>
<p style="text-align:justify;">Let us try to understand what are the different kinds of hints available in SQL Server and how they are helpful.</p>
<p style="text-align:justify;"><strong>What is a Hint?</strong></p>
<p style="text-align:justify;"><em>Hints </em> are options and strong suggestions specified for enforcement by the SQL Server query processor on DML statements. The hints override any execution plan the query optimizer might select for a query.</p>
<p style="text-align:justify;">Before we continue to explore this subject, we need to consider one very important fact and say some words of caution. SQL Server Query optimizer is a very smart tool and it makes a best selection of execution plan. Suggesting hints to the Query Optimizer should be attempted when absolutely necessary and by experienced developers who know exactly what they are doing (or in development as a way to experiment and learn).</p>
<p style="text-align:justify;">There are three different kinds of hints. Let us understand the basics of each of them separately.</p>
<h3 style="text-align:justify;"><a href="http://dotnetslackers.com/articles/sql/SQL-Server-Understanding-Table-Hints-with-examples.aspx" target="_blank">Please continue reading article here.</a></h3>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL Joins, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology Tagged: Query Hint <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5645/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5645/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5645/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5645/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5645/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5645/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5645/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5645/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5645/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5645/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5645&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/20/sql-server-%e2%80%93understanding-table-hints-with-examples/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Clustered Index on Separate Drive From Table Location</title>
		<link>http://blog.sqlauthority.com/2009/06/18/sql-server-clustered-index-on-separate-drive-from-table-location/</link>
		<comments>http://blog.sqlauthority.com/2009/06/18/sql-server-clustered-index-on-separate-drive-from-table-location/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 01:30:39 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Optimization]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5491</guid>
		<description><![CDATA[How to improve performance of SQL Server Queries is a common topic of discussion among many of us. Much has been said, much has been discussed. Few days back, I had an interesting discussion with one of the Junior developers regarding performance improvement of SQL Server Queries. We discussed on how by using a separate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5491&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><strong>How to improve performance of SQL Server Queries</strong> is a common topic of discussion among many of us. Much has been said, much has been discussed. Few days back, I had an interesting discussion with one of the Junior developers regarding performance improvement of SQL Server Queries. We discussed on how by using a separate hard drive for several database objects can right away improve performance. I suggested him that non clustered index and tempdb can be created on a separate disk to improve performance.</p>
<p style="text-align:justify;">No sooner had I given my suggestion than I received a question &#8211; What will happen if we can create clustered index on a separate drive from the table on which it is built.</p>
<p style="text-align:justify;">My answer is : <strong>No! </strong>It is not possible at all.</p>
<p style="text-align:justify;">Let us first be clear about the difference between a clustered and a non clustered index.</p>
<p style="text-align:justify;"><strong>Clustered Index</strong></p>
<ul>
<li>Only 1 allowed per table</li>
<li>Physically rearranges data in the table to conform to the index constraints</li>
<li>For use on columns that are frequently searched for ranges of data</li>
<li>For use on columns with low selectivity</li>
</ul>
<p style="text-align:justify;"><strong>Non-Clustered Index</strong></p>
<ul>
<li>Up to 249 (for SQL Server 2005) and 999 (for SQL Server 2008) allowed per table</li>
<li>Creates a separate list of key values with pointers to the location of the data in the data pages</li>
<li>For use on columns that are searched for single values</li>
<li>For use on columns with high selectivity</li>
</ul>
<p style="text-align:justify;">A table devoid of primary key index is called heap, and here data is not arranged in a particular order, which gives rise to issues that adversely affect performance. Data must be stored in some kind of order. If we put clustered index on it then the order will be forced by that index and the data will be stored in that particular order.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.sqlauthority.com/" target="_blank"><strong>http://blog.sqlauthority.com</strong></a><strong>)</strong></p>
Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL Constraint and Keys, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5491/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5491/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5491/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5491&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/06/18/sql-server-clustered-index-on-separate-drive-from-table-location/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
	</channel>
</rss>