SlideShare una empresa de Scribd logo
1 de 33
İsmail Adar
About.Me()
• Veritabanı Yöneticisi / Doğan Online
• Eğitimen/Danışman / Btakademi
• Kitap Yazarı
• Microsoft Certified Trainer
ismailadar@hotmail.com

http://www.ismailadar.com

İsmail
Adar

@ismailadars
Content.GetAgenda()
• SQL Server 2014 In-Memory OLTP Basics
• Create Database For In-Memory OLTP
• Creating Memory Optimized Tables and Indexes
• Accessing Memory Optimized Tables
• Memory Optimized Tables Limitations

• Memory management on memory-optimized tables
• Tools for analysis and migration
SQL Server 2014 In-Memory OLTP Basics
Create Database For In-Memory OLTP
code page 1252
associated collation
CREATE DATABASE [InMemoryDemo] COLLATE Latin1_General_CI_AI
GO
ALTER DATABASE [InMemoryDemo]
ADD FILEGROUP [InMemory_FStream_FGroup]
CONTAINS MEMORY_OPTIMIZED_DATA

Filegroup for memory optimized
table storage

GO
ALTER DATABASE [InMemoryDemo] ADD FILE ( NAME = N'InMemoryDemo_FS',
FILENAME = N'C:Program FilesMicrosoft SQL
ServerMSSQL12.MSSQLSERVERMSSQLDATAInMemoryDemo_FS' )
TO FILEGROUP [InMemory_FStream_FGroup]
GO

Add file to FS filegroup
DEMO
Creating Database For In Memory OLTP
Create Table DDL
Hash Index
CREATE TABLE [Customer](

BUCKET_COUNT 1-2X nr of
unique index key values

[CustomerID] INT NOT NULL
PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 1000000),
[Name] NVARCHAR(250) NOT NULL,
[CreatedDate] DATETIME NULL
INDEX [IX_CreatedDate] NONCLUSTERED
)

Indexes are specified inline
NONCLUSTERED indexes are
supported

WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA);

This table is memory
optimized

This table is durable
Memory Optimized Table Creation

CREATE TABLE DDL

Code generation and compilation
Table DLL produced
Table DLL loaded
DEMO
Creating Memory Optimized Tables
Memory-Optimized Indexes
•

Exist only in memory
– Rebuilt on database startup

•

Do not contain data rows
– Indexes contain memory pointers to the data rows

– No duplication of data
– All indexes are covering
Memory-optimized Table: Row
Format
Row header

Payload (table columns)

8 bytes * (IdxLinkCount)

Begin Ts

End Ts

StmtId

IdxLinkCount

8 bytes

8 bytes

4 bytes

2 bytes
Memory Optimized Tables and Hash Indexes
Timestamps
Hash index on
Name

50, ∞

Chain ptrs

Name

City
Hash index on
City

Jane

Prague

100, ∞

John

Prague

90, ∞
90, 150

Susan

Bogota
Nonclustered (range) index
•

No latch for page updates

•

No in-place updates on index pages


•

1

PAGE

Physical

Page size- up to 8K. Sized to the row

•

Page Mapping Table
0

Handled thru delta pages or building new pages

Sibling pages linked one direction


Root

PAGE

2

1
0

3

2
0

•

2
8

Require two indexes for ASC/DSC

No covering columns (only the key is stored)

Page-pid-0

PageID-3
4

8

1
0

1
1

1
5

1
8

2
1

2
4

2
7

Non-leaf pages

Logical

1

14
15

2

200,

4

∞

5

1

Key

6

2
5

7

50, 300

2

Key

2
6

2
7

Data rows

leaf pages
DEMO
Creating Indexes On Memory Optimized Tables
Create Procedure DDL
CREATE PROCEDURE [dbo].[InsertOrder] @id INT, @date DATETIME
WITH
This proc is natively
compiled

NATIVE_COMPILATION,
SCHEMABINDING,

Native procs must be
schema-bound

EXECUTE AS OWNER

Execution context is
required

AS
BEGIN ATOMIC
WITH

Atomic blocks
• Create a transaction if
there is none
• Otherwise, create a
savepoint

(TRANSACTION
ISOLATION LEVEL = SNAPSHOT,
LANGUAGE = N'us_english')

-- insert T-SQL here
END

Session settings are fixed at
create time
Procedure Creation

CREATE PROC DDL
Query optimization

Code generation and compilation
Procedure DLL produced
Procedure DLL loaded
Accessing Memory Optimized Tables
Interpreted T-SQL Access
• Access both memory- and disk-based
tables
• Less performance

Natively Compiled Stored
Procs
• Access only memory optimized tables
• Maximum performance
• Limited T-SQL surface area

• Virtually full T-SQL surface
• When to use
– Ad hoc queries
– Reporting-style queries

– Speeding up app migration

• When to use
– OLTP-style operations
– Optimize performance critical business logic
Sample AdventureWorks conversion
ostress.exe -S. –E
-dAdventureWorks2012
-Q"EXEC Sales.usp_InsertOrders
@use_inmem = <0,1>,
@order_count=100000"
–n<varies>
DEMO
Accessing Memory Optimized Tables
Limitations on In-Memory OLTP in SQL 2014
• Tables
–
–
–
–
–
–

Triggers: no DDL/DML triggers
No Identity columns
Data types: no LOBs, no XML and no CLR data types
Constraints: no FOREIGN KEY and no CHECK constraints
No schema changes (ALTER TABLE) – need to drop/recreate table
No add/remove index – need to drop/recreate table

• Natively Compiled Stored Procedures
– No outer join, no OR, no subqueries, no CASE
– Limited built-in functions [core math, date/time, and string functions are
available]
Memory Management For In-Memory OLTP
Data resides in memory at all times
• Must configure SQL server with sufficient memory to store memoryoptimized tables
• Failure to allocate memory will fail transactional workload at run-time
• Integrated with SQL Server memory manager and reacts to memory
pressure for GC (Garbage Collection)
Memory Management For In-Memory
OLTP
Integrated with Resource Governor
• To ensure performance stability for disk-based table workloads
• “Bind” a database to a resource pool
• Mem-opt tables in a database cannot exceed the limit of the resource
pool
• Hard top limit (80% of phys. memory) to ensure system remains stable
under memory pressure
Memory Management For In-Memory OLTP
Memory optimized max
memory limit
CREATE RESOURCE POOL InMemResourcePool
WITH (MAX_MEMORY_PERCENT=40);
ALTER RESOURCE GOVERNOR RECONFIGURE;
GO
EXEC sp_xtp_bind_db_resource_pool 'InMemoryDemoDB','InMemResourcePool';
GO
ALTER DATABASE InMemoryDemoDB SET OFFLINE;
ALTER DATABASE InMemoryDemoDB SET ONLINE;

Filegroup for memory optimized
table storage
DEMO
Memory Management For In-Memory OLTP
DEMO
Analysis and Migration Tools
Resources
•

Overview of all In-Memory OLTP posts on the SQL Server blog
–
http://blogs.technet.com/b/dataplatforminsider/archive/2013/10/15/the-411-on-the-microsoft-sql-server-2014-in-memory-oltp-blog-series.aspx

•

SQL 2014 CTP2
–
http://technet.microsoft.com/en-US/evalcenter/dn205290?WT.mc_id=Blog_SQL_InMem_CTP2

•

Getting started with In-Memory OLTP
–
http://blogs.technet.com/b/dataplatforminsider/archive/2013/06/26/getting-started-with-sql-server-2014-in-memory-oltp.aspx

•

In-Memory OLTP Sample, based on AdventureWorks
–
https://msftdbprodsamples.codeplex.com/releases/view/114491?WT.mc_id=Blog_SQL_InMem_CTP2

•

Analysis and Migration tools
–
–

http://technet.microsoft.com/en-us/library/dn284308(v=sql.120).aspx

–

•

http://technet.microsoft.com/en-us/library/dn205133(v=sql.120).aspx

http://technet.microsoft.com/en-us/library/dn358355(v=sql.120).aspx

Transaction isolation with In-Memory OLTP
–

Choosing isolation level: http://msdn.microsoft.com/en-us/library/dn133187(v=sql.120).aspx

–

Implement retry logic: http://msdn.microsoft.com/en-us/library/dn169141(v=sql.120).aspx

•

Books Online documentation for In-Memory OLTP
–
http://technet.microsoft.com/en-us/library/dn133186(v=sql.120).aspx

•

Limitations and workarounds
–

http://msdn.microsoft.com/en-us/library/dn247639(v=sql.120).aspx
©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the
U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft
must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Más contenido relacionado

La actualidad más candente

Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practices
webhostingguy
 
Optimizing MySQL for Cascade Server
Optimizing MySQL for Cascade ServerOptimizing MySQL for Cascade Server
Optimizing MySQL for Cascade Server
hannonhill
 
MySQL 5.6 Performance
MySQL 5.6 PerformanceMySQL 5.6 Performance
MySQL 5.6 Performance
MYXPLAIN
 

La actualidad más candente (18)

Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
 
MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practices
 
MySQL Tuning
MySQL TuningMySQL Tuning
MySQL Tuning
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
MySQL Performance Tuning - GNUnify 2010
MySQL Performance Tuning - GNUnify 2010MySQL Performance Tuning - GNUnify 2010
MySQL Performance Tuning - GNUnify 2010
 
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerGeek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
 
SharePoint is from Mars, SQL Server is from Venus (SQL Server for SharePoint ...
SharePoint is from Mars, SQL Server is from Venus (SQL Server for SharePoint ...SharePoint is from Mars, SQL Server is from Venus (SQL Server for SharePoint ...
SharePoint is from Mars, SQL Server is from Venus (SQL Server for SharePoint ...
 
Caching in Kentico 11
Caching in Kentico 11Caching in Kentico 11
Caching in Kentico 11
 
Optimizing MySQL for Cascade Server
Optimizing MySQL for Cascade ServerOptimizing MySQL for Cascade Server
Optimizing MySQL for Cascade Server
 
Boost your website by running PHP on Nginx
Boost your website by running PHP on NginxBoost your website by running PHP on Nginx
Boost your website by running PHP on Nginx
 
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software Webcast
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software WebcastPreparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software Webcast
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software Webcast
 
Inside sql server in memory oltp sql sat nyc 2017
Inside sql server in memory oltp sql sat nyc 2017Inside sql server in memory oltp sql sat nyc 2017
Inside sql server in memory oltp sql sat nyc 2017
 
Wizard of ORDS
Wizard of ORDSWizard of ORDS
Wizard of ORDS
 
Running PHP on Nginx
Running PHP on NginxRunning PHP on Nginx
Running PHP on Nginx
 
MySQL 5.6 Performance
MySQL 5.6 PerformanceMySQL 5.6 Performance
MySQL 5.6 Performance
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014
 
Mysql nowwhat
Mysql nowwhatMysql nowwhat
Mysql nowwhat
 

Similar a In Memory OLTP

SQL Server 2014 Mission Critical Performance - Level 300 Presentation
SQL Server 2014 Mission Critical Performance - Level 300 PresentationSQL Server 2014 Mission Critical Performance - Level 300 Presentation
SQL Server 2014 Mission Critical Performance - Level 300 Presentation
David J Rosenthal
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling Presentation
Tommy Falgout
 
Business Insight 2014 - Microsofts nye BI og database platform - Erling Skaal...
Business Insight 2014 - Microsofts nye BI og database platform - Erling Skaal...Business Insight 2014 - Microsofts nye BI og database platform - Erling Skaal...
Business Insight 2014 - Microsofts nye BI og database platform - Erling Skaal...
Microsoft
 
How_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_FarmHow_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_Farm
Nigel Price
 

Similar a In Memory OLTP (20)

SQL Server 2014 Mission Critical Performance - Level 300 Presentation
SQL Server 2014 Mission Critical Performance - Level 300 PresentationSQL Server 2014 Mission Critical Performance - Level 300 Presentation
SQL Server 2014 Mission Critical Performance - Level 300 Presentation
 
Novedades SQL Server 2014
Novedades SQL Server 2014Novedades SQL Server 2014
Novedades SQL Server 2014
 
Investigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock HolmesInvestigate SQL Server Memory Like Sherlock Holmes
Investigate SQL Server Memory Like Sherlock Holmes
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019
 
MemSQL 201: Advanced Tips and Tricks Webcast
MemSQL 201: Advanced Tips and Tricks WebcastMemSQL 201: Advanced Tips and Tricks Webcast
MemSQL 201: Advanced Tips and Tricks Webcast
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling Presentation
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
 
Star schema my sql
Star schema   my sqlStar schema   my sql
Star schema my sql
 
SQL Server 2014 New Features (Sql Server 2014 Yenilikleri)
SQL Server 2014 New Features (Sql Server 2014 Yenilikleri)SQL Server 2014 New Features (Sql Server 2014 Yenilikleri)
SQL Server 2014 New Features (Sql Server 2014 Yenilikleri)
 
SilverStripe From a Developer's Perspective
SilverStripe From a Developer's PerspectiveSilverStripe From a Developer's Perspective
SilverStripe From a Developer's Perspective
 
In-memory ColumnStore Index
In-memory ColumnStore IndexIn-memory ColumnStore Index
In-memory ColumnStore Index
 
Business Insight 2014 - Microsofts nye BI og database platform - Erling Skaal...
Business Insight 2014 - Microsofts nye BI og database platform - Erling Skaal...Business Insight 2014 - Microsofts nye BI og database platform - Erling Skaal...
Business Insight 2014 - Microsofts nye BI og database platform - Erling Skaal...
 
How_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_FarmHow_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_Farm
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
JSSUG: SQL Sever Performance Tuning
JSSUG: SQL Sever Performance TuningJSSUG: SQL Sever Performance Tuning
JSSUG: SQL Sever Performance Tuning
 
SQL Server 2014 for Developers (Cristian Lefter)
SQL Server 2014 for Developers (Cristian Lefter)SQL Server 2014 for Developers (Cristian Lefter)
SQL Server 2014 for Developers (Cristian Lefter)
 
Operational foundation for the sql server dba
Operational foundation for the sql server dbaOperational foundation for the sql server dba
Operational foundation for the sql server dba
 
Minding SQL Server Memory
Minding SQL Server MemoryMinding SQL Server Memory
Minding SQL Server Memory
 
Mysql database basic user guide
Mysql database basic user guideMysql database basic user guide
Mysql database basic user guide
 
ora_sothea
ora_sotheaora_sothea
ora_sothea
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

In Memory OLTP

  • 2. About.Me() • Veritabanı Yöneticisi / Doğan Online • Eğitimen/Danışman / Btakademi • Kitap Yazarı • Microsoft Certified Trainer ismailadar@hotmail.com http://www.ismailadar.com İsmail Adar @ismailadars
  • 3. Content.GetAgenda() • SQL Server 2014 In-Memory OLTP Basics • Create Database For In-Memory OLTP • Creating Memory Optimized Tables and Indexes • Accessing Memory Optimized Tables • Memory Optimized Tables Limitations • Memory management on memory-optimized tables • Tools for analysis and migration
  • 4. SQL Server 2014 In-Memory OLTP Basics
  • 5.
  • 6. Create Database For In-Memory OLTP code page 1252 associated collation CREATE DATABASE [InMemoryDemo] COLLATE Latin1_General_CI_AI GO ALTER DATABASE [InMemoryDemo] ADD FILEGROUP [InMemory_FStream_FGroup] CONTAINS MEMORY_OPTIMIZED_DATA Filegroup for memory optimized table storage GO ALTER DATABASE [InMemoryDemo] ADD FILE ( NAME = N'InMemoryDemo_FS', FILENAME = N'C:Program FilesMicrosoft SQL ServerMSSQL12.MSSQLSERVERMSSQLDATAInMemoryDemo_FS' ) TO FILEGROUP [InMemory_FStream_FGroup] GO Add file to FS filegroup
  • 7. DEMO Creating Database For In Memory OLTP
  • 8.
  • 9. Create Table DDL Hash Index CREATE TABLE [Customer]( BUCKET_COUNT 1-2X nr of unique index key values [CustomerID] INT NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 1000000), [Name] NVARCHAR(250) NOT NULL, [CreatedDate] DATETIME NULL INDEX [IX_CreatedDate] NONCLUSTERED ) Indexes are specified inline NONCLUSTERED indexes are supported WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA); This table is memory optimized This table is durable
  • 10. Memory Optimized Table Creation CREATE TABLE DDL Code generation and compilation Table DLL produced Table DLL loaded
  • 12. Memory-Optimized Indexes • Exist only in memory – Rebuilt on database startup • Do not contain data rows – Indexes contain memory pointers to the data rows – No duplication of data – All indexes are covering
  • 13. Memory-optimized Table: Row Format Row header Payload (table columns) 8 bytes * (IdxLinkCount) Begin Ts End Ts StmtId IdxLinkCount 8 bytes 8 bytes 4 bytes 2 bytes
  • 14. Memory Optimized Tables and Hash Indexes Timestamps Hash index on Name 50, ∞ Chain ptrs Name City Hash index on City Jane Prague 100, ∞ John Prague 90, ∞ 90, 150 Susan Bogota
  • 15. Nonclustered (range) index • No latch for page updates • No in-place updates on index pages  • 1 PAGE Physical Page size- up to 8K. Sized to the row • Page Mapping Table 0 Handled thru delta pages or building new pages Sibling pages linked one direction  Root PAGE 2 1 0 3 2 0 • 2 8 Require two indexes for ASC/DSC No covering columns (only the key is stored) Page-pid-0 PageID-3 4 8 1 0 1 1 1 5 1 8 2 1 2 4 2 7 Non-leaf pages Logical 1 14 15 2 200, 4 ∞ 5 1 Key 6 2 5 7 50, 300 2 Key 2 6 2 7 Data rows leaf pages
  • 16. DEMO Creating Indexes On Memory Optimized Tables
  • 17.
  • 18. Create Procedure DDL CREATE PROCEDURE [dbo].[InsertOrder] @id INT, @date DATETIME WITH This proc is natively compiled NATIVE_COMPILATION, SCHEMABINDING, Native procs must be schema-bound EXECUTE AS OWNER Execution context is required AS BEGIN ATOMIC WITH Atomic blocks • Create a transaction if there is none • Otherwise, create a savepoint (TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english') -- insert T-SQL here END Session settings are fixed at create time
  • 19. Procedure Creation CREATE PROC DDL Query optimization Code generation and compilation Procedure DLL produced Procedure DLL loaded
  • 20. Accessing Memory Optimized Tables Interpreted T-SQL Access • Access both memory- and disk-based tables • Less performance Natively Compiled Stored Procs • Access only memory optimized tables • Maximum performance • Limited T-SQL surface area • Virtually full T-SQL surface • When to use – Ad hoc queries – Reporting-style queries – Speeding up app migration • When to use – OLTP-style operations – Optimize performance critical business logic
  • 21. Sample AdventureWorks conversion ostress.exe -S. –E -dAdventureWorks2012 -Q"EXEC Sales.usp_InsertOrders @use_inmem = <0,1>, @order_count=100000" –n<varies>
  • 23.
  • 24. Limitations on In-Memory OLTP in SQL 2014 • Tables – – – – – – Triggers: no DDL/DML triggers No Identity columns Data types: no LOBs, no XML and no CLR data types Constraints: no FOREIGN KEY and no CHECK constraints No schema changes (ALTER TABLE) – need to drop/recreate table No add/remove index – need to drop/recreate table • Natively Compiled Stored Procedures – No outer join, no OR, no subqueries, no CASE – Limited built-in functions [core math, date/time, and string functions are available]
  • 25.
  • 26. Memory Management For In-Memory OLTP Data resides in memory at all times • Must configure SQL server with sufficient memory to store memoryoptimized tables • Failure to allocate memory will fail transactional workload at run-time • Integrated with SQL Server memory manager and reacts to memory pressure for GC (Garbage Collection)
  • 27. Memory Management For In-Memory OLTP Integrated with Resource Governor • To ensure performance stability for disk-based table workloads • “Bind” a database to a resource pool • Mem-opt tables in a database cannot exceed the limit of the resource pool • Hard top limit (80% of phys. memory) to ensure system remains stable under memory pressure
  • 28. Memory Management For In-Memory OLTP Memory optimized max memory limit CREATE RESOURCE POOL InMemResourcePool WITH (MAX_MEMORY_PERCENT=40); ALTER RESOURCE GOVERNOR RECONFIGURE; GO EXEC sp_xtp_bind_db_resource_pool 'InMemoryDemoDB','InMemResourcePool'; GO ALTER DATABASE InMemoryDemoDB SET OFFLINE; ALTER DATABASE InMemoryDemoDB SET ONLINE; Filegroup for memory optimized table storage
  • 29. DEMO Memory Management For In-Memory OLTP
  • 30.
  • 32. Resources • Overview of all In-Memory OLTP posts on the SQL Server blog – http://blogs.technet.com/b/dataplatforminsider/archive/2013/10/15/the-411-on-the-microsoft-sql-server-2014-in-memory-oltp-blog-series.aspx • SQL 2014 CTP2 – http://technet.microsoft.com/en-US/evalcenter/dn205290?WT.mc_id=Blog_SQL_InMem_CTP2 • Getting started with In-Memory OLTP – http://blogs.technet.com/b/dataplatforminsider/archive/2013/06/26/getting-started-with-sql-server-2014-in-memory-oltp.aspx • In-Memory OLTP Sample, based on AdventureWorks – https://msftdbprodsamples.codeplex.com/releases/view/114491?WT.mc_id=Blog_SQL_InMem_CTP2 • Analysis and Migration tools – – http://technet.microsoft.com/en-us/library/dn284308(v=sql.120).aspx – • http://technet.microsoft.com/en-us/library/dn205133(v=sql.120).aspx http://technet.microsoft.com/en-us/library/dn358355(v=sql.120).aspx Transaction isolation with In-Memory OLTP – Choosing isolation level: http://msdn.microsoft.com/en-us/library/dn133187(v=sql.120).aspx – Implement retry logic: http://msdn.microsoft.com/en-us/library/dn169141(v=sql.120).aspx • Books Online documentation for In-Memory OLTP – http://technet.microsoft.com/en-us/library/dn133186(v=sql.120).aspx • Limitations and workarounds – http://msdn.microsoft.com/en-us/library/dn247639(v=sql.120).aspx
  • 33. ©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Notas del editor

  1. xxxxx
  2. Talking points:* Main target scenario is high throughput OLTP; other scenarios include ETL, read scale-up (many concurrent transactions reading same data), and burst insert/update (i.e., batches of updates, interfering with read workload)Memory optimized data structuresNovel data structures – no Btree and no PINTABLEUse new structures such as hash indexesTables reside in memoryIndexes exist only in memoryTables are still fully durable – there is a copy of the data on disk for crash recovery purposesNative compilationT-SQL Stored procedures are compiled to native code as DLLsAllows more efficient query execution by reducing the CPU cycles required for each operationLatch- and lock-free data structuresTable structures are multi-versioned. This is built right into the data structures, no tempdb usageData structures are latch free – row updates are realized by inserting new row versionsNo locks, thus no blocking. Transactional consistency is guaranteed through multi-versioning and conflict detectionIntegration in SQL ServerUse the same familiar T-SQL syntax for creating memory optimized tables and natively compiled stored procedures
  3. Talking points:The code page of a (var)char value is determined by the collation associated with the value. For example, the collation SQL_Latin1_General_CP1_CI_AS has the associated code page 1252.-- all supported collations for (var)char columns in memory-optimized tables select * from sys.fn_helpcollations() where collationproperty(name, &apos;codepage&apos;) = 1252;Indexes can only be created on string columns if they use a BIN2 collation. The LastName variable uses BIN2 collation. FirstName uses the database default, which is CI_AS (case-insensitive, accent-sensitive).select * from sys.fn_helpcollations() where name like &apos;%BIN2&apos;
  4. Talking points:* Hash indexes are good for point lookups; need bucket countRange indexes are in the plan; you can think of a range index as a kind of nonclustered index, except that it is memory optimized and latch-free – no bucket-count requiredLike hash indexes, range indexes will be inherently coveringAlter table is not pertimmited
  5. Talking points:This diagram shows what happens when a table is createdTables are compiled for efficient access to table data – knowledge about indexes, columns, datatypes, etc, is baked into the DLLDLL is loaded immediately after compilationDLL is recompiled at server startup, so no risk of anyone tampering with the DLLs while the server is down
  6. Talking points:* Hash indexes are good for point lookups; need bucket countRange indexes are in the plan; you can think of a range index as a kind of nonclustered index, except that it is memory optimized and latch-free – no bucket-count requiredLike hash indexes, range indexes will be inherently covering
  7. Talking points:This diagram shows what happens when a table is createdTables are compiled for more efficient access to table data – knowledge about indexes, columns, datatypes, etc, is baked into the DLLDLL is loaded immediately after compilationDLL is recompiled at server startup, so no risk of anyone tampering with the DLLs while the server is down
  8. Starting SQL “14”, SQL Server has both memory optimized and disk-based tablesThe familiar interpreted T-SQL can be used to access bothHekaton introduces natively compiled stored procedures for efficient access to memory optimized tables, and efficient business logic executionCan access only memory optimized tablesMachine code in DLLs can access the table and index structures directly; machine code requires fewer CPU cycles to execute the queries than the SQL Server query execution engine, interpreting the query execution plan Because most query operators and functions need to be re-implemented for native procs, we have limitations in the query surface area in native procs. For example, no OR, no subqueries, and we will have a limited number of built-in functionsWhile interpreted T-SQL is less performant, there is more flexibility:1. can use ad hoc batches2. no restrictions on T-SQL surface area3. can access both memory optimized and disk-based tables in the same queryWith interop there is still the benefit of latch-free data structuresInterop limitations – No Cursors (except for static readonly cursors, API cursors), table sample, MERGE with memory optimized table as targetYou can start with interop, and over time move to natively compiled stored procedures.
  9. Talking points:The code page of a (var)char value is determined by the collation associated with the value. For example, the collation SQL_Latin1_General_CP1_CI_AS has the associated code page 1252.-- all supported collations for (var)char columns in memory-optimized tables select * from sys.fn_helpcollations() where collationproperty(name, &apos;codepage&apos;) = 1252;Indexes can only be created on string columns if they use a BIN2 collation. The LastName variable uses BIN2 collation. FirstName uses the database default, which is CI_AS (case-insensitive, accent-sensitive).select * from sys.fn_helpcollations() where name like &apos;%BIN2&apos;