JULY 2, 2015 SLIDE 1 BOOST YOUR SQL PERFORMANCE BY USING THE NEW FEATURES OF SQL SERVER 2014
Office Azure OS THE ROAD TO SQL SERVER 2014 2008 2010 2012 2014 SQL Server 2008 Audit Compression SQL Server 2008 R2 Multi-Server Admin Data-Tier Applications PowerPivot Change Data Capture Report Builder 2.0 Master Data Services Prepared Instances Data Collector Resource Governor Policy-Based Management PowerShell provider Spatial Data Filestream Data SQL Server 2012 AlwaysOn HA Columnstore Indexes Contained databases User-Defined Server Roles Data Quality Services SSAS Tabular Mode SSIS Catalog SSRS Power View SQL Server 2014 In-Memory OLTP Updateable columnstore Buffer Pool Extensions Enhanced AlwaysOn HA New server-level permissions Deploy to Azure VM Power View from MD SSRS Data Alerts Win Srvr 2008 Win Srvr 2008 R2 Win Srvr 2012 Win Srvr 2012 R2 Deploy to SQL Azure Sys Center 2007 Sys Center 2012 Sys Center 2012 R2 SQL Database Services (REST) Office 2007 Data Mining JULY 2, 2015 SLIDE 2 Add-Ins SQL Azure SQL Azure Reporting Data Market Office 2010 PowerPivot (Excel/SP) SQL Azure = SQL Database MDS Add-in (Excel) Office 2013 Power View(Excel) SQL Server in VMs O365 Power BI Power Query Power Map
ENHANCEMENTS TO SQL SERVER MANAGEMENT STUDIO Code Snippets Quickly create Transact-SQL statements for common tasks Create custom snippet files for your own code Enhanced Debugging Functionality Specify break conditions, filters, and actions Monitor Transact-SQL expressions Display pop-up information Keyboard Shortcuts Visual Studio 2010 Compatible keyboard scheme Alternative keyboard scheme provides shortcuts like those in SQL Server 2008 JULY 2, 2015 SLIDE 3
TRANSACT-SQL ENHANCEMENTS The WITH RESULT SETS clause The THROW Statement The OFFSET and FETCH Keywords Sequence Objects The OVER Clause Inline Syntax for Indexes JULY 2, 2015 SLIDE 4
THE WITH RESULT SETS CLAUSE Override schema of stored procedure results with explicit column names and data types Separate schemas for multiple result sets with a comma JULY 2, 2015 SLIDE 5
THE THROW STATEMENT Raise a custom error message: THROW 55000, 'The object does not exist.', 1; Re-raise an error from a CATCH block: BEGIN TRY SELECT 100/0 AS 'Problem'; END TRY BEGIN CATCH PRINT 'Code inside CATCH is beginning' PRINT 'Error: ' + CAST(ERROR_NUMBER() AS VARCHAR(255)); THROW; END CATCH JULY 2, 2015 SLIDE 6
THE OFFSET AND FETCH KEYWORDS Retrieve a page of rows as a subset of a query result based on: An OFFSET value indicating the first row to include A FETCH value indicating the number of rows to include JULY 2, 2015 SLIDE 7
SEQUENCE OBJECTS Define a sequence of numeric values Use NEXT VALUE FOR to allocate the next available value in the sequence Enables a sequence to be used across multiple tables JULY 2, 2015 SLIDE 8
THE OVER CLAUSE OVER defines a window, or set, of rows to be used by a window function, including any ordering With a specified window partition clause, the OVER clause restricts the set of rows to those with the same values in the partitioning elements JULY 2, 2015 SLIDE 9
INLINE SYNTAX FOR INDEXES Create indexes when creating tables CREATE TABLE dbo.salesorders ( SalesOrderID INTEGER PRIMARY KEY NONCLUSTERED, OrderDate DATETIME NOT NULL, CustomerID INTEGER NOT NULL, ProductID INTEGER NOT NULL, INDEX ix_salesorders_orderdate CLUSTERED (OrderDate) ); JULY 2, 2015 SLIDE 10
NEW AND ENHANCED TRANSACT-SQL FUNCTIONS Conversion Functions Date and Time Functions Logical Functions String Functions JULY 2, 2015 SLIDE 11
CONVERSION FUNCTIONS PARSE SELECT PARSE(' 345.98' AS money USING 'en-gb') -- Returns 345.98 TRY_PARSE SELECT TRY_PARSE(' 345.98' AS money USING 'en-us') -- Returns NULL because is not a valid US symbol TRY_CONVERT SELECT TRY_CONVERT(float, 1.2) -- Returns 1.2 SELECT TRY_CONVERT(float, 'One') -- Returns NULL JULY 2, 2015 SLIDE 12
DATE AND TIME FUNCTIONS Construct date and time values from component parts) Determine the last day of a specified month Function Example Syntax DATEFROMPARTS DATEFROMPARTS (2010, 12, 31) DATETIMEFROMPARTS DATETIMEFROMPARTS (2010, 12, 31, 23, 59, 59, 0) SMALLDATETIMEFROMPARTS SMALLDATETIMEFROMPARTS (2010, 12, 31, 23, 59) DATETIME2FROMPARTS DATETIME2FROMPARTS (2010, 12, 31, 23, 59, 59, 1, 7) TIMEFROMPARTS TIMEFROMPARTS (23, 59, 59, 1, 5) DATETIMEOFFSETFROMPARTS DATETIMEOFFSETFROMPARTS(2010,12,31,14,23,23,1,8,0,7) EOMONTH EOMONTH (GETDATE(), 1) JULY 2, 2015 SLIDE 13
LOGICAL FUNCTIONS CHOOSE DECLARE @MyChoice = 3 SELECT CHOOSE (@MyChoice,'Cash', 'Credit Card', 'Debit Card') -- Returns the 3 rd option ('Debit Card') IIF DECLARE @i = 3 SELECT IIF(@i % 2 = 0, 'Even', 'Odd') -- Returns 'Odd' because the modulo of 3 / 2 is non-zero JULY 2, 2015 SLIDE 14
STRING FUNCTIONS CONCAT SELECT CONCAT(FirstName, ' ', LastName) FROM Customers -- Returns names in the format 'Firstname Lastname' FORMAT SELECT FORMAT(UnitPrice, 'C', 'en-gb') FROM Sales -- Returns values in the format ' 1.99' JULY 2, 2015 SLIDE 15
STORING AND QUERYING DOCUMENTS FileTables Full-Text Enhancements Customizable Proximity Statistical Semantic Search Demonstration: Storing and Querying Documents JULY 2, 2015 SLIDE 16
FILETABLES CREATE TABLE FileStore AS FileTable WITH (FileTable_Directory = 'Documents'); SELECT [name], FileTableRootPath() + file_stream.getfilenamespacepath() [Full Path] FROM FileStore; Name Doc1.rtf Doc2.doc Full Path \\SERVERNAME\MSSQLSERVER\Documents\Doc1.rtf \\SERVERNAME\MSSQLSERVER\Documents\Doc2.doc JULY 2, 2015 SLIDE 17
FULL-TEXT ENHANCEMENTS Additional languages supported Greek Czech Updated word breakers and stemmers Property-scoped searching Search for properties such as Author and Title emitted by ifilters Good support from Microsoft Office 2007 ifilters (.docx,.xlsx,.pptx) SELECT [name] As FileName FROM FileStore WHERE CONTAINS(PROPERTY(file_stream,'Title'),'Bike OR Cycling'); JULY 2, 2015 SLIDE 18
CUSTOMIZABLE PROXIMITY Nearness of results often an indicator of relevance SQL Server 2008 provided fixed determination of nearness Fixed NEAR is now deprecated SQL Server 2014 NEAR allows specification of Maximum number of non-search terms that separate matches SELECT [name] As FileName FROM FileStore WHERE CONTAINS(file_stream, 'NEAR((bicycle, race), 15)'); Requirement for ordering within matches JULY 2, 2015 SLIDE 19
IN-MEMORY DATABASE CAPABILITIES The Buffer Pool Extension Columnstore Indexes Memory-Optimized Tables JULY 2, 2015 SLIDE 20
WHAT IS THE BUFFER POOL EXTENSION? Extends buffer cache to nonvolatile storage Improves performance for readheavy OLTP workloads SSD devices are often more costeffective than adding physical memory Simple configuration with no changes to existing applications. Buffer cache (RAM) Pages Buffer cache extension (SSD) Clean Pages Data files (Disk) JULY 2, 2015 SLIDE 21
BUFFER POOL EXTENSION SCENARIOS OLTP operations with a high volume of reads Up to 32 GB of physical memory Buffer Pool Extension is 4x to 10x physical memory Buffer Pool Extension on high throughput SSD storage JULY 2, 2015 SLIDE 22
CONFIGURING THE BUFFER POOL EXTENSION Enable using ALTER SERVER CONFIGURATION ALTER SERVER CONFIGURATION SET BUFFER POOL EXTENSION ON (FILENAME = 'E:\SSDCACHE\MYCACHE.BPE', SIZE = 50 GB); To Reconfigure, disable and then re-enable JULY 2, 2015 SLIDE 23
WHAT ARE COLUMNSTORE INDEXES? In-memory, compressed data in pages based on columns instead of rows Row Store ProductID OrderDate Cost ProductID Column Store OrderDate Cost data page 1000 data page 1001 310 20010701 2171.29 311 20010701 1912.15 312 20010702 2171.29 313 20010702 413.14 ProductID OrderDate Cost 314 20010701 333.42 315 20010701 1295.00 316 20010702 4233.14 317 20010702 641.22 data page 2000 310 311 312 313 314 315 316 317 318 319 320 321 data page 2001 20010701 20010702 20010703 20010704 data page 2002 2171.29 1912.15 2171.29 413.14 333.42 1295.00 4233.14 641.22 24.95 64.32 1111.25 JULY 2, 2015 SLIDE 24
COLUMNSTORE INDEX SCENARIOS Columnstore indexes are most suitable for: Databases with star or snowflake schemas Tables with large numbers of rows Tables that contain data that responds well to compression JULY 2, 2015 SLIDE 25
CLUSTERED AND NON-CLUSTERED COLUMNSTORE INDEXES Clustered Columnstore Indexes SQL Server 2014 Enterprise, Developer, and Evaluation Edition Only Includes all columns in the table Only index on the table Updatable Non-Clustered Columnstore Indexes Includes some or all columns in the table Can be combined with other indexes Read-Only JULY 2, 2015 SLIDE 26
CREATING A COLUMNSTORE INDEX CREATE CLUSTERED COLUMNSTORE INDEX csidx_factsalesorderdetails ON FactSalesOrderDetails; CREATE NONCLUSTERED COLUMNSTORE INDEX nccsidx_factsalesorder ON FactSalesOrder (CustomerKey, SalesPersonKey, ProductKey, OrderDateKey, OrderNo, ItemNo, Quantity, Cost, SalesAmount, Shipping, Discount); JULY 2, 2015 SLIDE 27
WHAT ARE MEMORY-OPTIMIZED TABLES? JULY 2, 2015 SLIDE 28 Defined as C structs, compiled into DLLs, and loaded into memory Can be persisted as filestreams, or non-durable Do not apply any locking semantics Can be indexed using hash indexes Can co-exist with disk-based tables Can be queried using Transact-SQL Cannot include some data types, including text, image, and nvarchar(max) Do not support identity columns or foreign key constraints
MEMORY-OPTIMIZED TABLE SCENARIOS Optimistic concurrency optimizes latch-bound workloads: Multiple concurrent transactions modify large numbers of rows A table contains hot pages Applications should handle conflict errors: Write conflicts Repeatable read validation failures Serializable validation failures Commit dependency failures JULY 2, 2015 SLIDE 29
CREATING MEMORY-OPTIMIZED TABLES Add a filegroup for memory-optimized data ALTER DATABASE MyDB ADD FILEGROUP mem_data CONTAINS MEMORY_OPTIMIZED_DATA; GO ALTER DATABASE MyDB ADD FILE (NAME = 'MemData' FILENAME = 'D:\Data\MyDB_MemData.ndf') TO FILEGROUP mem_data; Create a memory-optimized table CREATE TABLE dbo.memorytable (OrderId INTEGER NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 1000000), OrderDate DATETIME NOT NULL, ProductCode INTEGER NULL, Quantity INTEGER NULL) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA); JULY 2, 2015 SLIDE 30
MEMORY-OPTIMIZED TABLE INDEXES Hash indexes Assign rows to buckets based on hashing algorithm Multiple rows in the same bucket form a linked list Range indexes Use a latch-free BW-Tree structure CREATE TABLE dbo.indexedmemorytable (OrderId INTEGER NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 100000), OrderDate DATETIME NOT NULL, ProductCode INTEGER NULL, Quantity INTEGER NULL INDEX idx_memtab_orderdate NONCLUSTERED HASH(OrderDate) WITH (BUCKET_COUNT = 100000)) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA); JULY 2, 2015 SLIDE 31
QUERYING MEMORY-OPTIMIZED TABLES JULY 2, 2015 SLIDE 32 Query Interop Interpreted Transact- SQL Enables queries that combine memoryoptimized and diskbased tables Native Compilation Stored procedure converted to C and compiled Access to memoryoptimized tables only Native Compilation CREATE PROCEDURE Translate to C #define in HRESULT hkp_( Compile to DLL 0110101101 Tab1 Tab2 Tab3 Tab4 Memory-Optimized Tables Query Interop Transact-SQL SELECT t1.col1, t3.col2 FROM Tab1 t1 JOIN Tab2 t2 ON t1.col1 = t2.col1; Disk-Based Tables
CREATING NATIVE STORED PROCEDURES CREATE PROCEDURE Statement NATIVE_COMPILATION option SCHEMABINDING option EXECUTE AS option BEGIN ATOMIC clause JULY 2, 2015 SLIDE 33 CREATE PROCEDURE dbo.deletecustomer @CustomerID INT WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER AS BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL = SNAPSHOT; LANGUAGE = 'us_english') DELETE dbo.customer WHERE CustomerID = @CustomerID DELETE dbo.openorders WHERE CustomerID = @CustomerID END;
PLANNING MEMORY-OPTIMIZED TABLES Use the AMR tool to analyze existing workloads Use the Transaction Performance Collection Sets View Transaction Performance Analysis Overview report from Data Collector MDW Displays tables scattered by performance gain and migration effort High Gain Low Gain T3 T2 T1 JULY 2, 2015 SLIDE 34 Significant migration work Minimal migration work
NEW AND ENHANCED DYNAMIC MANAGEMENT VIEWS Troubleshooting Queries Demonstration: Using sys.dm_exec_query_stats Viewing Disk and Operating System Information Demonstration: Using sys.dm_os_volume_stats Viewing SQL Server Configuration Information Demonstration: Using sys.dm_server_services and sys.dm_server_registry JULY 2, 2015 SLIDE 35
TROUBLESHOOTING QUERIES sys.dm_exec_query_stats Troubleshoot long running queries Identify CPU and I/O intensive queries In this demonstration, you will see how to: Retrieve Query Statistics JULY 2, 2015 SLIDE 36
VIEWING DISK AND OPERATING SYSTEM INFORMATION sys.dm_os_volume_stats sys.dm_os_windows_info In this demonstration, you will see how to: Retrieve Volume Statistics JULY 2, 2015 SLIDE 37
VIEWING SQL SERVER CONFIGURATION INFORMATION sys.dm_server_memory_dumps Filename, Creation_time; Size_in_bytes sys.dm_server_services Service startup mode, Current state, Service Account sys.dm_server_registry Current version, Available services, Network configuration Demonstration : Retrieve Services Information Retrieve Server Registry Information JULY 2, 2015 SLIDE 38
THANK YOU Follow us on: Selected presentations are available on: WWW.REALDOLMEN.COM JULY 2, 2015 SLIDE 39