<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.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>Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx</link><description>Continuing in my series of things you should probably not do in SQL Server but sometimes have to , I'm going to do a few posts on dealing with very large bitmasks. Let me first state my utter hatered of bitmasks in databases. I think they're annoying,</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#3575</link><pubDate>Thu, 29 Nov 2007 03:29:01 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3575</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;I appreciate your binary examples. &amp;nbsp;One of the things that perplexes me as a previous application developer turned sql developer is that all of your examples would be better handled on the client side. &amp;nbsp;Some of your code...especially the use of a numbers table...is extremely innovative. &amp;nbsp;But, in a total solution I don't see why I would use the database to handle any of them. &amp;nbsp;Don't mean to be harsh...but i could see a carpenter build a nice space shuttle with wood... I just don't see it getting far.&lt;/p&gt;
</description></item><item><title>re: Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#3672</link><pubDate>Tue, 04 Dec 2007 15:30:36 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3672</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Jason:&lt;/p&gt;
&lt;p&gt;As I mention several times in the post, I do not recommend actually using this technique, for several reasons. &amp;nbsp;That said, it is certainly not hard to think of scenarios where one might want to do these kinds of things in the database. &amp;nbsp;Think encapsulation. &amp;nbsp;If -- for some very, very good reason -- you need to use bitmasks in the database, but perhaps don't need to expose the bitmasks to the application, you can and should do this work in the database in order to keep the application and database as loosely coupled as possible.&lt;/p&gt;
&lt;p&gt;I am all for handling tasks wherever they are best suited, but I'm an even bigger fan of highly modular designs. &amp;nbsp;So if I can keep the application ignorant of some hack I've worked up in the database, all the better...&lt;/p&gt;
</description></item><item><title>Correction on bitmask handling</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#11438</link><pubDate>Sun, 25 Jan 2009 19:46:07 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11438</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;In the article on handling bitmasks I posted the other day, I made a fatal error in the splitBitmask&lt;/p&gt;
</description></item><item><title>Bitmask Handling, part 2: Bitmask reconstitution</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#11439</link><pubDate>Sun, 25 Jan 2009 19:47:50 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11439</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Posting the first part of my series on bitmasks (yes, this is now officially a series) taught me a lot&lt;/p&gt;
</description></item><item><title>Bitmask Handling, part 3: Logical operators</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#11442</link><pubDate>Sun, 25 Jan 2009 19:50:20 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11442</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;It's been longer than I hoped since my last installment on bitmask / big number handling . Life caught&lt;/p&gt;
</description></item><item><title>re: Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#26244</link><pubDate>Thu, 17 Jun 2010 19:25:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26244</guid><dc:creator>Derek</dc:creator><description>&lt;p&gt;Just FYI Adam, I love this article. &amp;nbsp;I've been here hundreds of times so attribute a lot of traffic to me!&lt;/p&gt;
</description></item><item><title>re: Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#26286</link><pubDate>Sat, 19 Jun 2010 11:36:02 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26286</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Glad you enjoyed it. You know you can simply print it, frame it, and hang it on the wall, right? :-)&lt;/p&gt;
</description></item><item><title>re: Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#40623</link><pubDate>Fri, 23 Dec 2011 22:08:40 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40623</guid><dc:creator>David</dc:creator><description>&lt;p&gt;We do use large bitmasks in our database - and until now, we've handled them via SQL CLR, making all processing rather fast. However, with SQL Azure, CLR is no longer an option, at least for now. I tried re-implementing some of our bitmask user-defined functions in SQL basing myself on your wonderful articles and the bitmask reconstruction operation seems to be much slower than its SQL CLR counterpart. Do you think the bad performance is an intrinsic property of the bitmask reconstruction, or is there room for optimization?&lt;/p&gt;
</description></item><item><title>re: Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#40630</link><pubDate>Sat, 24 Dec 2011 03:19:32 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40630</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi David,&lt;/p&gt;
&lt;p&gt;It seems natural that a CLR approach would work much better--it's a very CPU-heavy operation, and CLR functions almost always deliver higher performance in those cases. Is it so much slower that it's unbearable?&lt;/p&gt;
&lt;p&gt;I originally wrote all of this stuff 7 or 8 years ago, so I'm not going to be able to give you a great answer about improvements without doing some testing. But taking a quick look at it, I'm thinking that yes, there is some room for optimization -- perhaps by using some of the XQuery methods that were added in SQL Server 2005. Are those available in Azure? I've luckily managed to avoid having to use it, to date!&lt;/p&gt;
&lt;p&gt;--Adam&lt;/p&gt;
</description></item><item><title>re: Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/dealing-with-very-large-bitmasks.aspx#40793</link><pubDate>Wed, 04 Jan 2012 00:10:56 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40793</guid><dc:creator>David</dc:creator><description>&lt;p&gt;The performance degradation is significant even for the binary mask creation. Consider the following:&lt;/p&gt;
&lt;p&gt;select Data, fnCreateBinaryMark(40) from SomeTable&lt;/p&gt;
&lt;p&gt;Which would create a binary mask of 40 bytes for each row of the table.&lt;/p&gt;
&lt;p&gt;For a table containing ~4000 rows, the SQL CLR version runs in less than a second while the purely SQL version takes 6 seconds.&lt;/p&gt;
&lt;p&gt;Since the binary mask creation is simply the concatenation if table variable values and &amp;nbsp;since the re-construction of the varbinary from a table already seems to be a costly operation, I have a feeling I would not be able to build performant bit operation functions, since it's the mandatory final step.&lt;/p&gt;
&lt;p&gt;I do believe XQuery is available on Azure, but not sure how it can help - afaik, bit operations are not part of XPath/XQuery.&lt;/p&gt;
</description></item></channel></rss>