Hekaton & CSI Version 2 unter der Lupe Sascha Götz Karlsruhe, 03. Dezember 2013
Most of today s database managers are built on the assumption that data lives on a disk, with little bits of data at a time loaded into memory for manipulation. There s a whole lot of infrastructure involved in paging those subsets of data in and out[ ] - Kevin Farlee, SQL Server program manager, Microsoft - 2
Hekaton 3
Query SQL Server Cache Disk-Based File group Memory-Optimized Memory Index Synchronisation Disk Disk (Memory Dump) Index Paging Locking 4
Filegroup hinzufügen ALTER DATABASE [AdventureWorksDW2012] ADD FILEGROUP [Hekaton_FG] CONTAINS MEMORY_OPTIMIZED_DATA GO Datafile hinzufügen ALTER DATABASE [AdventureWorksDW2012] ADD FILE ( NAME = N'Hekaton', FILENAME = N'C:\Hekaton.ndf') TO FILEGROUP [Hekaton_FG] GO 5
CREATE TABLE [dbo].[factinternetsales_hekaton] ( [ProductKey] [int] NOT NULL, [OrderDateKey] [int] NOT NULL, [...], ) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA) DURABILITY: SCHEMA_AND_DATA Schema und Daten werden mit Disk synchronisiert Speicherplatz wird im RAM und auf Disk benötigt SCHEMA_ONLY Nur Schema wird mit Disk synchronisiert 6
Natively Compiled Stored Procedure CREATE PROCEDURE <Schema_Name, sysname, dbo>.<procedure_name, sysname, Procedure_Name> -- Add the parameters for the stored procedure here [ ] WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER AS BEGIN ATOMIC WITH --Insert statements for the stored procedure here [ ] END Nur Abfrage auf In-Memory Tabellen 7
Index Memory Optimized tables müssen mindestens einen Index haben (auf PK) Keine Clustered Indizes Indexe werden nur im Speicher gehalten Kein Index Drop, Rebuild Max. 8 Index pro Tabelle CI Date Date Non-CI I1 I2 I8 Date Order# 1 11.11.13 13.11.13 1 3 6 13.11.13 98165 2 12.11.13 16.11.13 2 6 2 16.11.13 98121 3 13.11.13 14.11.13 3 4 1 14.11.13 98474 4 14.11.13 17.11.13 4 7 3 17.11.13 98521 5 15.11.13 15.11.13 5 5 4 15.11.13 98451 6 16.11.13 11.11.13 6 1 5 11.11.13 98514 7 17.11.13 12.11.13 7 2 7 12.11.13 98563 8
Limitations Keine Trigger Keine Foreign Key & Constraints Keine Identity columns Keine Schema changes (ALTER TABLE ) 9
Demo
Dauer in Sekunden SQL 2014 CTP1 45 40 Aggregierung (SUM & Group BY) über 2 Mio Datensätze 40 35 30 25 20 20 15 10 5 0 Ohne Index On-Disk In-Memory 4 1 Non-Clustered Index 11
Dauer in Sekunden SQL 2014 CTP1 70 Update 2 Mio Datensätze 60 60 50 52 40 30 32 20 10 0 1 On-Disk In-Memory In-Mermory + Natively Compiled 12
Dauer in Sekunden SQL 2014 CTP1 18 1 Mio. Datensätze Load 17 16 14 13 12 10 8 6 4 2 0 On-Disk 1 In-Memory 13
Vorteile Performance Performance Performance Kritik Stabilität Speichermanagement Auslagerungs-Falle Fehlende Features (FKs, Identity Columns, Constraints) Bestehende Tabellen können nicht in die Hekaton Filegroup verschoben werden 14
Einsatzzweck DURABILITY: SCHEMA_ONLY ETL Load Tabelle Temp Tabellen DURABILITY: SCHEMA_AND_DATA Log-Tabellen 15
Columnstore Index Columnstore Index 2 16
Columnstore Index Non-Clustered Columnstore Index (SQL Server 2012) (+) Performance (+) Easy-To-Use (-) Read-Only Clustered Columnstore Index (SQL Server 2014 CTP 1) (+) Performance (+) Easy-To-Use (+) Updateable (-) Keine PK & FK (-) Keine Constraints 17
Dauer in Sekunden SQL 2014 CTP1 Columnstore Index 120 Aggregierung (SUM & Group BY) über 25 Mio Datensätze 106 100 80 71 60 40 20 9 1 0 1 Ohne Index Non-Clustered Index Non-Clustered Columnstore Index Clustered Columnstore Index 18
Nicht möglich Dauer in Sekunden SQL 2014 CTP1 Columnstore Index 30 1 Mio. Datensätze Load 27 25 23 20 20 15 10 5 0 Ohne Index Non-Clustered Index Non-Clustered Columnstore Index Clustered Columnstore Index 19
Columnstore Index Daten doch Laden bei Non-Clustered Columnstore Index? Drop, Load and Rebuild Drop Load Build 4 20 103 Partition Swap Split Load Build Swap 1 20 5 1 Szenario: 25 Mio Datensätze, Non-Clustered CSI, 1 Mio Datensätze Load 20
Columnstore Index HowTo: Partition Swapping Tabelle partitionieren Leere Partitionen Load in Temp laden Partition Split CSI Index erstellen Switch CSI Facts 2011-2013 <2011 2011 2012 2013 >2013 2014 2014 >2014 21
Dauer in Sekunden Drop & Rebuild SQL 2014 CTP1 Columnstore Index 140 1 Mio. Datensätze Load 127 120 100 80 60 40 20 20 23 27 27 Partition Swap 0 Ohne Index Non-Clustered Index Non-Clustered CSI Non-Clustered CSI2 Clustered Columnstore Index 22
Columnstore Index Fazit Query-Performance: Gigantisch Load-Performance: Mäßig bis Schlecht Nachteile: Vorhanden Einsatzzweck: Non-Clustered CSI BI Fact tables mit daily/nightly Loads Partition Swap oder Index Rebuild Clustered CSI Log Tabellen Solo -Tabellen (ohne PK /FK) 23
Fragen? 24
Ressources SQL Server Hekaton CTP1 White Paper http://download.microsoft.com/download/f/5/0/f5096a71-3c31-4e9f-864e- A6D097A64805/SQL_Server_Hekaton_CTP1_White_Paper.pdf http://blogs.msdn.com/b/arvindsh/archive/2013/07/03/sql-2014-in-memory-oltphekaton-training-videos-and-white-papers.aspx http://www.databasejournal.com/features/mssql/new-enhanced-column-storeindex-in-sql-server-2014-part-1.html http://rusanu.com/2011/07/13/how-to-update-a-table-with-a-columnstore-index/ 25