{"id":1754,"date":"2013-12-19T17:02:01","date_gmt":"2013-12-20T01:02:01","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/bobb\/?p=1754"},"modified":"2013-12-19T17:02:01","modified_gmt":"2013-12-20T01:02:01","slug":"tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/","title":{"rendered":"Tracking execution stats of SQL Server 2014 natively-compiled sprocs"},"content":{"rendered":"<p>Haven&#8217;t had time to blog much lately. Finding out strange and interesting things about SQL Server 2014 to present at some seminars and conferences next year. &#8220;Shameless self-promotion&#8221; posts for those events will be forthcoming. \ud83d\ude09\u00a0A few days ago, an experiment with tracking compiled stored procedures turned up some &#8220;interesting&#8221; results. Thought I&#8217;d write about that.<\/p>\n<p>You normally get information about query execution at a query level with sys.dm_exec_query_stats, and info at a stored procedure level sys.dm_exec_procedure_stats. However, with in-memory, OLTP the point is to make things run as quickly as possible and, as such statistics (such as worker_time and elasped_time) don&#8217;t get collected. By default *nothing* appears in these DMVs about compiled sprocs. Not even a count of the number of time it&#8217;s been executed.<\/p>\n<p>However, Books Online mentions using sys.sp_xtp_control_query_exec_stats and sys.sp_xtp_control_proc_exec_stats to enable collection. Although sys.sp_xtp_control_proc_exec_stats controls a global setting, sys.sp_xtp_control_query_exec_stats controls collecting query information on a per-proc basis. That is, you can turn in on\/off for individual compiled stored procedures.<\/p>\n<p>I needed a test bed to try this out. Since there is a nice, new in-memory-OLTP sample on Codeplex\u00a0that layers on top of the AdventureWorks2012 database, and being the lazy person I am, I decided to use this one. Shouldn&#8217;t have been so lazy, perhaps. I downloaded the sample, downloaded AdventureWorks2012 and found interesting behaviors right off. After attaching the data (mdf) file with ObjectExplorer, I found the the database had no owner (owner is blank). That ruined the sample setup, so I changed the database owner to &#8216;sa&#8217;. Then the sample setup ran. Next, I issued the statement:<\/p>\n<p>select * from sys.sql_modules where uses_native_compilation = 1;<\/p>\n<p>This produced output naming two stored procedures (good) and four triggers (not so good, triggers can&#8217;t be natively compiled). One for the Connect site.<\/p>\n<p>Strangely the native\u00a0procedures were named Sales.usp_InsertSalesOrder_inmem and Sales.usp_UpdateSalesOrderShipInfo_native. While I wondered why they both weren&#8217;t suffixed by _inmem or _native, I found additional stored procedures in the demo that ended in &#8220;_inmem&#8221; and WEREN&#8217;T compiled stored procedures, they just referenced in-memory tables. One for me to remember when looking at the results.<\/p>\n<p>Started by clearing the procedure cache (DBCC FREEPROCCACHE, standard disclaimer not to do this on production) and inserting 10000 rows and updating additional rows with collection off (the default). Took 7 seconds. After this experiment there were no rows for those procedures\/queries in the two DMVs. Good. Now turn global settings on for both types of collection, free proccache, and run again. Executes in 4 seconds. Something needed some &#8220;warmup&#8221; because I would have expected &#8220;with collection&#8221; to take longer. OK let&#8217;s look at the DMVs.<\/p>\n<p>For query_stats, there are 5 queries in the two compiled sprocs. I get sql_handle (for the query), start\/end offset, creation\/last execution time, and the worker_time and elasped_time buckets. Nothing else. I don&#8217;t know what possessed me to think there&#8217;s be something in read\/write counts, but these were zero, because of the way memory-optimized tables are stored. They&#8217;re not in stored in pages. Procedure_stats had the same sparse infomation, which I was used to by then.<\/p>\n<p>In case you were wondering what the query plan looked like, there wasn&#8217;t one exposed. Plan_handle was zeros for those queries. In SQL Server 2014 CTP2 you still can&#8217;t get an actual query plan (with actual counts), but you can get an estimated plan. The estimated plans are really sparse as far as information goes, compared to what you&#8217;re used to.<\/p>\n<p>One final surprise was that, I thought I&#8217;d run multiple iterations of the test, using DBCC FREEPROCCACHE in between to zero the numbers. Not only does turning off data collection not zero the numbers, but running <strong>DBCC FREEPROCCACHE doesn&#8217;t get rid of the rows<\/strong>, either. These rows remain in the DMV until I drop and re-create the natively compiled proc. Or restart SQL Server, of course. That&#8217;s something I wasn&#8217;t expecting, but logic-ing it out a bit, perhaps this information wasn&#8217;t retrieved from the plan cache. Sure enough, looking at sys.dm_exec_cached_plans yielded no rows for these plans, because they&#8217;re not traditional plans.<\/p>\n<p>That&#8217;s enough fun for now, hopefully. More, on related topics, perhaps, coming&#8230;sometime.<\/p>\n<p>@bobbeauch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Haven&#8217;t had time to blog much lately. Finding out strange and interesting things about SQL Server 2014 to present at some seminars and conferences next year. &#8220;Shameless self-promotion&#8221; posts for those events will be forthcoming. \ud83d\ude09\u00a0A few days ago, an experiment with tracking compiled stored procedures turned up some &#8220;interesting&#8221; results. Thought I&#8217;d write about [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,41],"tags":[],"class_list":["post-1754","post","type-post","status-publish","format-standard","hentry","category-hekaton","category-sql-server-2014"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Tracking execution stats of SQL Server 2014 natively-compiled sprocs - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tracking execution stats of SQL Server 2014 natively-compiled sprocs - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"Haven&#8217;t had time to blog much lately. Finding out strange and interesting things about SQL Server 2014 to present at some seminars and conferences next year. &#8220;Shameless self-promotion&#8221; posts for those events will be forthcoming. \ud83d\ude09\u00a0A few days ago, an experiment with tracking compiled stored procedures turned up some &#8220;interesting&#8221; results. Thought I&#8217;d write about [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2013-12-20T01:02:01+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/\",\"name\":\"Tracking execution stats of SQL Server 2014 natively-compiled sprocs - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2013-12-20T01:02:01+00:00\",\"dateModified\":\"2013-12-20T01:02:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hekaton\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/hekaton\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Tracking execution stats of SQL Server 2014 natively-compiled sprocs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tracking execution stats of SQL Server 2014 natively-compiled sprocs - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/","og_locale":"en_US","og_type":"article","og_title":"Tracking execution stats of SQL Server 2014 natively-compiled sprocs - Bob Beauchemin","og_description":"Haven&#8217;t had time to blog much lately. Finding out strange and interesting things about SQL Server 2014 to present at some seminars and conferences next year. &#8220;Shameless self-promotion&#8221; posts for those events will be forthcoming. \ud83d\ude09\u00a0A few days ago, an experiment with tracking compiled stored procedures turned up some &#8220;interesting&#8221; results. Thought I&#8217;d write about [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/","og_site_name":"Bob Beauchemin","article_published_time":"2013-12-20T01:02:01+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/","name":"Tracking execution stats of SQL Server 2014 natively-compiled sprocs - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2013-12-20T01:02:01+00:00","dateModified":"2013-12-20T01:02:01+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/tracking-execution-stats-of-sql-server-2014-natively-compiled-sprocs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"Hekaton","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/hekaton\/"},{"@type":"ListItem","position":3,"name":"Tracking execution stats of SQL Server 2014 natively-compiled sprocs"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/1754","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=1754"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/1754\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=1754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=1754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=1754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}