{"id":2201,"date":"2014-03-12T11:00:24","date_gmt":"2014-03-12T15:00:24","guid":{"rendered":"http:\/\/sqlity.net\/en\/?p=2201"},"modified":"2014-11-13T13:41:05","modified_gmt":"2014-11-13T18:41:05","slug":"row-header","status":"publish","type":"post","link":"https:\/\/sqlity.net\/en\/2201\/row-header\/","title":{"rendered":"The Row Header (A Storage Wednesday Post)"},"content":{"rendered":"<div>\n<h3>Introduction<\/h3>\n<p>\nIn February 2014, I started the Storage Wednesday series. Since then I have written every Wednesday about the way SQL Server stores and accesses data. The list of posts can be found at the end of the first one: <a href=\"http:\/\/sqlity.net\/en\/2033\/the-page\/\">The Page<\/a>.\n<\/p>\n<p>\nIn continuation of the Storage Wednesday series, today I would like to invite you to discover the way a single row is organized within a data page. (The data page was introduced in <a href=\"http:\/\/sqlity.net\/en\/2134\/row-offset-array\/\">The Row Offset Array<\/a>.)\n<\/p>\n<h3>Row Header Example<\/h3>\n<p>\nTo dive into the row header, we need a table with a few columns, some based on a fixed length data type and some based on a variable length data type. I am going to use this table structure:\n<\/p>\n<div>\n[sql]\nIF OBJECT_ID('dbo.tst') IS NOT NULL DROP TABLE dbo.tst;<br \/>\nCREATE TABLE dbo.tst (<br \/>\n   id INT IDENTITY(1, 1)<br \/>\n          PRIMARY KEY CLUSTERED,<br \/>\n   Col2 INT DEFAULT CHECKSUM(NEWID()),<br \/>\n   Col3 DATETIME2 DEFAULT SYSUTCDATETIME(),<br \/>\n   Col4 VARCHAR(2200)<br \/>\n    DEFAULT ( REPLICATE('4', 1 + ABS(CHECKSUM(NEWID()) % 10)) ),<br \/>\n   Col5 VARCHAR(2200)<br \/>\n    DEFAULT ( REPLICATE('5', 1 + ABS(CHECKSUM(NEWID()) % 10)) )<br \/>\n  );<br \/>\nINSERT INTO dbo.tst(Col3)SELECT SYSUTCDATETIME() FROM sys.columns;<br \/>\n[\/sql]\n<\/div>\n<p>\nThis SQL batch (re-)creates the <span class=\"tt\">dbo.tst<\/span> table and also inserts a few rows into it. The inserted strings in <span class=\"tt\">Col4<\/span> and <span class=\"tt\">Col5<\/span> have a random length, so you will see different lengths in every row.\n<\/p>\n<p>\nLet us look at the first page. In my case the first page is page 1:282 and I am going to use <span class=\"tt\">DBCC PAGE<\/span> with display type 3:\n<\/p>\n<div>\n[sql]\nDBCC TRACEON(3604);<br \/>\nDBCC PAGE(0,1,282,3);<br \/>\n[\/sql]\n<\/div>\n<p>\nThe output of these statements is too long to include here. However, for each row on the page you will find a section like this:\n<\/p>\n<div>\n[sourcecode]\nRecord Type = PRIMARY_RECORD        Record Attributes =  NULL_BITMAP VARIABLE_COLUMNS<br \/>\nRecord Size = 42<br \/>\nMemory Dump @0x000000006F36A060<\/p>\n<p>0000000000000000:   30001400 01000000 f32daf6b 6d7579d1 073e380b  0.......\u00f3-\u00afkmuy\u00d1.&gt;8.<br \/>\n0000000000000014:   05000002 0027002a 00343434 34343434 34343435  .....'.*.44444444445<br \/>\n0000000000000028:   3535                                          55     <\/p>\n<p>Slot 0 Column 1 Offset 0x4 Length 4 Length (physical) 4<\/p>\n<p>id = 1                              <\/p>\n<p>Slot 0 Column 2 Offset 0x8 Length 4 Length (physical) 4<\/p>\n<p>Col2 = 1806642675                   <\/p>\n<p>Slot 0 Column 3 Offset 0xc Length 8 Length (physical) 8<\/p>\n<p>Col3 = 2014-03-03 00:55:57.9169133  <\/p>\n<p>Slot 0 Column 4 Offset 0x1d Length 10 Length (physical) 10<\/p>\n<p>Col4 = 4444444444                   <\/p>\n<p>Slot 0 Column 5 Offset 0x27 Length 3 Length (physical) 3<\/p>\n<p>Col5 = 555                          <\/p>\n<p>Slot 0 Offset 0x0 Length 0 Length (physical) 0<\/p>\n<p>KeyHashValue = (8194443284a0)<br \/>\nSlot 1 Offset 0x8a Length 47<br \/>\n[\/sourcecode]\n<\/p><\/div>\n<p>\nThis output separates all the values for easier digestion. However, it does not cover the entire row header. The complete row data looks like this:\n<\/p>\n<div>\n[sourcecode]\n0000000000000000:   30001400 01000000 f32daf6b 6d7579d1 073e380b  0.......\u00f3-\u00afkmuy\u00d1.&gt;8.<br \/>\n0000000000000014:   05000002 0027002a 00343434 34343434 34343435  .....'.*.44444444445<br \/>\n0000000000000028:   3535                                          55<br \/>\n[\/sourcecode]\n<\/div>\n<p>\nThe row header is split into two pieces, separated from each other by the fixed length column values. The first two bytes, <span class=\"tt\">0x3000<\/span> in our case, contain status bits. This value indicates the type of row and whether the row contains variable length data.\n<\/p>\n<p>\nThe next two bytes, <span class=\"tt\">0x1400<\/span> in the example, is a pointer to the start of the second half of the header. Remember that al vaues are stored n reverse byte order, so this entry actually means <span class=\"tt\">0x14<\/span> or 20. The remaining bytes of the first row in this output (<span class=\"tt\">01000000 f32daf6b 6d7579d1 073e380b<\/span>) contain the values for the fixed length columns <span class=\"tt\">id<\/span>, <span class=\"tt\">Col2<\/span> and <span class=\"tt\">Col3<\/span>. The first two columns are of data type <span class=\"tt\">INT<\/span> and take four bytes each, <span class=\"tt\">Col3<\/span> is a <span class=\"tt\">DATETIME2<\/span> column and uses eight bytes.\n<\/p>\n<p>\nStarting with byte <span class=\"tt\">0x14<\/span> we have two bytes that contain the number of columns in the row (<span class=\"tt\">0x0500<\/span>). After that follows the NULL-bitmap. The NULL-bitmap contains one bit for each column in the row. That means the length of the NULL-bitmap is one byte for every eight columns in the row.\n<\/p>\n<p>\nFollowing the NULL-bitmap, at position <span class=\"tt\">0x17<\/span> in our example is the variable length section of the row. It is completely omitted if the row does not contain variable length columns. It starts with a two-byte field that contains the number of variable lengths columns (<span class=\"tt\">0x0200<\/span>). It is followed by as many two-byte pointers, each pointing to the first byte after the respective variable length column. The variable length values follow right after those pointers, starting a position <span class=\"tt\">0x1d<\/span> in the example.\n<\/p>\n<p>\nIn total, there are six bytes in the header, plus the NULL-bitmap and plus the variable length column offset array that starts out with a two byte count. Every row in SQL Server 2012 has a NULL-bitmap (in some earlier versions that was optional), so the minimum header length is seven bytes if the row consists of less <span class=\"tt\"><\/span><=8[\/tt] columns and no column is of a variable length data type.\n<\/p>\n<h3>Summary<\/h3>\n<p>\nEvery row in SQL Server has its own header, the row header. It contains metadata describing the record and is at least seven bytes in length.\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The row header contains metadata describing the row. It contains information about the row type, the column count and  a NULL-bitmap. Read on to get all the details.<\/p>\n<p> <a href=\"https:\/\/sqlity.net\/en\/2201\/row-header\/\">[more&#8230;]<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5,27,14,105],"tags":[111,107,128,15,109],"class_list":["post-2201","post","type-post","status-publish","format-standard","hentry","category-general","category-series","category-sql-server-internals","category-storage-wednesday","tag-dbcc-page","tag-page","tag-row-header","tag-sql-server","tag-storage-engine"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Row Header (A Storage Wednesday Post) - sqlity.net<\/title>\n<meta name=\"description\" content=\"The row header contains metadata describing the row. It contains information about the row type, the column count and a NULL-bitmap. Read on to get all the details.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sqlity.net\/en\/2201\/row-header\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Row Header (A Storage Wednesday Post) - sqlity.net\" \/>\n<meta property=\"og:description\" content=\"The row header contains metadata describing the row. It contains information about the row type, the column count and a NULL-bitmap. Read on to get all the details.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sqlity.net\/en\/2201\/row-header\/\" \/>\n<meta property=\"og:site_name\" content=\"sqlity.net\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/sqlity.net\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-12T15:00:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-13T18:41:05+00:00\" \/>\n<meta name=\"author\" content=\"Sebastian Meine\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sqlity\" \/>\n<meta name=\"twitter:site\" content=\"@sqlity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Meine\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/\"},\"author\":{\"name\":\"Sebastian Meine\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"headline\":\"The Row Header (A Storage Wednesday Post)\",\"datePublished\":\"2014-03-12T15:00:24+00:00\",\"dateModified\":\"2014-11-13T18:41:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/\"},\"wordCount\":771,\"commentCount\":0,\"keywords\":[\"DBCC PAGE\",\"page\",\"Row Header\",\"SQL Server\",\"storage engine\"],\"articleSection\":[\"General\",\"Series\",\"SQL Server Internals\",\"Storage Wednesday\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/\",\"name\":\"The Row Header (A Storage Wednesday Post) - sqlity.net\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\"},\"datePublished\":\"2014-03-12T15:00:24+00:00\",\"dateModified\":\"2014-11-13T18:41:05+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"description\":\"The row header contains metadata describing the row. It contains information about the row type, the column count and a NULL-bitmap. Read on to get all the details.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2201\\\/row-header\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Row Header (A Storage Wednesday Post)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\",\"name\":\"sqlity.net\",\"description\":\"Quality for SQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sqlity.net\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\",\"name\":\"Sebastian Meine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"caption\":\"Sebastian Meine\"},\"sameAs\":[\"http:\\\/\\\/sqlity.net\",\"https:\\\/\\\/x.com\\\/sqlity\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Row Header (A Storage Wednesday Post) - sqlity.net","description":"The row header contains metadata describing the row. It contains information about the row type, the column count and a NULL-bitmap. Read on to get all the details.","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:\/\/sqlity.net\/en\/2201\/row-header\/","og_locale":"en_US","og_type":"article","og_title":"The Row Header (A Storage Wednesday Post) - sqlity.net","og_description":"The row header contains metadata describing the row. It contains information about the row type, the column count and a NULL-bitmap. Read on to get all the details.","og_url":"https:\/\/sqlity.net\/en\/2201\/row-header\/","og_site_name":"sqlity.net","article_publisher":"https:\/\/www.facebook.com\/sqlity.net","article_published_time":"2014-03-12T15:00:24+00:00","article_modified_time":"2014-11-13T18:41:05+00:00","author":"Sebastian Meine","twitter_card":"summary_large_image","twitter_creator":"@sqlity","twitter_site":"@sqlity","twitter_misc":{"Written by":"Sebastian Meine","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sqlity.net\/en\/2201\/row-header\/#article","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/2201\/row-header\/"},"author":{"name":"Sebastian Meine","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"headline":"The Row Header (A Storage Wednesday Post)","datePublished":"2014-03-12T15:00:24+00:00","dateModified":"2014-11-13T18:41:05+00:00","mainEntityOfPage":{"@id":"https:\/\/sqlity.net\/en\/2201\/row-header\/"},"wordCount":771,"commentCount":0,"keywords":["DBCC PAGE","page","Row Header","SQL Server","storage engine"],"articleSection":["General","Series","SQL Server Internals","Storage Wednesday"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sqlity.net\/en\/2201\/row-header\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sqlity.net\/en\/2201\/row-header\/","url":"https:\/\/sqlity.net\/en\/2201\/row-header\/","name":"The Row Header (A Storage Wednesday Post) - sqlity.net","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/#website"},"datePublished":"2014-03-12T15:00:24+00:00","dateModified":"2014-11-13T18:41:05+00:00","author":{"@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"description":"The row header contains metadata describing the row. It contains information about the row type, the column count and a NULL-bitmap. Read on to get all the details.","breadcrumb":{"@id":"https:\/\/sqlity.net\/en\/2201\/row-header\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sqlity.net\/en\/2201\/row-header\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/sqlity.net\/en\/2201\/row-header\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sqlity.net\/en\/"},{"@type":"ListItem","position":2,"name":"The Row Header (A Storage Wednesday Post)"}]},{"@type":"WebSite","@id":"https:\/\/sqlity.net\/en\/#website","url":"https:\/\/sqlity.net\/en\/","name":"sqlity.net","description":"Quality for SQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sqlity.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c","name":"Sebastian Meine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","caption":"Sebastian Meine"},"sameAs":["http:\/\/sqlity.net","https:\/\/x.com\/sqlity"]}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2wXuw-zv","jetpack-related-posts":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/2201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/comments?post=2201"}],"version-history":[{"count":0,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/2201\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/media?parent=2201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/categories?post=2201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/tags?post=2201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}