{"id":82018,"date":"2007-08-06T20:40:55","date_gmt":"2007-08-06T20:40:55","guid":{"rendered":"https:\/\/www.webstaging.red-gate.com\/simple-talk\/?p=73161"},"modified":"2019-11-08T13:59:10","modified_gmt":"2019-11-08T13:59:10","slug":"sys-dm_exec_query_optimizer_info","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/sys-dm_exec_query_optimizer_info\/","title":{"rendered":"sys.dm_exec_query_optimizer_info"},"content":{"rendered":"<p>Information about how queries have been optimized since the server has been restarted. Note that counters are only affected when there is some sort of optimization event, not on every query.<\/p>\n<p><b>Type<\/b>: View<\/p>\n<p><b>Data<\/b>: Accumulating reset at restart<\/p>\n<p><b>Columns:<\/b><\/p>\n<ul>\n<li><b>counter<\/b> &#8211; Name of the query<\/li>\n<li><b>occurrence \u2013 <\/b>Number of times<b> <\/b>the counter was recorded to<b><\/b><\/li>\n<li><b>value \u2013 <\/b>May or may not have some value, but is typically an average of the values that were recorded when the counter was written to (for a complete list of counters, check the books online documentation on sys.dm_exec_query_optimizer_info (1))<b><\/b><\/li>\n<\/ul>\n<p><b>Example:<\/b><\/p>\n<p>As an example, on a low use server, I restarted the server and executed:<\/p>\n<p>select counter,occurrence, value<br \/>\nfrom sys.dm_exec_query_optimizer_info<\/p>\n<p>You will get values like:<\/p>\n<p>counter\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 occurrence\u00a0\u00a0\u00a0 value<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; <br \/>\noptimizations\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01<br \/>\nelapsed time\u00a0\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0.0235776097702821<br \/>\nfinal cost\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4.1957E-05<\/p>\n<p>This tells you the number of statements that have been optimized and a plan created (the same value is for all three of the displayed counters), the average elapsed time spent compiling in the value column for the elapsed time row, and finally, the average final cost in the final cost row. Using these counters and some of the others you will discover will help you to determine how often statements ae being compiled.<\/p>\n<p>Execute it again, it will give you the same values (assuming you are the only user, of course.) Now, execute the same query, this time making it uppercase, forcing another complication, since plans must match in every way:<\/p>\n<p>SELECT COUNTER, OCCURRENCE, VALUE<br \/>\nFROM SYS.DM_EXEC_QUERY_OPTIMIZER_INFO<\/p>\n<p>You will see that the occurrences have increased, and there may be some difference in the average time it took:<\/p>\n<p>counter\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 occurrence\u00a0\u00a0\u00a0 value<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; <br \/>\noptimizations\u00a0\u00a0\u00a0\u00a0\u00a02\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01<br \/>\nelapsed time\u00a0\u00a0\u00a0\u00a0\u00a0\u00a02\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0.020978588737036<br \/>\nfinal cost\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4.1957E-05<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>Note:\u00a0 This is part of an ongoing project to write a book about all of the dynamic management views for <a href=\"http:\/\/www.red-gate.com\" target=\"_blank\" rel=\"noopener\">Red-Gate<\/a>.\u00a0It will be freely distributable once complete as an ebook.\u00a0Any examples, suggestions, corrections are desired and will certainly be mentioned in the final book.\u00a0 Also, I will begin maintaining the following web page once the book is closer to completion: <a href=\"http:\/\/drsql.org\/dmvbook.aspx\">http:\/\/drsql.org\/dmvbook.aspx<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Information about how queries have been optimized since the server has been restarted. Note that counters are only affected when there is some sort of optimization event, not on every query. Type: View Data: Accumulating reset at restart Columns: counter &#8211; Name of the query occurrence \u2013 Number of times the counter was recorded to&#8230;&hellip;<\/p>\n","protected":false},"author":56085,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[19684],"class_list":["post-82018","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/82018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/56085"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=82018"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/82018\/revisions"}],"predecessor-version":[{"id":85666,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/82018\/revisions\/85666"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=82018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=82018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=82018"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=82018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}