{"id":287,"date":"2016-12-29T07:42:07","date_gmt":"2016-12-29T13:42:07","guid":{"rendered":"http:\/\/www.sqlnuggets.com\/?p=287"},"modified":"2017-03-31T15:14:50","modified_gmt":"2017-03-31T20:14:50","slug":"performance-problem-when-using-or-in-a-join","status":"publish","type":"post","link":"https:\/\/sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/","title":{"rendered":"Performance Problem When Using OR In A JOIN"},"content":{"rendered":"<p>I recently had a developer come to me with a poorly performing query. \u00a0As you will see below, it&#8217;s a fairly straight forward query, consisting of one table with one join and a simple WHERE clause. \u00a0The problem was that this query was taking over 11 minutes to run, and only returned about 40,000 results. \u00a0Let&#8217;s take a look at the query.<\/p>\n<p><em>Note: The queries and execution plans below have been run through the &#8220;Anonymize&#8221; feature of <a href=\"https:\/\/www.sentryone.com\/plan-explorer\" target=\"_blank\">Sentry One Plan Explorer<\/a>, and then tweaked a little by me for better readability. \u00a0I don&#8217;t really name my tables things like &#8220;object2&#8221;.<\/em><\/p>\n<pre class=\"lang:tsql decode:true\">SELECT DISTINCT a.Column1, a.Column2, b.Column3, a.Column4, b.Column5\r\nFROM Object2 a\r\nINNER JOIN Object3 b ON ( (a.Column1 IS NOT NULL AND a.Column1 = b.Column1) \r\n                        OR (a.Column2 IS NOT NULL AND b.Column2 = a.Column2) )\r\nWHERE (b.Column6 = @variable1)<\/pre>\n<p>A quick look at the execution plan in Plan Explorer shows us where the problem is.<\/p>\n<p><a href=\"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-302 alignnone\" src=\"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png\" alt=\"Bad Execution Plan\" width=\"564\" height=\"156\" srcset=\"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png 564w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28-300x83.png 300w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28-250x69.png 250w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28-150x41.png 150w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/a><\/p>\n<p>Wait, what?!? \u00a0SQL Server is taking 628,000 rows and\u00a0putting them into a spool of over 7 BILLION rows! \u00a0And when I hovered over that data stream it showed that we had an actual data size of 112GB! \u00a0Houston, I think we found the problem&#8230;something in the JOIN between our two tables is causing SQL Server to have to do a ton of work. \u00a0So, let&#8217;s take another look at that query.<\/p>\n<pre class=\"lang:tsql decode:true\">SELECT DISTINCT a.Column1, a.Column2, b.Column3, a.Column4, b.Column5\r\nFROM Object2 a\r\nINNER JOIN Object3 b ON ( (a.Column1 IS NOT NULL AND a.Column1 = b.Column1) \r\n                        OR (a.Column2 IS NOT NULL AND b.Column2 = a.Column2) )\r\nWHERE (b.Column6 = @variable1)<\/pre>\n<p>Looking at our JOIN, we can see there is an OR statement in the join condition. \u00a0This <a href=\"https:\/\/en.wikipedia.org\/wiki\/Code_smell\" target=\"_blank\">smells funny<\/a>. \u00a0That condition is basically telling SQL Server to do try to do two separate things, something along the lines of:<\/p>\n<pre class=\"lang:tsql decode:true \">INNER JOIN Object3 b ON a.Column1 IS NOT NULL AND a.Column1 = b.Column1\r\nOR\r\nINNER JOIN Object3 b ON a.Column2 IS NOT NULL AND b.Column2 = a.Column2<\/pre>\n<p>This is confusing to SQL Server. \u00a0What could be looked at as 2 separate pieces of logic is being crammed into one, which causes it to create a crazy 7 BILLION row, 112GB\u00a0table spool.<\/p>\n<p>The fix for this would be to separate that JOIN into two joins, and since this was a small query I decided to do that with a UNION. \u00a0Here is my updated query:<\/p>\n<pre class=\"lang:tsql decode:true \">SELECT a.Column1, a.Column2, b.Column3, a.Column4, b.Column5\r\nFROM Object2 a\r\nINNER JOIN Object3 b ON a.Column1 IS NOT NULL AND a.Column1 = b.Column1\r\nWHERE (b.Column6 = @variable1)\r\nUNION\r\nSELECT a.Column1, a.Column2, b.Column3, a.Column4, b.Column5\r\nFROM Object2 a\r\nINNER JOIN Object3 b ON a.Column2 IS NOT NULL AND b.Column2 = a.Column2\r\nWHERE (b.Column6 = @variable1)<\/pre>\n<p>Both queries in the UNION are the same, except for the JOIN statements, which are just the two parts of the original JOIN\u00a0now being run separately. \u00a0As an added bonus, since I used a UNION we no longer need DISTINCT in the query. (I hate DISTINCT!) \u00a0Now when we check the execution plan, we get the following:<\/p>\n<p><a href=\"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot2-2016-12-28-at-11.41.05-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-303\" src=\"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot2-2016-12-28-at-11.41.05-AM.png\" alt=\"Better Execution Plan\" width=\"481\" height=\"287\" srcset=\"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot2-2016-12-28-at-11.41.05-AM.png 481w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot2-2016-12-28-at-11.41.05-AM-300x179.png 300w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot2-2016-12-28-at-11.41.05-AM-250x150.png 250w, https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot2-2016-12-28-at-11.41.05-AM-150x90.png 150w\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" \/><\/a><\/p>\n<p>MUCH BETTER! \u00a0We no longer have that crazy table spool, and our <strong>query execution time dropped from 11 minutes to 2oo milliseconds<\/strong>. \u00a0I would call that a win! \u00a0Even though there are still some indexing improvements that could be made to the query, and a couple of warnings to look into, we now get a much simpler, more efficient execution plan by removing the OR from the\u00a0JOIN condition.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently had a developer come to me with a poorly performing query. \u00a0As you will see below, it&#8217;s a fairly straight forward query, consisting of one table with one &#8230;<\/p>\n","protected":false},"author":2,"featured_media":302,"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":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[41,40,15],"class_list":["post-287","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-t-sql","tag-bad-t-sql","tag-execution-plans","tag-performance"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Performance Problem When Using OR In A JOIN - SQL Nuggets<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Performance Problem When Using OR In A JOIN - SQL Nuggets\" \/>\n<meta property=\"og:description\" content=\"I recently had a developer come to me with a poorly performing query. \u00a0As you will see below, it&#8217;s a fairly straight forward query, consisting of one table with one ...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Nuggets\" \/>\n<meta property=\"article:published_time\" content=\"2016-12-29T13:42:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-03-31T20:14:50+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png\" \/>\n\t<meta property=\"og:image:width\" content=\"564\" \/>\n\t<meta property=\"og:image:height\" content=\"156\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Eric Cobb\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cfgears\" \/>\n<meta name=\"twitter:site\" content=\"@sqlnugg\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eric Cobb\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/#article\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/\"},\"author\":{\"name\":\"Eric Cobb\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#\\\/schema\\\/person\\\/210536254addbc1b9d2d95dc1448b38a\"},\"headline\":\"Performance Problem When Using OR In A JOIN\",\"datePublished\":\"2016-12-29T13:42:07+00:00\",\"dateModified\":\"2017-03-31T20:14:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/\"},\"wordCount\":425,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#organization\"},\"image\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/Screen-Shot1-2016-12-28.png\",\"keywords\":[\"Bad T-SQL\",\"Execution Plans\",\"Performance\"],\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/\",\"url\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/\",\"name\":\"Performance Problem When Using OR In A JOIN - SQL Nuggets\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/Screen-Shot1-2016-12-28.png\",\"datePublished\":\"2016-12-29T13:42:07+00:00\",\"dateModified\":\"2017-03-31T20:14:50+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/#primaryimage\",\"url\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/Screen-Shot1-2016-12-28.png\",\"contentUrl\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/Screen-Shot1-2016-12-28.png\",\"width\":564,\"height\":156},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/performance-problem-when-using-or-in-a-join\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/www.sqlnuggets.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Performance Problem When Using OR In A JOIN\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#website\",\"url\":\"http:\\\/\\\/www.sqlnuggets.com\\\/\",\"name\":\"SQL Nuggets\",\"description\":\"Nuggets Of SQL Server Knowledge\",\"publisher\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/www.sqlnuggets.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#organization\",\"name\":\"SQL Nuggets\",\"url\":\"http:\\\/\\\/www.sqlnuggets.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/website-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/sqlnuggets.com\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/website-logo.jpg\",\"width\":320,\"height\":54,\"caption\":\"SQL Nuggets\"},\"image\":{\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/sqlnugg\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/ericcobb\\\/\"]},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/www.sqlnuggets.com\\\/#\\\/schema\\\/person\\\/210536254addbc1b9d2d95dc1448b38a\",\"name\":\"Eric Cobb\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg\",\"caption\":\"Eric Cobb\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/cfgears\"],\"url\":\"https:\\\/\\\/sqlnuggets.com\\\/author\\\/eric-cobb\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Performance Problem When Using OR In A JOIN - SQL Nuggets","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":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/","og_locale":"en_US","og_type":"article","og_title":"Performance Problem When Using OR In A JOIN - SQL Nuggets","og_description":"I recently had a developer come to me with a poorly performing query. \u00a0As you will see below, it&#8217;s a fairly straight forward query, consisting of one table with one ...","og_url":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/","og_site_name":"SQL Nuggets","article_published_time":"2016-12-29T13:42:07+00:00","article_modified_time":"2017-03-31T20:14:50+00:00","og_image":[{"width":564,"height":156,"url":"http:\/\/www.sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png","type":"image\/png"}],"author":"Eric Cobb","twitter_card":"summary_large_image","twitter_creator":"@cfgears","twitter_site":"@sqlnugg","twitter_misc":{"Written by":"Eric Cobb","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/#article","isPartOf":{"@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/"},"author":{"name":"Eric Cobb","@id":"http:\/\/www.sqlnuggets.com\/#\/schema\/person\/210536254addbc1b9d2d95dc1448b38a"},"headline":"Performance Problem When Using OR In A JOIN","datePublished":"2016-12-29T13:42:07+00:00","dateModified":"2017-03-31T20:14:50+00:00","mainEntityOfPage":{"@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/"},"wordCount":425,"commentCount":0,"publisher":{"@id":"http:\/\/www.sqlnuggets.com\/#organization"},"image":{"@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png","keywords":["Bad T-SQL","Execution Plans","Performance"],"articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/","url":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/","name":"Performance Problem When Using OR In A JOIN - SQL Nuggets","isPartOf":{"@id":"http:\/\/www.sqlnuggets.com\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/#primaryimage"},"image":{"@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png","datePublished":"2016-12-29T13:42:07+00:00","dateModified":"2017-03-31T20:14:50+00:00","breadcrumb":{"@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/#primaryimage","url":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png","contentUrl":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png","width":564,"height":156},{"@type":"BreadcrumbList","@id":"http:\/\/www.sqlnuggets.com\/performance-problem-when-using-or-in-a-join\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.sqlnuggets.com\/"},{"@type":"ListItem","position":2,"name":"Performance Problem When Using OR In A JOIN"}]},{"@type":"WebSite","@id":"http:\/\/www.sqlnuggets.com\/#website","url":"http:\/\/www.sqlnuggets.com\/","name":"SQL Nuggets","description":"Nuggets Of SQL Server Knowledge","publisher":{"@id":"http:\/\/www.sqlnuggets.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.sqlnuggets.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/www.sqlnuggets.com\/#organization","name":"SQL Nuggets","url":"http:\/\/www.sqlnuggets.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.sqlnuggets.com\/#\/schema\/logo\/image\/","url":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2023\/11\/website-logo.jpg","contentUrl":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2023\/11\/website-logo.jpg","width":320,"height":54,"caption":"SQL Nuggets"},"image":{"@id":"http:\/\/www.sqlnuggets.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/sqlnugg","https:\/\/www.linkedin.com\/in\/ericcobb\/"]},{"@type":"Person","@id":"http:\/\/www.sqlnuggets.com\/#\/schema\/person\/210536254addbc1b9d2d95dc1448b38a","name":"Eric Cobb","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3ca1fc0c7054a668e048f09d412cd4ebf89833c4630fbbfccca78a0678a6bdc2?s=96&d=mm&r=pg","caption":"Eric Cobb"},"sameAs":["https:\/\/x.com\/cfgears"],"url":"https:\/\/sqlnuggets.com\/author\/eric-cobb\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/sqlnuggets.com\/wp-content\/uploads\/2016\/12\/Screen-Shot1-2016-12-28.png","jetpack_shortlink":"https:\/\/wp.me\/pdyDvE-4D","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":449,"url":"https:\/\/sqlnuggets.com\/sql-scripts-find-index-fragmentation\/","url_meta":{"origin":287,"position":0},"title":"SQL Scripts: How To Find Index Fragmentation","author":"Eric Cobb","date":"June 22, 2017","format":false,"excerpt":"This is the first post in\u00a0an ongoing SQL Scripts series, in which I list useful queries that I use in my day to day database administration. What Is Index Fragmentation? Over time, as records are inserted, updated, and deleted, your tables and indexes become fragmented. \u00a0This fragmentation can lead to\u2026","rel":"","context":"In &quot;Indexes&quot;","block_context":{"text":"Indexes","link":"https:\/\/sqlnuggets.com\/category\/indexes\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":813,"url":"https:\/\/sqlnuggets.com\/sql-scripts-how-to-find-missing-indexes\/","url_meta":{"origin":287,"position":1},"title":"SQL Scripts: How To Find Missing Indexes","author":"Eric Cobb","date":"June 5, 2018","format":false,"excerpt":"One of the really cool things that SQL Server does is keep up with index statistics behind the scenes.\u00a0 It knows how an index has been used, how often it is used, or if it is even being used at all.\u00a0 But SQL Server doesn't just monitor the indexes that\u2026","rel":"","context":"In &quot;Indexes&quot;","block_context":{"text":"Indexes","link":"https:\/\/sqlnuggets.com\/category\/indexes\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/06\/lost-cat-tree-sign-fun-159868.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/06\/lost-cat-tree-sign-fun-159868.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/06\/lost-cat-tree-sign-fun-159868.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/06\/lost-cat-tree-sign-fun-159868.jpeg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2018\/06\/lost-cat-tree-sign-fun-159868.jpeg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1078,"url":"https:\/\/sqlnuggets.com\/sql-scripts-find-queries-that-have-missing-index-requests\/","url_meta":{"origin":287,"position":2},"title":"SQL Scripts: Find Queries That Have Missing Index Requests","author":"Eric Cobb","date":"August 27, 2019","format":false,"excerpt":"In a previous article, I went over how SQL Server will recommend an index that it believes will help a query run faster, and I showed how to find missing index recommendations. Now, as I said in that article, you do not want to just blindly add whatever index SQL\u2026","rel":"","context":"In &quot;SQL Scripts&quot;","block_context":{"text":"SQL Scripts","link":"https:\/\/sqlnuggets.com\/category\/sql-scripts\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/08\/question-mark-1872634_1280.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/08\/question-mark-1872634_1280.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/08\/question-mark-1872634_1280.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/08\/question-mark-1872634_1280.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/08\/question-mark-1872634_1280.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1255,"url":"https:\/\/sqlnuggets.com\/sql-scripts-list-databases-a-login-can-access\/","url_meta":{"origin":287,"position":3},"title":"SQL Scripts: List Databases A Login Can Access","author":"Eric Cobb","date":"January 7, 2020","format":false,"excerpt":"When you are managing your SQL Server database permissions through Active Directory Groups (which you should be!), it can sometimes be difficult to know just which databases a user actually has access to. Sure, you could look up each AD Group that user is a member of and then check\u2026","rel":"","context":"In &quot;Security&quot;","block_context":{"text":"Security","link":"https:\/\/sqlnuggets.com\/category\/security\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/12\/checklist-2470549_1280.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/12\/checklist-2470549_1280.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/12\/checklist-2470549_1280.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/12\/checklist-2470549_1280.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2019\/12\/checklist-2470549_1280.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":790,"url":"https:\/\/sqlnuggets.com\/sql-scripts-how-to-find-filtered-indexes\/","url_meta":{"origin":287,"position":4},"title":"SQL Scripts: How To Find Filtered Indexes","author":"Eric Cobb","date":"May 9, 2018","format":false,"excerpt":"Filtered indexes are one of those neat little SQL Server features that a lot of people don't seem to know about, or if they do they don't use them very much.\u00a0 While I agree that putting a filter on every index probably isn't a good idea, there are cases where\u2026","rel":"","context":"In &quot;Indexes&quot;","block_context":{"text":"Indexes","link":"https:\/\/sqlnuggets.com\/category\/indexes\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/sqlnuggets.com\/wp-content\/uploads\/2017\/06\/board-electronics-computer-data-processing-50711-e1498160567831.jpeg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":322,"url":"https:\/\/sqlnuggets.com\/getting-alerts-from-sql-sentry-when-you-dont-have-email\/","url_meta":{"origin":287,"position":5},"title":"Getting Alerts From SQL Sentry When You Don&#8217;t Have Email","author":"Eric Cobb","date":"February 7, 2017","format":false,"excerpt":"I use SentryOne's SQL Sentry for my SQL Server monitoring, and it does an excellent job. \u00a0However I recently had a situation where I was unable to get email alerts from SQL Sentry. \u00a0This was by no fault of SQL Sentry, our email sever was down so I couldn't get\u2026","rel":"","context":"In &quot;Monitoring&quot;","block_context":{"text":"Monitoring","link":"https:\/\/sqlnuggets.com\/category\/monitoring\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/comments?post=287"}],"version-history":[{"count":0,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/media\/302"}],"wp:attachment":[{"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlnuggets.com\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}