<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.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>Alexander Kuznetsov</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>On filtered indexes and defensive coding</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/02/05/on-filtered-indexes-and-defensive-coding.aspx</link><pubDate>Fri, 05 Feb 2010 15:16:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:21875</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/21875.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=21875</wfw:commentRss><description>When one and the same constant is copied and pasted in more than one place, there is always a chance that we can change it in one place and fail to change in another, resulting in a discrepancy. For example, recently I read a very interesting post by...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/02/05/on-filtered-indexes-and-defensive-coding.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=21875" width="1" height="1"&gt;</description></item><item><title>Multi-statement TVFs are essentially slowish nested loops.</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/02/02/multiline-tvfs-are-essentially-slowish-nested-loops.aspx</link><pubDate>Tue, 02 Feb 2010 20:53:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:21727</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>8</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/21727.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=21727</wfw:commentRss><description>Whenever we are using multi-statement TVFs, we are essentially forcing nested loops logic on the database engine. Although multi-statement TVFs are smart enough and do not always execute once per row, when they do so, they may be much slower than nested...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/02/02/multiline-tvfs-are-essentially-slowish-nested-loops.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=21727" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Transact+SQL/default.aspx">Transact SQL</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Inline+UDFs/default.aspx">Inline UDFs</category></item><item><title>Don't swap horses in midstream.</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/02/01/don-t-swap-horses-in-midstream.aspx</link><pubDate>Mon, 01 Feb 2010 19:07:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:21671</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/21671.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=21671</wfw:commentRss><description>We can begin a transaction under snapshot isolation, but we cannot switch to it in the middle of an outstanding transaction. For example, the following procedure looks good and passes a smoke test: CREATE PROCEDURE dbo.SelectCountry @CountrySymbol CHAR...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/02/01/don-t-swap-horses-in-midstream.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=21671" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Transact+SQL/default.aspx">Transact SQL</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Defensive+programming/default.aspx">Defensive programming</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/snapshot+isolation/default.aspx">snapshot isolation</category></item><item><title>Correlated subqueries do not execute once per row.</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/01/20/correlated-subqueries-do-not-execute-once-per-row.aspx</link><pubDate>Wed, 20 Jan 2010 23:08:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:21292</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>12</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/21292.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=21292</wfw:commentRss><description>Correlated subqueries do not have to execute once per row - on the contrary, they are equivalent to outer joins, and they may have the same execution plans and the same real execution costs (if we retrieve only one column via a correlated subquery, of...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/01/20/correlated-subqueries-do-not-execute-once-per-row.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=21292" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Transact+SQL/default.aspx">Transact SQL</category></item><item><title>When acquiring locks in the same order is not possible or not feasible.</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/01/15/when-acquiring-locks-in-the-same-order-is-not-possible-or-not-feasible.aspx</link><pubDate>Fri, 15 Jan 2010 21:18:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:21095</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>6</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/21095.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=21095</wfw:commentRss><description>To avoid deadlocks, one of the most common recommendations is "to acquire locks in the same order" or "access objects in the same order". Clearly this makes perfect sense, but is it always feasible? Is it always possible? I keep encountering cases when...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/01/15/when-acquiring-locks-in-the-same-order-is-not-possible-or-not-feasible.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=21095" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Transact+SQL/default.aspx">Transact SQL</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Defensive+programming/default.aspx">Defensive programming</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Deadlocks/default.aspx">Deadlocks</category></item><item><title>T-SQL Tuesday #002: patterns that do not work as expected.</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/01/12/t-sql-tuesday-002-patterns-that-do-not-work-as-expected.aspx</link><pubDate>Tue, 12 Jan 2010 14:38:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:20931</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>11</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/20931.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=20931</wfw:commentRss><description>Neither UPDATE … IF (@@ROWCOUNT = 0) INSERT nor IF EXISTS(...) UPDATE ELSE INSERT patterns work as expected under high concurrency. Both may fail. Both may fail very frequently. MERGE is the king - it holds up much better.Let us do some stress testing...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/01/12/t-sql-tuesday-002-patterns-that-do-not-work-as-expected.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=20931" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Transact+SQL/default.aspx">Transact SQL</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Defensive+programming/default.aspx">Defensive programming</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Stress+Testing/default.aspx">Stress Testing</category></item><item><title>Retrying after deadlocks leads to lost updates</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/01/08/retrying-after-deadlocks-leads-to-lost-updates.aspx</link><pubDate>Fri, 08 Jan 2010 15:15:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:20732</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>2</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/20732.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=20732</wfw:commentRss><description>When we retry after deadlocks, we are very likely to overwrite other processes' changes. We need to be aware that very likely someone else modified the data we intended to modify. Especially if all the readers run under snapshot isolation, then readers...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2010/01/08/retrying-after-deadlocks-leads-to-lost-updates.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=20732" width="1" height="1"&gt;</description></item><item><title>To design or not to design?</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/12/08/to-design-or-not-to-design.aspx</link><pubDate>Tue, 08 Dec 2009 22:18:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:19646</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/19646.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=19646</wfw:commentRss><description>Clearly Linux is one of the most successful products ever. Let me quote a little bit from Linus Torvalds and other brilliant people involved in it: "A strong vision and a sure hand sound like good things on paper. It's just that I have never _ever_ met...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/12/08/to-design-or-not-to-design.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=19646" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Agile+Development/default.aspx">Agile Development</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Database+Design/default.aspx">Database Design</category></item><item><title>T-SQL Tuesday #001: Yesterday it worked, today it's not working...</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/12/08/t-sql-tuesday-001-yesterday-it-worked-today-it-s-not-working.aspx</link><pubDate>Tue, 08 Dec 2009 16:06:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:19623</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/19623.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=19623</wfw:commentRss><description>But did it actually work yesterday? If the day is Friday, Noverber 13th, or the 13th day of any other month, and your query blows up for the first time, one place to search for is character strings converted to datetime values. The following script illustrates...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/12/08/t-sql-tuesday-001-yesterday-it-worked-today-it-s-not-working.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=19623" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/T-SQL+Tuesday/default.aspx">T-SQL Tuesday</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/datetime/default.aspx">datetime</category></item><item><title>PIVOting dense data may speed up your queires</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/11/20/pivoting-dense-data-may-speed-up-your-queires.aspx</link><pubDate>Fri, 20 Nov 2009 18:53:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:19040</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>1</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/19040.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=19040</wfw:commentRss><description>Of course, PIVOting uses up some CPU. However, if the data is dense (all the cells in the pivoted result set are not NULL), then the size of the pivoted result set may be significantly less. As a result, the overall time to retrieve a pivoted result set...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/11/20/pivoting-dense-data-may-speed-up-your-queires.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=19040" width="1" height="1"&gt;</description></item><item><title>Speaking in Chicago on Sep 10</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/08/17/speaking-in-chicago-on-sep-10.aspx</link><pubDate>Mon, 17 Aug 2009 20:31:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:16076</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/16076.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=16076</wfw:commentRss><description>I'll be speaking about Defensive Database Programming in Chicago on Sep 10 at 5:30PM. http://chicago.sqlpass.org/ The seating is limited to 50, You must RSVP to attend Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/08/17/speaking-in-chicago-on-sep-10.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=16076" width="1" height="1"&gt;</description></item><item><title>When you add an index and your query blows up...</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/07/16/when-you-add-an-index-and-your-query-blows-up.aspx</link><pubDate>Thu, 16 Jul 2009 21:39:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15300</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>3</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/15300.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=15300</wfw:commentRss><description>You cannot assume that the conditions in your WHERE clause will evaluate in the left-to-write order - making such assumptions leads to unsafe queries. For example, the following query is not safe: SELECT * FROM dbo.Messages WHERE ISDATE ( VarcharColumn...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/07/16/when-you-add-an-index-and-your-query-blows-up.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=15300" width="1" height="1"&gt;</description></item><item><title>Saving the whole team of players or nothing</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/07/15/saving-the-whole-team-or-nothing.aspx</link><pubDate>Wed, 15 Jul 2009 18:28:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15288</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/15288.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=15288</wfw:commentRss><description>Suppose that you need to store teams of players, and you must enforce the following business rule: each team must consist of exactly two players. I will demonstrate how you can use constraints to implement this rule. I haven't used this approach in production...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/07/15/saving-the-whole-team-or-nothing.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=15288" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Transact+SQL/default.aspx">Transact SQL</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Business+rules/default.aspx">Business rules</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/constraints/default.aspx">constraints</category></item><item><title>Optimizing yet another query that involves highly correlated columns</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/07/13/optimizing-yet-another-query-that-involves-highly-correlated-columns.aspx</link><pubDate>Mon, 13 Jul 2009 22:15:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15251</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>2</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/15251.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=15251</wfw:commentRss><description>In some cases some of the columns involved in a query are highly correlated. If you manage to communicate to the optimizer that valuable information, it may come up with a more efficient plan. For example, consider the following table (the script that...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/07/13/optimizing-yet-another-query-that-involves-highly-correlated-columns.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=15251" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/Transact+SQL/default.aspx">Transact SQL</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/query+performance/default.aspx">query performance</category></item><item><title>Using CROSS APPLY to optimize joins on BETWEEN conditions</title><link>http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/07/07/using-cross-apply-to-optimize-joins-on-between-conditions.aspx</link><pubDate>Wed, 08 Jul 2009 00:47:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15148</guid><dc:creator>Alexander Kuznetsov</dc:creator><slash:comments>12</slash:comments><comments>http://sqlblog.com/blogs/alexander_kuznetsov/comments/15148.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/alexander_kuznetsov/commentrss.aspx?PostID=15148</wfw:commentRss><description>Recently I encountered a case when I knew much more about the data than the optimizer. Originally the performance was horrible, this is why I had to have a look at the query in the first place. When I was able to share my knowledge with the optimizer,...(&lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/07/07/using-cross-apply-to-optimize-joins-on-between-conditions.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=15148" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://sqlblog.com/blogs/alexander_kuznetsov/archive/tags/query+performance/default.aspx">query performance</category></item></channel></rss>