{"id":726,"date":"2010-04-06T08:28:00","date_gmt":"2010-04-06T08:28:00","guid":{"rendered":"\/blogs\/paul\/post\/A-SQL-Server-DBA-myth-a-day-(630)-three-null-bitmap-myths.aspx"},"modified":"2017-08-01T10:39:56","modified_gmt":"2017-08-01T17:39:56","slug":"a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/","title":{"rendered":"A SQL Server DBA myth a day: (6\/30) three null bitmap myths"},"content":{"rendered":"<p style=\"text-align: justify;\">(Look in the <a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/category\/misconceptions\/\">Misconceptions<\/a> blog category for the rest of the month&#8217;s posts and check out the 60-page PDF with all the myths and misconceptions blog posts collected together when you join our <a href=\"https:\/\/www.sqlskills.com\/join-the-sqlskills-insider-community\/\" target=\"_blank\" rel=\"noopener noreferrer\">Insider list<\/a>, plus my online <a href=\"https:\/\/www.pluralsight.com\/courses\/sqlserver-myths\" target=\"_blank\" rel=\"noopener noreferrer\">Myths and Misconceptions training course<\/a> on Pluralsight.)<\/p>\n<p style=\"text-align: justify;\">Today&#8217;s myth is a multi-parter especially for the folks in the Designing for Performance class that Kimberly&#8217;s teaching on the MS campus today &#8211; hellooooo!<\/p>\n<p style=\"text-align: justify;\">The null bitmap keeps track of which columns in a record are null or not. It exists as a performance optimization to allow the Storage Engine to avoid having to read all of a record into the CPU when null columns are part of the <em>SELECT<\/em> list &#8211; thus minimizing CPU cache line invalidations (checkout <a href=\"https:\/\/en.wikipedia.org\/wiki\/MESI_protocol\">this link<\/a> for details of how CPU memory caches work\u00a0and the MESI protocol). There are three pervasive myths to debunk here:<\/p>\n<p><strong>Myth #6a:<\/strong> <em>The null bitmap isn&#8217;t always present.<\/em><\/p>\n<p><span style=\"text-decoration: underline;\"><strong><em>TRUE<\/em><\/strong><\/span><\/p>\n<p style=\"text-align: justify;\">The null bitmap is *always* present in data records (in heaps or the leaf-level of clustered indexes) &#8211; even if the table has no nullable columns &#8211; except in the special case where the record is only made up of non-NULL SPARSE columns. The null bitmap is *not* always present in index records (leaf level of nonclustered indexes, and non-leaf levels of clustered and nonclustered indexes).<\/p>\n<p>Here&#8217;s a simple script to prove it:<\/p>\n<pre class=\"brush: sql; title: ; toolbar: true; wrap-lines: true; notranslate\" title=\"\">\r\nCREATE TABLE &#x5B;NullTest] (&#x5B;c1] INT NOT NULL);\r\nCREATE NONCLUSTERED INDEX &#x5B;NullTest_NC] ON &#x5B;NullTest] (&#x5B;c1]);\r\nGO\r\nINSERT INTO &#x5B;NullTest] VALUES (1);\r\nGO\r\n\r\nEXEC sp_allocationMetadata N'NullTest';\r\nGO\r\n<\/pre>\n<p style=\"text-align: justify;\">You can get my <em>sp_allocationMetadata<\/em> script from\u00a0my\u00a0post <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/inside-the-storage-engine-sp_allocationmetadata-putting-undocumented-system-catalog-views-to-work\/\" target=\"_blank\" rel=\"noopener noreferrer\">Inside The Storage Engine: sp_AllocationMetadata &#8211; putting undocumented system catalog views to work<\/a><\/em>.<\/p>\n<p>Use the page IDs in the output from the script in the <em>First Page<\/em> column. Do the following:<\/p>\n<pre class=\"brush: sql; title: ; toolbar: true; wrap-lines: true; notranslate\" title=\"\">\r\nDBCC TRACEON (3604);\r\nDBCC PAGE (foo, 1, 152, 3); -- page ID from SP output where Index ID = 0\r\nDBCC PAGE (foo, 1, 154, 1); -- page ID from SP output where Index ID = 2\r\nGO\r\n<\/pre>\n<p>From the first <em>DBCC PAGE<\/em> dump of the heap data record:<\/p>\n<pre class=\"brush: plain; gutter: false; title: ; toolbar: true; wrap-lines: true; notranslate\" title=\"\">\r\nSlot 0 Offset 0x60 Length 11\r\n\r\nRecord Type = PRIMARY_RECORD         Record Attributes =  NULL_BITMAP\r\nMemory Dump @0x685DC060\r\n<\/pre>\n<p>From the second <em>DBCC PAGE<\/em> dump of the nonclustered index\u00a0record:<\/p>\n<pre class=\"brush: plain; gutter: false; title: ; toolbar: true; wrap-lines: true; notranslate\" title=\"\">\r\nSlot 0, Offset 0x60, Length 13, DumpStyle BYTE\r\n\r\nRecord Type = INDEX_RECORD           Record Attributes = No null bitmap\r\nMemory Dump @0x685DC060\r\n<\/pre>\n<p><strong>Myth #6b:<\/strong> <em>The null bitmap only contains bits for nullable columns.<\/em><\/p>\n<p><span style=\"text-decoration: underline;\"><strong><em>FALSE<\/em><\/strong><\/span><\/p>\n<p style=\"text-align: justify;\">The null bitmap, when present, contains bits for all columns in the record, plus &#8216;filler&#8217; bits for non-existent columns to make up complete bytes in the null bitmap. I already debunked this one with a long internals blog post last May &#8211; see <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-null-bitmap-size\/\" target=\"_blank\" rel=\"noopener noreferrer\">Misconceptions around null bitmap size<\/a><\/em>.<\/p>\n<p><strong>Myth #6c:<\/strong> <em>Adding another column to the table always results in an immediate size-of-data operation.<\/em><\/p>\n<p><span style=\"text-decoration: underline;\"><strong><em>FALSE<\/em><\/strong><\/span><\/p>\n<p style=\"text-align: justify;\">The only times that adding a column to a table results in a size-of-data operation (i.e. an operation that modifies every row in a table) are:<\/p>\n<ul>\n<li>When the new column has a non-null default and is not nullable<\/li>\n<li style=\"text-align: justify;\">When the new column has a non-null default, IS nullable, and you&#8217;re using SQL Server 2008 R2 or earlier<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">In all other cases, the Storage Engine remembers that there are one or more additional columns that may not actually be present in the records themselves. I explained this in a little more depth in the blog post <em><a href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/misconceptions-around-adding-columns-to-a-table\/\" target=\"_blank\" rel=\"noopener noreferrer\">Misconceptions around adding columns to a table<\/a><\/em>.<\/p>\n<p>Back to a single myth-a-day for tomorrow &#8211; today was a bulk-bin special!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Look in the Misconceptions blog category for the rest of the month&#8217;s posts and check out the 60-page PDF with all the myths and misconceptions blog posts collected together when you join our Insider list, plus my online Myths and Misconceptions training course on Pluralsight.) Today&#8217;s myth is a multi-parter especially for the folks in [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,61],"tags":[],"class_list":["post-726","post","type-post","status-publish","format-standard","hentry","category-inside-the-storage-engine","category-misconceptions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A SQL Server DBA myth a day: (6\/30) three null bitmap myths - Paul S. Randal<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A SQL Server DBA myth a day: (6\/30) three null bitmap myths - Paul S. Randal\" \/>\n<meta property=\"og:description\" content=\"(Look in the Misconceptions blog category for the rest of the month&#8217;s posts and check out the 60-page PDF with all the myths and misconceptions blog posts collected together when you join our Insider list, plus my online Myths and Misconceptions training course on Pluralsight.) Today&#8217;s myth is a multi-parter especially for the folks in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/\" \/>\n<meta property=\"og:site_name\" content=\"Paul S. Randal\" \/>\n<meta property=\"article:published_time\" content=\"2010-04-06T08:28:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-08-01T17:39:56+00:00\" \/>\n<meta name=\"author\" content=\"Paul Randal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Randal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/\",\"name\":\"A SQL Server DBA myth a day: (6\/30) three null bitmap myths - Paul S. Randal\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\"},\"datePublished\":\"2010-04-06T08:28:00+00:00\",\"dateModified\":\"2017-08-01T17:39:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A SQL Server DBA myth a day: (6\/30) three null bitmap myths\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/\",\"name\":\"Paul S. Randal\",\"description\":\"In Recovery...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce\",\"name\":\"Paul Randal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g\",\"caption\":\"Paul Randal\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/paul\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A SQL Server DBA myth a day: (6\/30) three null bitmap myths - Paul S. Randal","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/","og_locale":"en_US","og_type":"article","og_title":"A SQL Server DBA myth a day: (6\/30) three null bitmap myths - Paul S. Randal","og_description":"(Look in the Misconceptions blog category for the rest of the month&#8217;s posts and check out the 60-page PDF with all the myths and misconceptions blog posts collected together when you join our Insider list, plus my online Myths and Misconceptions training course on Pluralsight.) Today&#8217;s myth is a multi-parter especially for the folks in [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/","og_site_name":"Paul S. Randal","article_published_time":"2010-04-06T08:28:00+00:00","article_modified_time":"2017-08-01T17:39:56+00:00","author":"Paul Randal","twitter_misc":{"Written by":"Paul Randal","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/","name":"A SQL Server DBA myth a day: (6\/30) three null bitmap myths - Paul S. Randal","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website"},"datePublished":"2010-04-06T08:28:00+00:00","dateModified":"2017-08-01T17:39:56+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/a-sql-server-dba-myth-a-day-630-three-null-bitmap-myths\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/paul\/"},{"@type":"ListItem","position":2,"name":"A SQL Server DBA myth a day: (6\/30) three null bitmap myths"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/paul\/","name":"Paul S. Randal","description":"In Recovery...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/paul\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/ffcec826c18782e1e0adf173826a7fce","name":"Paul Randal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/paul\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b6a266bba2f088f2551ef529293001bd73bf026bc1908b9866728c062beeeb6?s=96&d=mm&r=g","caption":"Paul Randal"},"sameAs":["http:\/\/3.209.169.194\/blogs\/paul"],"url":"https:\/\/www.sqlskills.com\/blogs\/paul\/author\/paul\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/comments?post=726"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/posts\/726\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/media?parent=726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/categories?post=726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/paul\/wp-json\/wp\/v2\/tags?post=726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}