<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblogcasts.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SQL and the like - All Comments</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/default.aspx</link><description>Dave Ballantyne&amp;#39;s blog.  Freelance SQL Server database designer and developer at &lt;a href="http://www.clearskysql.co.uk"&gt;Clear Sky SQL&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>re: [BUG] Inserts to tables with an index view can fail</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2012/01/06/bug-inserts-to-index-views-can-fail.aspx#16070</link><pubDate>Sat, 07 Jan 2012 12:18:22 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16070</guid><dc:creator>Dave Ballantyne</dc:creator><description>&lt;p&gt;Hi Peter,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Hmm , thats a pretty tenuous piece of documentation :) &amp;nbsp;&lt;/p&gt;
&lt;p&gt;From a user perspective there should be no difference between using literal values and variables that is why im calling it a bug.&lt;/p&gt;
&lt;p&gt;Indeed, even if you :&lt;/p&gt;
&lt;p&gt;insert into myTable(Id,InView,SomeData)&lt;/p&gt;
&lt;p&gt;select 1,'N','a'&lt;/p&gt;
&lt;p&gt;union all&lt;/p&gt;
&lt;p&gt;select 1,'N','a'&lt;/p&gt;
&lt;p&gt;the problem also occurs.&lt;/p&gt;
&lt;p&gt;Im not seeing it as the same as your example , as there is a definate path of logic here that should be obeyed. &amp;nbsp;The calculation is only useful and can only be used if InView = 'Y'. &amp;nbsp;Though i doubt that this will be something simple to solve by the team.&lt;/p&gt;
&lt;p&gt;This also does make me think of the inefficiences here too, &amp;nbsp;the operations are firing when the output will not be used. &amp;nbsp;Maybe thats also something worth exploring later.&lt;/p&gt;
&lt;p&gt;Dave&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16070" width="1" height="1"&gt;</description></item><item><title>re: [BUG] Inserts to tables with an index view can fail</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2012/01/06/bug-inserts-to-index-views-can-fail.aspx#16069</link><pubDate>Sat, 07 Jan 2012 08:01:17 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16069</guid><dc:creator>Peso</dc:creator><description>&lt;p&gt;It's not really a bug, it's a feature and it's documented in Books Online for SQL Server 2005.&lt;/p&gt;
&lt;p&gt;See &amp;quot;Expressions in queries&amp;quot; here &lt;a rel="nofollow" target="_new" href="http://technet.microsoft.com/en-us/library/ms143359"&gt;technet.microsoft.com/.../ms143359&lt;/a&gt;(SQL.90).aspx&lt;/p&gt;
&lt;p&gt;See this example, which is the same thing.&lt;/p&gt;
&lt;p&gt;SELECT Column_Name&lt;/p&gt;
&lt;p&gt; from &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SELECT Column_Name&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select 'staff' as Column_Name union all&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select '234000' as Column_Name&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;) as Table_Name&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHERE &amp;nbsp; ISNUMERIC(Column_Name) = 1 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;) as d&lt;/p&gt;
&lt;p&gt; where &amp;nbsp; &amp;nbsp;CAST(Column_Name AS INT) &amp;lt;= 1000000&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16069" width="1" height="1"&gt;</description></item><item><title>re: Book review - SQL Server Secret Diary (Know the unknown secrets of SQL Server)</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2011/12/31/book-review-sql-server-secret-diary-know-the-unknown-secrets-of-sql-server.aspx#16063</link><pubDate>Thu, 05 Jan 2012 13:25:37 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16063</guid><dc:creator>GrumpyOldDBA</dc:creator><description>&lt;p&gt;As I know from a number of &amp;quot;discussions&amp;quot; I've had on blogs and forums you are correct in saying &amp;quot;It just depends&amp;quot;. I put it down to the joys of the internet whereby equal amounts of rubbish and quality can get the same coverage ( perhaps more rubbish to be honest! ). &lt;/p&gt;
&lt;p&gt;I've been asked many times to document how I go about performance tuning, say, a stored procedure. Trouble is it's just not linear and is full of if 1 or + 3 or 4 or if 6 and 7 then 2 so in the end it's just impossible to plot a logical path. It's easy to generalise but that hardly makes for such a book title.&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16063" width="1" height="1"&gt;</description></item><item><title>re: SQL 101 : Without “ORDER BY”, order is not guaranteed.</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2010/06/27/sql-101-without-order-by-order-is-not-guaranteed.aspx#16051</link><pubDate>Mon, 02 Jan 2012 18:02:07 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16051</guid><dc:creator>Dave Ballantyne</dc:creator><description>&lt;p&gt;Hi Paul, &amp;nbsp;sorry for the lateness of my reply.&lt;/p&gt;
&lt;p&gt;One possible way to reproduce is to delete a row and then insert a row, &amp;nbsp;this *should* then use the same row slot on the page and cause an unordered result set.&lt;/p&gt;
&lt;p&gt;drop &amp;nbsp;table #t1&lt;/p&gt;
&lt;p&gt;go&lt;/p&gt;
&lt;p&gt;create table #t1&lt;/p&gt;
&lt;p&gt;(&lt;/p&gt;
&lt;p&gt;id integer identity&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;
&lt;p&gt;go&lt;/p&gt;
&lt;p&gt;insert into #t1 default values&lt;/p&gt;
&lt;p&gt;go 2&lt;/p&gt;
&lt;p&gt;select * from #t1&lt;/p&gt;
&lt;p&gt;go&lt;/p&gt;
&lt;p&gt;delete from #t1 where id =1&lt;/p&gt;
&lt;p&gt;go&lt;/p&gt;
&lt;p&gt;insert into #t1 default values&lt;/p&gt;
&lt;p&gt;go&lt;/p&gt;
&lt;p&gt;select * from #t1&lt;/p&gt;
&lt;p&gt;As for heaps, well they are just a collection of rows with no order. &amp;nbsp;Any scan will start at page 0 and go through to page N following the page link chain...&lt;/p&gt;
&lt;p&gt;Hope that helps&lt;/p&gt;
&lt;p&gt;Dave&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16051" width="1" height="1"&gt;</description></item><item><title>re: Book review - SQL Server Secret Diary (Know the unknown secrets of SQL Server)</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2011/12/31/book-review-sql-server-secret-diary-know-the-unknown-secrets-of-sql-server.aspx#16050</link><pubDate>Mon, 02 Jan 2012 15:04:57 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16050</guid><dc:creator>aolcot</dc:creator><description>&lt;p&gt;I actually spent a couple of quid buying this book a few &amp;nbsp;months back and I agree with your comments that it isn't exactly the best and probably one to avoid in all honesty.&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16050" width="1" height="1"&gt;</description></item><item><title>re: Extended Events - inaccurate_cardinality_estimate</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2011/12/06/extended-events-inaccurate-cardinality-estimate.aspx#16000</link><pubDate>Tue, 06 Dec 2011 17:22:17 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:16000</guid><dc:creator>mcflyamorim</dc:creator><description>&lt;p&gt;Well done, I really liked this new xEvents... &lt;/p&gt;
&lt;p&gt;Voted.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
&lt;p&gt;Fabiano&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=16000" width="1" height="1"&gt;</description></item><item><title>re: SQL 101 : Without “ORDER BY”, order is not guaranteed.</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2010/06/27/sql-101-without-order-by-order-is-not-guaranteed.aspx#15989</link><pubDate>Tue, 29 Nov 2011 21:53:07 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:15989</guid><dc:creator>paulbarbin</dc:creator><description>&lt;p&gt;Great reference. &amp;nbsp;You are absolutely correct, and this is definitely 101 stuff. I've been preaching it to developers for decades(?). &amp;nbsp;But I appreciate the academics.&lt;/p&gt;
&lt;p&gt;My personal experience shows the execution plan pretty much dictates the order if ORDER BY isn't given. &amp;nbsp;That is, if a clustered index scan comes back in clustered index order. &amp;nbsp;Nonclustered index scans come back in nonclustered index order. &lt;/p&gt;
&lt;p&gt;I didn't realize parallelism would change the order but that certainly makes sense. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Finally, I thought perhaps a heap might always return the same order since I &amp;quot;THOUGHT&amp;quot; a table scan would just go in RowId order (i.e. the order they were inserted). &amp;nbsp;As any self respecting DBA, I would NEVER rely on this!&lt;/p&gt;
&lt;p&gt;But when troubleshooting a developer's code lately, I saw an issue that appeared to have been caused by an unordered resultset. &amp;nbsp;I am yet to actually prove it and I guess I was wondering two things. Is there anyway to reproduce the different ordering reliably? &amp;nbsp;And what is the technical reason why the order is different if it's a heap (temp table too)?&lt;/p&gt;
&lt;p&gt;Thanks, mainly just academic, but I'd really like to know.&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=15989" width="1" height="1"&gt;</description></item><item><title>re: Rows or Range, What’s the difference ?</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2011/09/22/rows-or-range-what-s-the-difference.aspx#15975</link><pubDate>Tue, 22 Nov 2011 20:50:44 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:15975</guid><dc:creator>mcflyamorim</dc:creator><description>&lt;p&gt;Hi Dave I only found your blog right now, congrats for the posts, I loved… lot of things to read :-).&lt;/p&gt;
&lt;p&gt;There is another difference I would like to mention, &lt;/p&gt;
&lt;p&gt;The execution plan window spool operator (used to process the window) as two ways for storing the frame data, on-disk or on-memory. Unfortunately the default frame (RANGE…) always use the on-disk window spool… the ROWS frame use an on-memory worktable if the number of rows is less than 10000 rows… If the number of rows is greater than 10k it will also use the on-disk spool.&lt;/p&gt;
&lt;p&gt;I saw in your video at SQLBits you said the FIRS_VALUE function was not good on performance… In fact the problem was that you were using the default frame (RANGE…) and it was using the on-disk window spool, if you change the frame to ROWS, it will be better than the old solution (CROSS APPLY) because it will use the on-memory window spool.&lt;/p&gt;
&lt;p&gt;You could use xEvents to capture the warning (window_spool_ondisk_warning), you can also see the difference between windows spooling on disks looking at the results of statistics io, the worktable will show lots of page reads.&lt;/p&gt;
&lt;p&gt;I think there are some scenarios where MS could change this behavior, for instance if the ORDER BY clause is unique (as in your sample) even if we use the RANGE frame we know we could use the ROWS and consequently use the in-memory worktable…&lt;/p&gt;
&lt;p&gt;Also, this 10000 number is fixed, I think it should use the same model on spill to disk if the memory grant has been exceeded, use an rowsize base to know how much memory to grant…&lt;/p&gt;
&lt;p&gt;I think this is something that could be improved on SQL2012.&lt;/p&gt;
&lt;p&gt;What do you think? &lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
&lt;p&gt;Fabiano N. Amorim - SQL Server MVP&lt;/p&gt;
&lt;p&gt;Twitter: @mcflyamorim │Blog: &lt;a rel="nofollow" target="_new" href="http://blogfabiano.com"&gt;http://blogfabiano.com&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=15975" width="1" height="1"&gt;</description></item><item><title>re: Denali Paging–Is it win/win ?</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2010/11/10/denali-paging-is-it-win-win.aspx#15043</link><pubDate>Thu, 11 Nov 2010 10:36:29 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:15043</guid><dc:creator>Dave Ballantyne</dc:creator><description>&lt;p&gt;Hi Steve, can i say , &amp;quot;it depends&amp;quot; ? :)&lt;/p&gt;
&lt;p&gt;I wouldnt say that there are hard and fast rules for a tipping point , its going to be down to data size etc.&lt;/p&gt;
&lt;p&gt;Maybe the most efficient method would be to use the denali functionality for 'low' pages but Paul's for 'high' pages. &amp;nbsp;Will make for more maint, but if it is being executed thousands of times , it should make a difference overall.&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=15043" width="1" height="1"&gt;</description></item><item><title>re: Denali Paging–Is it win/win ?</title><link>http://sqlblogcasts.com/blogs/sqlandthelike/archive/2010/11/10/denali-paging-is-it-win-win.aspx#15035</link><pubDate>Wed, 10 Nov 2010 21:46:30 GMT</pubDate><guid isPermaLink="false">fa8c4e8e-46a3-4193-8264-2c1a9cb3475d:15035</guid><dc:creator>steveh99999</dc:creator><description>&lt;p&gt;excellent bit of research Dave - was wondering, did you fnd out the tipping point where the new functionality starts to become less efficient ?&lt;/p&gt;
&lt;img src="http://sqlblogcasts.com/aggbug.aspx?PostID=15035" width="1" height="1"&gt;</description></item></channel></rss>
