{"id":1897,"date":"2016-04-12T16:30:01","date_gmt":"2016-04-12T14:30:01","guid":{"rendered":"https:\/\/www.sqlinthewild.co.za\/?p=1897"},"modified":"2016-04-14T23:52:50","modified_gmt":"2016-04-14T21:52:50","slug":"sql-server-2016-features-live-query-statistics","status":"publish","type":"post","link":"https:\/\/www.sqlinthewild.co.za\/index.php\/2016\/04\/12\/sql-server-2016-features-live-query-statistics\/","title":{"rendered":"SQL Server 2016 features: Live query statistics"},"content":{"rendered":"<p>Ever wanted to look at a query\u2019s actual execution plan (execution plan with runtime information) without waiting for the query to finish? Now you can.<\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2016\/03\/LiveQueryStats.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"LiveQueryStats\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2016\/03\/LiveQueryStats_thumb.png\" alt=\"LiveQueryStats\" width=\"154\" height=\"64\" border=\"0\" \/><\/a><\/p>\n<p>Enable that and run a query, and you get an execution plan immediately, one with a few more details in it than we\u2019re used to.<\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2016\/03\/LiveQuery.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"LiveQuery\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2016\/03\/LiveQuery_thumb.png\" alt=\"LiveQuery\" width=\"484\" height=\"138\" border=\"0\" \/><\/a><\/p>\n<p>I\u2019m not sure what the times on the operators show, because a constant scan wouldn\u2019t take over 4 seconds, it generates a single number. I suspect it\u2019s the time between the first row request and the operator returning \u2018no more rows\u2019, but I\u2019d have to test more to be sure.<\/p>\n<p>The percentage done is probably based on the estimated row count, because on this plan all the operators went to 99% done instantly. The two numbers underneath the % done are the number of rows currently processed and below that the estimated number of rows.<\/p>\n<p>It\u2019s clear there\u2019s a severe row estimation problem here. The last nested loop join estimated 97 rows and, at the point the screenshot was taken, had processed 170500 rows. It\u2019s a pity that the estimated executions isn\u2019t shown as well, as it makes identifying row estimation errors slightly harder for operators that execute multiple times (eg the key lookup). <a title=\"https:\/\/www.sqlinthewild.co.za\/index.php\/2009\/09\/22\/estimated-rows-actual-rows-and-execution-count\/\" href=\"https:\/\/www.sqlinthewild.co.za\/index.php\/2009\/09\/22\/estimated-rows-actual-rows-and-execution-count\/\">https:\/\/www.sqlinthewild.co.za\/index.php\/2009\/09\/22\/estimated-rows-actual-rows-and-execution-count\/<\/a><\/p>\n<p>Identifying this kind of problem is, I think, one of the primary uses for Live Query Stats (other that using it to see how the QP works). The old example of \u2018it ran fast yesterday and slow today, why?\u2019 can be at least partially answered with Live Query Stats. Run the query with it turned on and see what plan is used and what row counts are flowing through them. Combine that with Query Store\u2019s history of what plans were used yesterday, and we have a very powerful way of identifying why something is running unusually slow.<\/p>\n<p>However is it something that should be used sparsely in production, as it does add some\u00a0 overhead.<\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2016\/03\/LiveStatsOn.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"LiveStatsOn\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2016\/03\/LiveStatsOn_thumb.png\" alt=\"LiveStatsOn\" width=\"516\" height=\"53\" border=\"0\" \/><\/a><\/p>\n<p>In most ways the Live Query Stats behaves like a normal execution plan, it can be saved and if saved part way through a query\u2019s execution, the resultant file is a normal .sqlplan file and has actual row counts of the point in execution where it was saved.<\/p>\n<p>It\u2019s not a ground breaking new feature, but it\u2019s a fun way to see how queries execute and it does have some uses in debugging sudden performance problems.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever wanted to look at a query\u2019s actual execution plan (execution plan with runtime information) without waiting for the query to finish? Now you can. Enable that and run a query, and you get an execution plan immediately, one with&#8230; <a class=\"read-more-button\" href=\"https:\/\/www.sqlinthewild.co.za\/index.php\/2016\/04\/12\/sql-server-2016-features-live-query-statistics\/\">(Read more)<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New blog post: SQL Server 2016 features: Live query statistics","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,16],"tags":[],"class_list":["post-1897","post","type-post","status-publish","format-standard","hentry","category-sql-server","category-syndication"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7h6n-uB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/posts\/1897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=1897"}],"version-history":[{"count":2,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/posts\/1897\/revisions"}],"predecessor-version":[{"id":1899,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/posts\/1897\/revisions\/1899"}],"wp:attachment":[{"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=1897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=1897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=1897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}