SQL Server memory optimization of the index table design

Test version: SQL Server 2017

You can create three types of indexes on the table memory optimization, are: Hash Index, memory optimizer non-aggregated (NONCLUSTERED) index and aggregation (CLUSTERED) column store index.

First, create an index

When you create a memory optimization table, you can create a standard level of the index:

<table_index> ::=
  INDEX index_name
{   [ NONCLUSTERED ] HASH (column [ ,... n ] ) WITH (BUCKET_COUNT = bucket_count)
  | [ NONCLUSTERED ] (column [ ASC | DESC ] [ ,... n ] )
      [ ON filegroup_name | default ]
  | CLUSTERED COLUMNSTORE [WITH ( COMPRESSION_DELAY = {0 | delay [Minutes]})]
      [ ON filegroup_name | default ]
  
}

1, non-clustered index

If the query contains an order by clause, or contain where index_column> value range and other scanning operations, recommended non-clustered index.

2, hash indexes

Hash index is particularly suitable for point lookup (point lookup), for example, where index_column = value, rather than a range scan is recommended hash index.

Second, the internal structure of the memory non-clustered index

Memory similar non-clustered index B-Tree structure, referred Bw-Tree, is a new B-Tree structure. From a high level perspective, Bw-Tree can be understood as the organization in accordance with page Page ID mapping.

In Bw-Tree structure, each having a set of ordered Page index key (the structure is similar to conventional B-tree), the key is arranged in order of size, and the index comprises a hierarchical structure, a parent level to sub-level , pointing to the leaf level data rows.

Differences Bw-Tree can be connected with a plurality of data lines, the page pointer is level logical page ID, the ID is actually the logical page offset of the page mapping table, the mapping table having each page physical address of each page to find the actual physical memory address offset.

Non-clustered index in memory, there is no place updates (in place update) index page, in order to achieve this, the introduction of a new update mechanism:

  • When updating the page, you do not need to latch and lock
  • Index page size is not fixed

In the non-leaf level, a parental level key value is stored in the page it points to the maximum value of the child key page, and each row of the page further comprises a logical page ID (offset). The leaf level data pages contain not only the key, also contains the physical address of the page.

Third, the internal structure of the hash index

Hash index comprises an array consisting of a pointer, each tuple in the array is called a hash bucket:

  • Each hash bucket occupancy 8Bytes, a chain consisting of a list of key entry point
  • Each entry consists essentially of the index key value, the address pointing to the corresponding data line and a pointer entry
  • Each entry has a pointer for pointing to the next entry in the chain, in this way, constitute a chain structure entry

The number of hash bucket must be specified when the index definition:

  • The maximum number of hash bucket of the hash index is 1,073,741,824
  • A short list of relatively long chain of linked list better performance
  • The lower the number of hash bucket number and the ratio of unique values ​​in the table, the longer the length of each hash bucket points to the linked list, the poorer the performance. Therefore, it is appropriate to increase the number of hash bucket.
  • Ideally, hash bucket in Table preferably 1 to 2 times the number of unique values.

 

Reference documents:

Index Architecture & Design

Guess you like

Origin www.cnblogs.com/ljhdo/p/10533688.html