Laying the foundation

Before we can start creating our memory-optimized objects, we need to create a database with a FILEGROUP designed for memory-optimized objects. This can be achieved as follows:

CREATE DATABASE InMemoryTest 
    ON  
    PRIMARY(NAME = [InMemoryTest_disk],  
               FILENAME = 'C:tempInMemoryTest_disk.mdf', size=100MB),  
    FILEGROUP [InMemoryTest_inmem] CONTAINS MEMORY_OPTIMIZED_DATA 
               (NAME = [InMemoryTest_inmem],  
               FILENAME = 'C:tempInMemoryTest_inmem') 
   LOG ON (name = [InMemoryTest_log], Filename='c:tempInMemoryTest_log.ldf', size=100MB) 
   COLLATE Latin1_General_100_BIN2;  

The first main thing to note is that we have a separate FILEGROUP dedicated to the memory-optimized objects, with the keyword CONTAINS MEMORY_OPTIMIZED_DATA. This FILEGROUP is used to persist the memory-optimized objects between server restarts (if required). The filestream APIs are used for this, you can observe what objects are created by navigating to the folder location and accessing the folder (with administrator permissions).

Also of note is that the database has been created with the windows BIN2 collation. This is an initial implementation limitation of In-Memory OLTP with SQL Server 2014 and limited the support for comparisons, grouping and sorting with memory-optimized objects.

It is equally possible to add a FILEGROUP to an existing database using the ALTER DATABASE command, specifying the FILEGROUP and then the location for the filestream folder:

ALTER DATABASE AdventureWorks2014  
         ADD FILEGROUP InMemTest CONTAINS MEMORY_OPTIMIZED_DATA; 
GO 
ALTER DATABASE AdventureWorks2014 
         ADD FILE (NAME='InMemTest', FILENAME='c:tempInMemTest')  
    TO FILEGROUP InMemTest; 
GO 

As we can see, Microsoft has tried to keep the integration of the In-Memory OLTP engine as seamless as possible. A simple filegroup addition is all it takes to be able to start creating memory-optimized objects. We are one step closer to a faster database, let's keep going.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.226.255