Using In-Memory Tables

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Module 12

Using In-Memory Tables


Module Overview

Memory-Optimized Tables
• Natively Compiled Stored Procedures
Lesson 1: Memory-Optimized Tables

What Are Memory-Optimized Tables?


Scenarios for Memory-Optimized Tables
Creating a Filegroup for Memory-Optimized Data
Creating Memory-Optimized Tables
Indexes in Memory-Optimized Tables
Converting Tables with Memory Optimization
Advisor
Querying Memory-Optimized Tables
• Demonstration: Using Memory-Optimized Tables
What Are Memory-Optimized Tables?

• Defined as C structs, compiled into DLLs, and


loaded into memory
• Can be persisted as FILESTREAM data, or
nondurable
• Do not apply any locking semantics
• Contain at least one index
• Can coexist with disk-based tables
• Can be queried by using Transact-SQL
• Support most data types and features
Scenarios for Memory-Optimized Tables

• Optimistic concurrency optimizes latch-bound


workloads
• Common scenarios:
• Multiple concurrent transactions modifying large
numbers of rows
• A table containing “hot” pages

• Applications should handle conflict errors:


• Write conflicts
• Repeatable read validation failures
• Serializable validation failures
• Commit dependency failures
Creating a Filegroup for Memory-Optimized
Data

• Databases with memory-optimized tables must


contain a filegroup for memory-optimized data
• Either:
• Use Transact-SQL, or
• Filegroups page of database properties in SSMS
Creating Memory-Optimized Tables

• Durability
• SCHEMA_AND_DATA
• SCHEMA_ONLY

• Primary Keys
• Must use for SCHEMA_AND_DATA durability
• Specify inline or after columns
• Must specify NONCLUSTERED
Indexes in Memory-Optimized Tables

• Nonclustered hash indexes


• Assign rows to buckets based on a hashing algorithm
• Optimized for equality seeks

• Nonclustered indexes
• Use a latch-free BW-tree structure
• Support equality seeks, inequality seeks, and sort order

• Decide which type of index to use


Converting Tables with Memory Optimization
Advisor

• Memory Optimization Checklist


• Memory Optimization Warnings
• Review Optimization Options
• Review Primary Key Conversion
• Review Index Conversion
• Verify Migration Actions
Querying Memory-Optimized Tables

• Interpreted Transact-SQL
• Enables memory-optimized tables in the same way as
disk-based tables
• Provides an interop layer
• Enables queries that combine memory-optimized and
disk-based tables
• Natively Compiled Stored Procedures
• Increased performance
• Stored procedure converted to C and compiled
• Access to memory-optimized tables only
Demonstration: Using Memory-Optimized
Tables

In this demonstration, you will see how to:


• Create a database with a filegroup for memory-
optimized data
• Use memory-optimized tables
Lesson 2: Natively Compiled Stored Procedures

What Are Natively Compiled Stored Procedures?


When to use Natively Compiled Stored Procedures
Creating Natively Compiled Stored Procedures
Execution Statistics
• Demonstration: Creating a Natively Compiled
Stored Procedure
What Are Natively Compiled Stored Procedures?

• Written in Transact-SQL and compiled to native


code at creation time
• Access memory-optimized tables
• Offer greater speed and efficiency
• Contain one atomic block—will succeed or fail as
a single unit
When to use Natively Compiled Stored
Procedures

• Use natively compiled stored procedures when:


• Performance is critical
• There are many rows to be processed
• The stored procedure is called frequently
• Logic that uses:
• Aggregation
• Nested-loop joins
• Multistatement select, insert, update, and deletes
• Complex expressions
• Procedural logic
• Avoid named parameters
Creating Natively Compiled Stored Procedures

• CREATE PROCEDURE statement


• NATIVE_COMPILATION option
• SCHEMABINDING option
• EXECUTE AS option
• BEGIN ATOMIC clause
Execution Statistics

• To enable the collection of statistics, use


sys.sp_xtp_control_proc_stats
• To monitor the performance of a natively
compiled stored procedure, use
sys.dm_exec_procedure_stats
Demonstration: Creating a Natively Compiled
Stored Procedure

In this demonstration, you will see how to:


• Create a natively compiled stored procedure
Lab: Using In-Memory Database Capabilities

Exercise 1: Using Memory-Optimized Tables


• Exercise 2: Using Natively Compiled Stored
Procedures

Logon Information
Virtual machine: 20762C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd

Estimated Time: 45 minutes


Lab Scenario

You are planning to optimize some database


workloads by using the in-memory database
capabilities of SQL Server. You will create
memory-optimized tables and natively compiled
stored procedures to optimize OLTP workloads.
Lab Review

• In this lab, you should have created a natively


compiled stored procedure.
Module Review and Takeaways

• Review Question(s)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy