{"id":3603,"date":"2014-02-14T05:16:00","date_gmt":"2014-02-14T04:16:00","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/"},"modified":"2014-02-14T05:16:00","modified_gmt":"2014-02-14T04:16:00","slug":"sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/","title":{"rendered":"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts"},"content":{"rendered":"<p><img decoding=\"async\" class=\"blog-image aligncenter\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg\" alt=\"\" \/><\/p>\n<p>For my first blog post at dbi services, I think it could be a good opportunity to begin by discussing around SQL Server 2014, Hekaton memory optimized tables, and hash indexes. When you create a memory optimized table you have to consider the number of buckets that you have to reserve for its associated hash index. It\u2019s an important aspect of configuration because after creating your table, you cannot change the number of buckets without recreating it.<\/p>\n<p>For the SQL Server database administrators world, it is not usual because with other ordinary indexes (clustered, nonclustered indexes) or other special indexes (xml or spatial indexes) this parameter does not exist. Furthermore, Microsoft recommends to reserve a number of buckets equal at least two times the number of distinct values in the table! The first time I read the documentation I asked myself a few questions:<\/p>\n<ul>\n<li>Why reserve a fixed number of buckets?<\/li>\n<li>Why round the number of buckets to the power of 2?<\/li>\n<\/ul>\n<p>In order to find the answers, I first had to understand how a hash index works.<\/p>\n<p>Let&#8217;s start from a basic definition of a hash table: it is a data structure used to implement an unsorted associative data array that can map a key to a value. To compute this key a hash function is used. The hash result is then stored into an array of buckets as shown to figure 1 (simplified schema).<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/bucket_hash_index.jpg\" alt=\"bucket_hash_index\" width=\"400\" height=\"151\" \/><\/p>\n<p>Notice that the hashing keys are not sorted. For lookup operations it does not matter, but for range value scans the hash index does not perform well. In the hash table world, the ideal situation is one key for one unique bucket to allow constant time for lookups, but in reality it is not the case because of hash collisions (two distinct pieces of data can have the same hash value). However, the hash function should be efficient enough to spread keys into buckets uniformly to avoid this phenomenon\u00a0as much as possible.<\/p>\n<p>There are several strategies to resolve hash collisions and the lack of buckets. SQL Server uses a method that consists of a separated chaining. When a hash collision occurs or when the number of buckets is not sufficient, the row data is added to the row chain for the selecting bucket. In consequence, the cost of the table operation is that of scanning the number of entries in the row chain of the selecting bucket for the concerned index key. If the distribution is sufficiently uniform, the average cost of a lookup depends only on the average number of keys per bucket also called the load factor. The load factor is the number of total entries divided by the number of buckets. The larger the load factor, the more the hash table will be slow. It means for a fixed number of buckets the time for lookups will grow with the number of entries.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/bucket_hash_collision.jpg\" alt=\"bucket_hash_collision\" width=\"453\" height=\"121\" \/><\/p>\n<p>Now let\u2019s start with a practical example of a memory-optimized table :<\/p>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">CREATE<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: blue\">TABLE [dbo]<span style=\"color: gray\">.[HekatonTableDurable]<\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">(<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [c1] [int] <span style=\"color: gray\">NOT <span style=\"color: gray\">NULL,<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [c2] [char]<span style=\"color: gray\">(100<span style=\"color: gray\">) <span style=\"color: fuchsia\">COLLATE Latin1_General_100_BIN2 <span style=\"color: gray\">NOT <span style=\"color: gray\">NULL<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0 <span style=\"color: blue\">CONSTRAINT [pk_HekatonTableDurable] <span style=\"color: blue\">PRIMARY <span style=\"color: blue\">KEY <span style=\"color: blue\">NONCLUSTERED <span style=\"color: blue\">HASH <\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">(<\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [c1]<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: gray\">) <span style=\"color: blue\">WITH <span style=\"color: gray\">( <span style=\"color: blue\">BUCKET_COUNT <span style=\"color: gray\">= 1000<span style=\"color: gray\">)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">)<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">WITH<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">(<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">MEMORY_OPTIMIZED <span style=\"color: gray\">= <span style=\"color: blue\">ON <span style=\"color: gray\">, <\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">DURABILITY <span style=\"color: gray\">= SCHEMA_AND_DATA <\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">)<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">GO<\/span><\/div>\n<p>We create a simple memory optimized table with two columns and 1000 buckets to store the hash index entries. After creating this table, we can see the number of buckets allocated and we notice the final number is not the same, but rounded to the nearest power of two.<\/p>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">SELECT<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: fuchsia\">OBJECT_NAME<span style=\"color: gray\">(<span style=\"color: fuchsia\">object_id<span style=\"color: gray\">) <span style=\"color: blue\">AS table_name<span style=\"color: gray\">,<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name <span style=\"color: blue\">AS index_name<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 index_id<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type_desc<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [bucket_count]<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">FROM<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: green\">sys<span style=\"color: gray\">.hash_indexes <\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\"><span style=\"color: green\"><span style=\"color: gray\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">GO<br \/>\n<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\"><span style=\"color: green\"><span style=\"color: gray\">\u00a0<\/span><\/span><\/span><\/span><\/div>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/number_of_buckets_after_creating_hk_table.jpg\" alt=\"number_of_buckets_after_creating_hk_table\" width=\"574\" height=\"45\" \/><\/p>\n<p>This fact is very interesting because using a power of two to determine the position of the bucket pointer in the array is very efficient. Generally, with hash tables the hash function process is done in two steps to determine the index in the buckets array:<\/p>\n<ul>\n<li>hash value = hash function (key)<\/li>\n<li>position in the array = hash value % array size<\/li>\n<\/ul>\n<p>The modulo operator in the case could be very expensive and can fortunately be replaced by a bitwise AND operator (because the array size is a power of two) which reduces the operation to masking and improves speed. To verify, we can do a simple test with a console application in C#:<\/p>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">using<span style=\"font-family: Consolas;font-size: 9.5pt\"> System;<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">using<span style=\"font-family: Consolas;font-size: 9.5pt\"> System.Diagnostics;<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">namespace<span style=\"font-family: Consolas;font-size: 9.5pt\"> ConsoleApplication1<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">{<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0 <span style=\"color: blue\">class <span style=\"color: #2b91af\">Program<\/span><\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0 {<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">static <span style=\"color: blue\">void Main(<span style=\"color: blue\">string[] args)<\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">int i = 0;<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">int result = 0;<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">int maxloop = 1000000000;<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: #2b91af\">Stopwatch timer = <span style=\"color: blue\">new <span style=\"color: #2b91af\">Stopwatch();<\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: green\">\/\/ Modulo operator<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timer.Start();<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">while (i &lt; maxloop)<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 result = modulo_operation(i, 4);<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 i++;<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timer.Stop();<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: #2b91af\">Console.WriteLine(<span style=\"color: #a31515\">&#8220;With modulo : (ms) &#8220;);<\/span><\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: #2b91af\">Console.WriteLine(timer.ElapsedMilliseconds);<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 i = 0;<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: green\">\/\/ Bitwise AND<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timer.Restart();<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">while (i &lt; maxloop)<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 result = bitwiseand(i, 4);<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 i++;<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timer.Stop();<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: #2b91af\">Console.WriteLine(<span style=\"color: #a31515\">&#8220;With bitwise and : (ms)&#8221;);<\/span><\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: #2b91af\">Console.WriteLine(timer.ElapsedMilliseconds);<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: #2b91af\">Console.ReadLine();<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: green\">\/\/ modulo<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">public <span style=\"color: blue\">static <span style=\"color: blue\">int modulo_operation (<span style=\"color: blue\">int x, <span style=\"color: blue\">int y)<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">return x % y;<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: green\">\/\/ bitwise<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">public <span style=\"color: blue\">static <span style=\"color: blue\">int bitwiseand (<span style=\"color: blue\">int x, <span style=\"color: blue\">int y)<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">return (x &amp; (y -1));<\/span><\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0 }<\/span><\/div>\n<div style=\"background: #d0cece;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">}<\/span><\/div>\n<p>By executing this console application on my dev environment (Intel Core i7-3610QM 2.30 GHz), we can notice that the bitwise and function performs faster than the modulo function for an iteration of 1 billion:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/csharp_test.jpg\" alt=\"csharp_test\" width=\"312\" height=\"91\" \/><\/p>\n<p>Then we can play with different combination of data rows and hash index buckets to understand why the number of bucket is very important.<\/p>\n<h4>Test 1: Filling up the table with 500 distinct rows and 1024 buckets<\/h4>\n<p><strong><span style=\"text-decoration: underline\">\u00a0<\/span><\/strong><\/p>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">declare<span style=\"font-family: Consolas;font-size: 9.5pt\"> @i <span style=\"color: blue\">int <span style=\"color: gray\">= 0<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">while<span style=\"font-family: Consolas;font-size: 9.5pt\"> @i <span style=\"color: gray\">&lt; 500<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">begin<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">insert HekatonTableDurable <span style=\"color: blue\">values <span style=\"color: gray\">(@i<span style=\"color: gray\">, <span style=\"color: red\">&#8216;test_&#8217; <span style=\"color: gray\">+ <span style=\"color: fuchsia\">cast<span style=\"color: gray\">(@i <span style=\"color: blue\">as <span style=\"color: blue\">varchar<span style=\"color: gray\">(50<span style=\"color: gray\">)));<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">set @i <span style=\"color: gray\">+= 1<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">end<\/span><\/div>\n<p>By using the DMV <em>sys.dm_db_xtp_hash_index_stats<\/em> we can see useful information about buckets usage.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/hash_index_stats.jpg\" alt=\"hash_index_stats\" width=\"527\" height=\"40\" \/><\/p>\n<p>We retrieve the total number of buckets allocated for the index hash equal to 1024. Furthermore, we notice that we have 545 empty buckets and in consequence 1024 \u2013 545 = 479 buckets in use. Normally, with a perfect distribution of key values in the bucket array, we should have 500 buckets in use, but we notice that we certainly already have some hash collisions. We can verify this in the value of the column max_chain_length which tells us there is at least one bucket with a row chain length of 2. In other words, we have at least one bucket that contains two rows with the same index hash. Notice that the load factor is equal to 500 \/ 1024 = 0.49<\/p>\n<p><strong><span style=\"text-decoration: underline\"><span style=\"line-height: 107%;font-family: 'Calibri','sans-serif';font-size: 11pt\">\u00a0<\/span><\/span><\/strong><\/p>\n<h4>Test 2: Filling up the memory-optimized table with a load factor of 3. We will insert 3072 rows for a total of bucket count equal to 1024<\/h4>\n<p><span style=\"text-decoration: underline\"><span style=\"line-height: 107%;font-family: 'Calibri','sans-serif';font-size: 11pt\"><span style=\"line-height: 107%;font-family: 'Calibri','sans-serif';font-size: 11pt\">\u00a0<\/span><\/span><\/span><\/p>\n<p><span style=\"text-decoration: underline\"><span style=\"line-height: 107%;font-family: 'Calibri','sans-serif';font-size: 11pt\"><span style=\"line-height: 107%;font-family: 'Calibri','sans-serif';font-size: 11pt\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/number_of_buckets_after_with_load_factor_3_hk_table.jpg\" alt=\"number_of_buckets_after_with_load_factor_3_hk_table\" width=\"524\" height=\"40\" \/><\/span><\/span><\/span><\/p>\n<p><span style=\"text-decoration: underline\"><span style=\"line-height: 107%;font-family: 'Calibri','sans-serif';font-size: 11pt\"><span style=\"line-height: 107%;font-family: 'Calibri','sans-serif';font-size: 11pt\">\u00a0<\/span><\/span><\/span><\/p>\n<p>As expected, all buckets are used (empty_bucket_count = 0). We have an average row chain length of 3 (avg_chain_length = 3) in the bucket array equal to the load factor. Some of the rows chain lengths are equal to five, certainly due to a hash collision (max_chain_length = 5).<\/p>\n<h4>Test 3: Filling up the memory-optimized table with duplicate rows<\/h4>\n<p>Before filling up the table, some changes in the schema are required. Let&#8217;s create a second non-unique hash index (ix_OrderDate):<\/p>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">IF<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: fuchsia\">OBJECT_ID<span style=\"color: gray\">(<span style=\"color: red\">&#8216;dbo.HekatonTableDurable&#8217;<span style=\"color: gray\">) <span style=\"color: gray\">IS <span style=\"color: gray\">NOT <span style=\"color: gray\">NULL<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">DROP <span style=\"color: blue\">TABLE [dbo]<span style=\"color: gray\">.[HekatonTableDurable]<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">GO<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">CREATE<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: blue\">TABLE [dbo]<span style=\"color: gray\">.[HekatonTableDurable]<\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">(<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [c1] [int] <span style=\"color: gray\">NOT <span style=\"color: gray\">NULL <span style=\"color: blue\">PRIMARY <span style=\"color: blue\">KEY <span style=\"color: blue\">NONCLUSTERED <span style=\"color: blue\">HASH <span style=\"color: blue\">WITH <span style=\"color: gray\">( <span style=\"color: blue\">BUCKET_COUNT <span style=\"color: gray\">= 1024<span style=\"color: gray\">) <span style=\"color: gray\">,<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [c2] [char]<span style=\"color: gray\">(100<span style=\"color: gray\">) <span style=\"color: fuchsia\">COLLATE Latin1_General_100_BIN2 <span style=\"color: gray\">NOT <span style=\"color: gray\">NULL <span style=\"color: blue\">INDEX ix_OrderDate <span style=\"color: blue\">HASH <span style=\"color: blue\">WITH <span style=\"color: gray\">(<span style=\"color: blue\">BUCKET_COUNT<span style=\"color: gray\">=1024<span style=\"color: gray\">)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">)<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">WITH<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">(<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">MEMORY_OPTIMIZED <span style=\"color: gray\">= <span style=\"color: blue\">ON <span style=\"color: gray\">, <\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">DURABILITY <span style=\"color: gray\">= SCHEMA_AND_DATA <\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">)<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">GO<\/span><\/div>\n<p>Then we can fill up the table with 500 rows that contain some duplicate rows:<\/p>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">declare<span style=\"font-family: Consolas;font-size: 9.5pt\"> @i <span style=\"color: blue\">int <span style=\"color: gray\">= 0<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">while<span style=\"font-family: Consolas;font-size: 9.5pt\"> @i <span style=\"color: gray\">&lt; 500<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">begin<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">insert dbo<span style=\"color: gray\">.HekatonTableDurable <span style=\"color: blue\">values <span style=\"color: gray\">(@i<span style=\"color: gray\">, <span style=\"color: blue\">case @i <span style=\"color: gray\">% 4 <span style=\"color: blue\">WHEN 0 <span style=\"color: blue\">THEN <span style=\"color: red\">&#8216;test_&#8217; <span style=\"color: gray\">+ <span style=\"color: fuchsia\">cast<span style=\"color: gray\">(@i <span style=\"color: blue\">as <span style=\"color: blue\">varchar<span style=\"color: gray\">(50<span style=\"color: gray\">)) <span style=\"color: blue\">ELSE <span style=\"color: red\">&#8216;test&#8217; <span style=\"color: blue\">END<span style=\"color: gray\">);<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">set @i <span style=\"color: gray\">+= 1<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">end<\/span><\/div>\n<p>Here is an overview of the number of duplicates rows in the table:<\/p>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">select<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 c2<span style=\"color: gray\">,<\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: fuchsia\">count<span style=\"color: gray\">(*)<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">from<span style=\"font-family: Consolas;font-size: 9.5pt\"> dbo<span style=\"color: gray\">.HekatonTableDurable<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">group<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: blue\">by c2<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">order<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: blue\">by <span style=\"color: fuchsia\">count<span style=\"color: gray\">(*) <span style=\"color: blue\">desc<\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<p style=\"line-height: normal;margin-bottom: 0pt\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/number_of_duplicate_rows_after_loading_hk_table.jpg\" alt=\"number_of_duplicate_rows_after_loading_hk_table\" width=\"214\" height=\"111\" \/><\/p>\n<p>We can now check how the buckets are used for the two hash indexes:<\/p>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">select<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: fuchsia\">object_name<span style=\"color: gray\">(i<span style=\"color: gray\">.<span style=\"color: fuchsia\">object_id<span style=\"color: gray\">) <span style=\"color: blue\">as table_name<span style=\"color: gray\">,<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 i<span style=\"color: gray\">.name <span style=\"color: blue\">as index_name<span style=\"color: gray\">,<\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 his<span style=\"color: gray\">.total_bucket_count<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 his<span style=\"color: gray\">.empty_bucket_count<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 his<span style=\"color: gray\">.avg_chain_length<span style=\"color: gray\">,<\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 his<span style=\"color: gray\">.max_chain_length<\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">from<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: green\">sys<span style=\"color: gray\">.dm_db_xtp_hash_index_stats <span style=\"color: blue\">as his<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: gray\">join <span style=\"color: green\">sys<span style=\"color: gray\">.hash_indexes <span style=\"color: blue\">as i<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">on his<span style=\"color: gray\">.index_id <span style=\"color: gray\">= i<span style=\"color: gray\">.index_id<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: gray\">and his<span style=\"color: gray\">.<span style=\"color: fuchsia\">object_id <span style=\"color: gray\">= i<span style=\"color: gray\">.<span style=\"color: fuchsia\">object_id<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">where<span style=\"font-family: Consolas;font-size: 9.5pt\"> i<span style=\"color: gray\">.<span style=\"color: fuchsia\">object_id <span style=\"color: gray\">= <span style=\"color: fuchsia\">object_id<span style=\"color: gray\">(<span style=\"color: red\">&#8216;dbo.HekatonTableDurable&#8217;<span style=\"color: gray\">)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<p>We retrieve the same number of used buckets for the primary hash index key (545) as first tests. This is because the hash function used by SQL Server is deterministic. The same index key is always mapped to the same bucket in the array. The index key is relatively well distributed. However, we can see a different result for the second hash index. We only have 119 buckets in use to store 500 rows. Furthermore, we notice that the maximum row chain length is very high and corresponds in fact to the number of duplicates values we inserted (375).<\/p>\n<h4>Test 4: Filling up the table with an insufficient number of buckets to uniformly store the hash indexes<\/h4>\n<p>For this last test, we will use 10 buckets to store 8192 distinct rows (a load factor = 819).<\/p>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">IF<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: fuchsia\">OBJECT_ID<span style=\"color: gray\">(<span style=\"color: red\">&#8216;dbo.HekatonTableDurable&#8217;<span style=\"color: gray\">) <span style=\"color: gray\">IS <span style=\"color: gray\">NOT <span style=\"color: gray\">NULL<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">DROP <span style=\"color: blue\">TABLE [dbo]<span style=\"color: gray\">.[HekatonTableDurable]<span style=\"color: gray\">;<\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">GO<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">CREATE<span style=\"font-family: Consolas;font-size: 9.5pt\"> <span style=\"color: blue\">TABLE [dbo]<span style=\"color: gray\">.[HekatonTableDurable]<\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">(<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [c1] [int] <span style=\"color: gray\">NOT <span style=\"color: gray\">NULL <span style=\"color: blue\">PRIMARY <span style=\"color: blue\">KEY <span style=\"color: blue\">NONCLUSTERED <span style=\"color: blue\">HASH <span style=\"color: blue\">WITH <span style=\"color: gray\">( <span style=\"color: blue\">BUCKET_COUNT <span style=\"color: gray\">= 10<span style=\"color: gray\">) <span style=\"color: gray\">,<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [c2] [char]<span style=\"color: gray\">(100<span style=\"color: gray\">) <span style=\"color: fuchsia\">COLLATE Latin1_General_100_BIN2 <span style=\"color: gray\">NOT <span style=\"color: gray\">NULL <span style=\"color: blue\">INDEX ix_OrderDate <span style=\"color: blue\">HASH <span style=\"color: blue\">WITH <span style=\"color: gray\">(<span style=\"color: blue\">BUCKET_COUNT<span style=\"color: gray\">=10<span style=\"color: gray\">)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">)<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">WITH<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">(<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">MEMORY_OPTIMIZED <span style=\"color: gray\">= <span style=\"color: blue\">ON <span style=\"color: gray\">, <\/span><\/span><\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"font-family: Consolas;font-size: 9.5pt\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: blue\">DURABILITY <span style=\"color: gray\">= SCHEMA_AND_DATA <\/span><\/span><\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: gray;font-family: Consolas;font-size: 9.5pt\">)<\/span><\/div>\n<div style=\"background: #d9d9d9;line-height: normal;margin-bottom: 0pt\"><span style=\"color: blue;font-family: Consolas;font-size: 9.5pt\">GO<\/span><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/number_of_buckets_worse_case_hk_table.jpg\" alt=\"number_of_buckets_worse_case_hk_table\" width=\"593\" height=\"47\" \/><\/p>\n<p>In this case, only one bucket is used (no empty buckets) and the value of the avg_chain_length and the max_chain_length column are pretty close. This is an indication of a lack of buckets with a big row chain.<\/p>\n<p>In this post, we have seen the basic concepts of the hash table, the importance of a correct configuration of the buckets and how to use the dynamic management view sys.dm_db_xtp_index_hash_stats to get useful statistics for hash indexes.<\/p>\n<p>By David Barbarin<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my first blog post at dbi services, I think it could be a good opportunity to begin by discussing around SQL Server 2014, Hekaton memory optimized tables, and hash indexes. When you create a memory optimized table you have to consider the number of buckets that you have to reserve for its associated hash [&hellip;]<\/p>\n","protected":false},"author":26,"featured_media":3189,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[431,49,51,52],"type_dbi":[],"class_list":["post-3603","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-integration-middleware","tag-hekaton","tag-microsoft","tag-sql-server","tag-sql-server-2014"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts - dbi Blog<\/title>\n<meta name=\"description\" content=\"This SQL Server 2014 posting is about basic hash table concepts, the importance of a correct configuration of the buckets and how to use the dynamic management view sys.dm_db_xtp_index_hash_stats to get useful statistics for hash indexes.\" \/>\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.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts\" \/>\n<meta property=\"og:description\" content=\"This SQL Server 2014 posting is about basic hash table concepts, the importance of a correct configuration of the buckets and how to use the dynamic management view sys.dm_db_xtp_index_hash_stats to get useful statistics for hash indexes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-02-14T04:16:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"245\" \/>\n\t<meta property=\"og:image:height\" content=\"149\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Microsoft Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Microsoft Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/\"},\"author\":{\"name\":\"Microsoft Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\"},\"headline\":\"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts\",\"datePublished\":\"2014-02-14T04:16:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/\"},\"wordCount\":1615,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg\",\"keywords\":[\"hekaton\",\"Microsoft\",\"SQL Server\",\"SQL Server 2014\"],\"articleSection\":[\"Application integration &amp; Middleware\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/\",\"name\":\"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg\",\"datePublished\":\"2014-02-14T04:16:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\"},\"description\":\"This SQL Server 2014 posting is about basic hash table concepts, the importance of a correct configuration of the buckets and how to use the dynamic management view sys.dm_db_xtp_index_hash_stats to get useful statistics for hash indexes.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg\",\"width\":245,\"height\":149},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4\",\"name\":\"Microsoft Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g\",\"caption\":\"Microsoft Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/microsoft-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts - dbi Blog","description":"This SQL Server 2014 posting is about basic hash table concepts, the importance of a correct configuration of the buckets and how to use the dynamic management view sys.dm_db_xtp_index_hash_stats to get useful statistics for hash indexes.","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.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts","og_description":"This SQL Server 2014 posting is about basic hash table concepts, the importance of a correct configuration of the buckets and how to use the dynamic management view sys.dm_db_xtp_index_hash_stats to get useful statistics for hash indexes.","og_url":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/","og_site_name":"dbi Blog","article_published_time":"2014-02-14T04:16:00+00:00","og_image":[{"width":245,"height":149,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg","type":"image\/jpeg"}],"author":"Microsoft Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Microsoft Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/"},"author":{"name":"Microsoft Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4"},"headline":"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts","datePublished":"2014-02-14T04:16:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/"},"wordCount":1615,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg","keywords":["hekaton","Microsoft","SQL Server","SQL Server 2014"],"articleSection":["Application integration &amp; Middleware"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/","url":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/","name":"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg","datePublished":"2014-02-14T04:16:00+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4"},"description":"This SQL Server 2014 posting is about basic hash table concepts, the importance of a correct configuration of the buckets and how to use the dynamic management view sys.dm_db_xtp_index_hash_stats to get useful statistics for hash indexes.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2e1ax_default_entry_sqlserver2014_20130625-144612_1.jpg","width":245,"height":149},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/sql-server-2014-hekaton-memory-optimized-tables-hash-indexes-and-bucket-counts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL Server 2014: Hekaton memory optimized tables, hash indexes, and bucket counts"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/bfab48333280d616e1170e7369df90a4","name":"Microsoft Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c44a1a792c059f24055763aa77d80a244467f6eef724a8bd13db8d4a350b7a4c?s=96&d=mm&r=g","caption":"Microsoft Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/microsoft-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=3603"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3603\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media\/3189"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=3603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=3603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=3603"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=3603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}