Project “Hekaton” adds in-memory technology to boost performance of OLTP workloads in SQL Server
CREATE TABLE [Customer]( [CustomerID] INT NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = ), [Name] NVARCHAR(250) NOT NULL INDEX [IName] HASH WITH (BUCKET_COUNT = ), [CustomerSince] DATETIME NULL ) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA); This table is memory optimized This table is durable Secondary Indexes are specified inline Hash Index
CREATE TABLE DDLCode generation and compilationTable DLL producedTable DLL loaded
90,150 Susan Bogota 50, ∞ JanePrague 100, 200 JohnParis 200, ∞ JohnBeijing TimestampsNameChain ptrsCity Hash index on City Hash index on Name Garbage Collection Removes Unused Rows
CREATE PROCEDURE DATETIME WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER AS BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = 'us_english') -- insert T-SQL here END This proc is natively compiled Native procs must be schema-bound Atomic blocks Create a transaction if there is none Otherwise, create a savepoint Execution context is required Session settings are fixed at create time
CREATE PROC DDLQuery optimizationCode generation and compilationProcedure DLL producedProcedure DLL loaded
Accessing Memory Optimized Tables Natively Compiled Procs – Access only memory optimized tables – Maximum performance – Limited T-SQL surface area When to use – OLTP-style operations – Optimize performance critical business logic Interpreted T-SQL Access (InterOP) – Access both memory- and disk-based tables – Less performant – Virtually full T-SQL surface When to use – Ad hoc queries – Reporting-style queries – Speeding up app migration – Eliminating Latch Contention
TimeTransaction T1 (SNAPSHOT)Transaction T2 (SNAPSHOT) 1BEGIN 2 3UPDATE t SET c1=‘bla’ WHERE c2=123 4UPDATE t SET c1=‘bla’ WHERE c2=123 (write conflict) First writer wins
Disk-based tablesMemory-optimized tables Tab1TabnTab1Tabm Regular Tx contextHekaton Tx context
Disk-basedMemory optimizedUsage recommendations READCOMMITTEDSNAPSHOT Baseline combination – most cases that use READCOMMITTED today READCOMMITTEDREPEATABLEREAD/ SERIALIZABLE Data migration Hekaton-only Interop REPEATABLEREAD/ SERIALIZABLE SNAPSHOT Memory-optimized table access is INSERT-only Useful for data migration and if no concurrent writes on memory-optimized tables (e.g., ETL) Disk-basedMemory optimized SNAPSHOT Any isolation level REPEATABLEREAD/ SERIALIZABLE REPEATABLEREAD/ SERIALIZABLE Supported isolation level combinations (V1) Unsupported isolation level combinations (V1)
CREATE PROCEDURE type2,... AS BEGIN END
CREATE PROCEDURE type2,... AS BEGIN INT = 10 WHILE > 0) BEGIN END
CREATE PROCEDURE type2,... AS BEGIN INT = 10 WHILE > 0) BEGIN BEGIN TRY = 0 END TRY BEGIN CATCH -= 1 END CATCH END
CREATE PROCEDURE type2,... AS BEGIN INT = 10 WHILE > 0) BEGIN BEGIN TRY = 0 END TRY BEGIN CATCH -= 1 IF > 0 AND error_number() in (41302, 41305, 41325, 41301, 1205)) IF ROLLBACK TRANSACTION ELSE THROW END CATCH END Deadlock (for disk-based tables) Hekaton-specific error codes
CREATE PROCEDURE type2,... AS BEGIN INT = 10 WHILE > 0) BEGIN BEGIN TRY = 0 END TRY BEGIN CATCH -= 1 IF > 0 AND error_number() in (41302, 41305, 41325, 41301, 1205)) IF ROLLBACK TRANSACTION ELSE THROW END CATCH END
CREATE TABLE t1 ( c1 INT NOT NULL IDENTITY..., c2 INT, c3 DATE) CREATE TABLE t1 ( c1 INT NOT NULL..., c2 INT, c3 DATE) WITH (MEMORY_OPTIMIZED=ON) Before migration:After migration: CREATE PROC INT, c3 DATE AS BEGIN INSERT INTO t1 END CREATE SEQUENCE usq_t1 AS INT START WITH 1 INCREMENT BY 1 CREATE PROC INT, c3 DATE AS BEGIN INT = NEXT VALUE FOR usq_t1 INSERT INTO END
Windows Azure