{"id":1433,"date":"2014-02-21T09:30:00","date_gmt":"2014-02-21T17:30:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/dataplatforminsider\/2014\/02\/21\/using-natively-compiled-stored-procedures-in-sql-server-2014\/"},"modified":"2024-01-22T22:49:01","modified_gmt":"2024-01-23T06:49:01","slug":"using-natively-compiled-stored-procedures-in-sql-server-2014","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/sql-server\/blog\/2014\/02\/21\/using-natively-compiled-stored-procedures-in-sql-server-2014\/","title":{"rendered":"Using Natively Compiled Stored Procedures in SQL Server 2014"},"content":{"rendered":"

The new In-Memory OLTP feature in SQL Server 2014 greatly optimizes the performance of certain OLTP applications. By using the new memory-optimized tables you can speed up data access, in particular in concurrency situations, due to the lock- and latch-free architecture of the In-Memory OLTP Engine. This means that applications which suffer from a lot of contention between concurrent transactions can greatly benefit from just migrating your hot tables to memory-optimized.<\/p>\n

The other part of the equation are the new natively compiled stored procedures, which allow you to speed up query processing and business logic execution. These native procs are T-SQL stored procedures that are compiled to native code, in the form of DLLs, which are linked to the SQL Server process, for very efficient execution. The efficiency in natively compiled procs comes from savings in the execution path by baking the operations into machine code that can interact very efficiently with the In-Memory storage engine. For example, when scanning an index and identifying rows that match a certain predicate, we see that a native proc requires around 1\/4th<\/sup> the number of CPU instructions compared with traditional interpreted T-SQL queries and stored procedures.<\/p>\n

In this post we walk through some of the considerations when developing and using natively compiled stored procedures in your application.<\/p>\n

OLTP-Style Operations<\/h1>\n

Natively compiled stored procedures are optimized for OLTP-style operations. Now, what do we mean by that? Some characteristics: a) single-threaded execution (MAXDOP=1); b)\u00a0point lookups and small range scans, no full table scans, in general operations that touch a relatively small number of rows; c) nested-loops joins and stream aggregation; d) short-running transactions, in the ideal case a transaction spans a single execution of a natively compiled stored procedure.<\/p>\n

Some examples of OLTP-style operations:<\/p>\n