{"id":2340,"date":"2019-03-12T16:00:52","date_gmt":"2019-03-12T14:00:52","guid":{"rendered":"https:\/\/www.sqlinthewild.co.za\/?p=2340"},"modified":"2019-02-23T22:56:36","modified_gmt":"2019-02-23T20:56:36","slug":"comparing-plans-in-query-store","status":"publish","type":"post","link":"https:\/\/www.sqlinthewild.co.za\/index.php\/2019\/03\/12\/comparing-plans-in-query-store\/","title":{"rendered":"Comparing plans in Query Store"},"content":{"rendered":"<p>One feature that was added in the 2016 version of SSMS that hasn\u2019t received a lot of attention, is the ability to compare execution plans.<\/p>\n<p>There\u2019s two ways of doing this, from Query Store and from saved files.<\/p>\n<p>Let\u2019s start with Query Store, and I\u2019m going to use a demo database that I\u2019ve been working on for a few months \u2013 Interstellar Transport (IST). I\u2019ve got a stored procedure in there that has a terrible parameter sniffing problem (intentionally). I\u2019m going to run it a few times with one parameter value, then run it a few more times with another parameter value, remove the plan from cache and repeat the executions in the reverse order.<\/p>\n<p>With that done, the query should show up in the \u2018Queries with High Variance\u2019 report (SQL 2017)<\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image_thumb.png\" alt=\"image\" width=\"484\" height=\"150\" border=\"0\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image_thumb-1.png\" alt=\"image\" width=\"484\" height=\"205\" border=\"0\" \/><\/a><\/p>\n<p>The query has the two expected plans, and they are quite different from each other.<\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/Plan1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"Plan1\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/Plan1_thumb.png\" alt=\"Plan1\" width=\"484\" height=\"109\" border=\"0\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/Plan2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"Plan2\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/Plan2_thumb.png\" alt=\"Plan2\" width=\"484\" height=\"105\" border=\"0\" \/><\/a><\/p>\n<p>I can click on the points on the graph individually to see the plans, but comparing the plans in that way is difficult and requires that I make notes somewhere else. What I can do instead is select two different points on the graph and chose the \u2018compare plans\u2019 option.<\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image_thumb-2.png\" alt=\"image\" width=\"139\" height=\"204\" border=\"0\" \/><\/a><\/p>\n<p>This brings up a window where the two plans are displayed one above the other, and areas in the plan which are similar are highlighted.<\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image_thumb-3.png\" alt=\"image\" width=\"484\" height=\"217\" border=\"0\" \/><\/a><\/p>\n<p>Select an operator and pull up the properties, and the properties of the operator from both plans are shown, with the differences highlighted.<\/p>\n<p><a href=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"image\" src=\"https:\/\/www.sqlinthewild.co.za\/wp-content\/uploads\/2018\/12\/image_thumb-4.png\" alt=\"image\" width=\"484\" height=\"248\" border=\"0\" \/><\/a><\/p>\n<p>This isn\u2019t the only way to compare query plans. The next post will show how it can be done without using Query Store at all.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One feature that was added in the 2016 version of SSMS that hasn\u2019t received a lot of attention, is the ability to compare execution plans. There\u2019s two ways of doing this, from Query Store and from saved files. Let\u2019s start&#8230; <a class=\"read-more-button\" href=\"https:\/\/www.sqlinthewild.co.za\/index.php\/2019\/03\/12\/comparing-plans-in-query-store\/\">(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: Comparing plans in Query Store","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":[23,15],"tags":[],"class_list":["post-2340","post","type-post","status-publish","format-standard","hentry","category-execution-plans","category-sql-server"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7h6n-BK","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/posts\/2340","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=2340"}],"version-history":[{"count":2,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/posts\/2340\/revisions"}],"predecessor-version":[{"id":2389,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/posts\/2340\/revisions\/2389"}],"wp:attachment":[{"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=2340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=2340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlinthewild.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=2340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}