There’s a special Microsoft product that has come a long way since its first OS/2 version. Actually this year, the 12th version of the product marks 25 years from the start, 25 years of Microsoft SQL Server.
Over the years, we have seen many amazing and innovative technologies such as SQL CLR, Service Broker, Resource Governor or recently the cloud-based version of SQL Server. And each time we concluded that we have seen it all, another version came to surprise us. SQL Server 2014 is no exception and I guarantee that some of its features will know your socks off!
I will say just “In-Memory OLTP” and “Updatable Clustered Columnstore Indexes” and it should be enough. But there’s more than that! Come to this session to find out for yourself!
Handwritten Text Recognition for manuscripts and early printed texts
SQL Server 2014 for Developers (Cristian Lefter)
1. Premium community conference on Microsoft technologies itcampro@ itcamp14#
SQL Server 2014 for
Developers
Cristian Lefter, SQL Server MVP
http://about.me/CristianLefter
2. Premium community conference on Microsoft technologies itcampro@ itcamp14#
Huge thanks to our sponsors & partners!
3. Premium community conference on Microsoft technologies itcampro@ itcamp14#
WHAT’S NEW IN DATABASE ENGINE
SQL Server 2014
4. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Code name Hekaton
• Memory-optimized Tables
• Natively compiled stored procedures
• It’s all about optimism versus pessimism
• 100x times faster – how?
• It’s a project started in Microsoft Research
• Hekaton Team: Cristian Diaconu
• It also applies to Table-Valued Parameters and
Table Variables
CREATE TYPE
[Sales].[SalesOrderDetailType_inmem] AS TABLE(
[OrderQty] [smallint] NOT NULL,
[ProductID] [int] NOT NULL,
[SpecialOfferID] [int] NOT NULL,
[LocalID] [int] NOT NULL,
INDEX [IX_ProductID] HASH ([ProductID]) WITH
( BUCKET_COUNT = 8),
INDEX [IX_SpecialOfferID] NONCLUSTERED
)
WITH ( MEMORY_OPTIMIZED = ON )
In-memory OLTP
5. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Not for everyone
• Optimistic Multi-version Concurrency Control
• Best scenario: highly concurrent workloads using small transactions
In-memory OLTP (cont.)
6. Premium community conference on Microsoft technologies itcampro@ itcamp14#
In-memory OLTP (cont.)
Workload Pattern Implementation Scenario Benefits
High data insertion rate
from multiple concurrent
connections.
Primarily append-only store.
Unable to keep up with the insert
workload.
Eliminate contention.
Reduce logging.
Read performance and
scale with periodic batch
inserts and updates.
High performance read operations,
especially when each server request has
multiple read operations to perform.
Unable to meet scale-up requirements.
Eliminate contention when new
data arrives.
Lower latency data retrieval.
Minimize code execution time.
Intensive business logic
processing in the
database server.
Insert, update, and delete workload.
Intensive computation inside stored
procedures.
Read and write contention.
Eliminate contention.
Minimize code execution time for
reduced latency and improved
throughput.
Low latency. Require low latency business transactions
which typical database solutions cannot
achieve.
Eliminate contention.
Minimize code execution time.
Low latency code execution.
Efficient data retrieval.
Session state
management.
Frequent insert, update and point
lookups.
High scale load from numerous stateless
web servers.
Eliminate contention. Efficient
data retrieval. Optional IO
reduction or removal, when using
non-durable tables
7. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Buffer Pool Extension to SSD (Solid State Disks)
• Only “clean” pages are stored to the Buffer Pool
Extension
• Increased random I/O throughput
• Reduced I/O latency
• Increased transaction throughput
• Improved read performance with a larger hybrid buffer
pool
• A caching architecture that can take advantage of
present and future low-cost memory drives
• Supported in Standard and Enterprise editions
• Best scenario: databases larger than available memory
Buffer Pool Extension
8. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• SELECT … INTO can operate in parallel
• Database compatibility level at least 110.
• Main benefit – performance
SELECT … INTO can run in parallel
9. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Customize the wait priority of an online operation using the
WAIT_AT_LOW_PRIORITY option
Syntax:
<low_priority_lock_wait>::= {
WAIT_AT_LOW_PRIORITY ( MAX_DURATION = <time> [ MINUTES ] ,
ABORT_AFTER_WAIT = { NONE | SELF |
BLOCKERS } ) }
Example:
ALTER INDEX ALL ON Production.Product REBUILD WITH
(
FILLFACTOR = 80,
SORT_IN_TEMPDB = ON,
STATISTICS_NORECOMPUTE = ON,
ONLINE = ON ( WAIT_AT_LOW_PRIORITY ( MAX_DURATION = 4 MINUTES,
ABORT_AFTER_WAIT = BLOCKERS ) ),
DATA_COMPRESSION = ROW
);
Managing the lock priority of online operations
10. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• The cardinality estimator is re-designed in SQL Server 2014
• Improve query plans (improved query performance)
Example:
SELECT P.EnglishProductName, F.OrderDate
FROM [dbo].[FactInternetSales_V2] F
JOIN [dbo].[DimProduct] P
ON F.ProductKey = P.ProductKey
(1268358 row(s) affected)
New Design for Cardinality Estimation
SQL Server 2014 SQL Server 2012
11. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• The individual partitions of partitioned tables can now be rebuilt online.
• Can be used with Managed Lock Priority feature.
• Increases database availability.
Partial Syntax:
ALTER INDEX { index_name | ALL } ON <object> {
REBUILD
[ PARTITION = ALL ]
[ WITH ( <rebuild_index_option> [ ,...n ] ) ]
| [ PARTITION = partition_number
[ WITH ( <single_partition_rebuild_index_option> ) [
,...n ] ] ... } [ ; ]
<single_partition_rebuild_index_option> ::=
{
SORT_IN_TEMPDB = { ON | OFF } | MAXDOP = max_degree_of_parallelism
| DATA_COMPRESSION = { NONE | ROW | PAGE | COLUMNSTORE |
COLUMNSTORE_ARCHIVE} }
| ONLINE = { ON [ ( <low_priority_lock_wait> ) ] | OFF }
}
Partition Switching and Indexing
12. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Specifying the encryption algorithm and the encryptor (a Certificate or Asymmetric Key)
• All storage destinations: on-premises and Window Azure storage are supported.
• Encryption Algorithm supported: AES 128, AES 192, AES 256, and Triple DES
• Encryptor: A certificate or asymmetric Key
• For restore, the certificate or the asymmetric key used to encrypt the backup file, must be
available on the instance that you are restoring to.
Backup Encryption
13. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Reduce latency using delayed durable transactions
• Delayed durable transaction means that the control is return to the
client before the transaction log record is written to disk
• Can be controlled at:
– The database level
– The COMMIT level
– The ATOMIC block level
Syntax:
-- at the database level
ALTER DATABASE dbname
SET DELAYED_DURABILITY = DISABLED | ALLOWED | FORCED;
-- at the COMMIT level
COMMIT TRANSACTION WITH (DELAYED_DURABILITY = ON);
-- at the ATOMIC block level
BEGIN ATOMIC WITH (DELAYED_DURABILITY = ON, ...)
Delayed Durability
14. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Column-based data storage.
• Optimized for bulk loads and read-only queries.
• Up to 10x query performance and up to 7x data
compression.
• SQL Server 2012:
– nonclustered columnstore indexes
– batch mode processing
– nonclustered columnstore indexes result in a read-
only table
• SQL Server 2014
– updatable clustered columnstore indexes
– archival data compression
Updateable Clustered Columnstore Indexes
• In SQL Server, a clustered columnstore index:
– Available in Enterprise, Developer, and Evaluation editions
– Is the primary storage method for the entire table.
– Has no key columns. All columns are included columns.
– Is the only index on the table. It cannot be combined with any other indexes.
– Rebuilding the columnstore index requires an exclusive lock on the table or partition
• Best scenario: application requiring large scans and aggregations
15. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Statistics can be created at partition level.
• New partition won’t require statistics update for the entire table!
• INCREMENTAL option
• Not supported for:
– Statistics created with indexes that are not partition-aligned with the base table.
– Statistics created on AlwaysOn readable secondary databases.
– Statistics created on read-only databases.
– Statistics created on filtered indexes.
– Statistics created on views.
– Statistics created on internal tables.
– Statistics created with spatial indexes or XML indexes.
Example:
UPDATE STATISTICS MyTable(MyStatistics)
WITH RESAMPLE ON PARTITIONS(3, 4);
Incremental Statistics
16. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Physical IO Control using
MIN_IOPS_PER_VOLUME and
MAX_IOPS_PER_VOLUME settings for a
resource pool.
• The MAX_OUTSTANDING_IO_PER_VOLUME
option sets the maximum queued I/O
operations per disk volume.
Resource Governor enhancements for physical IO control
18. Premium community conference on Microsoft technologies itcampro@ itcamp14#
• Allows monitoring queries in real time.
• SET STATISTICS PROFILE ON or SET
STATISTICS XML ON are necessary to serialize the
requests of sys.dm_exec_query_profiles and
return the final results
The sys.dm_exec_query_profiles DMV
19. Premium community conference on Microsoft technologies itcampro@ itcamp14#
Partial Syntax:
--Disk-Based CREATE TABLE Syntax
CREATE TABLE [ database_name . [ schema_name ] . | schema_name . ]
table_name [ AS FileTable ]
( { <column_definition> | <computed_column_definition>
| <column_set_definition> | [ <table_constraint> ]
| [ <table_index> ] [ ,...n ] } )... [ ; ]
< table_index > ::=
INDEX index_name [ CLUSTERED | NONCLUSTERED ] (column [ ASC | DESC ]
[ ,... n ] )
[ WITH ( <index_option> [ ,... n ] ) ]
[ ON { partition_scheme_name (column_name ) | filegroup_name
| default }]
Example:
CREATE TABLE dbo.MyTable
(
i INT, INDEX idx_MyTable_i NONCLUSTERED(i DESC)
);
Inline specification of CLUSTERED and NONCLUSTERED
20. Premium community conference on Microsoft technologies itcampro@ itcamp14#
DEMO
SQL Server 2014 - What’s New in Database engine