Warning: Constant WP_TEMP_DIR already defined in /var/www/html/blogs/joe/wp-config.php on line 93

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/joe/wp-config.php:93) in /var/www/html/blogs/joe/wp-includes/rest-api/class-wp-rest-server.php on line 1902
{"id":1159,"date":"2014-01-27T08:43:25","date_gmt":"2014-01-27T16:43:25","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/joe\/?p=1159"},"modified":"2014-01-27T08:47:34","modified_gmt":"2014-01-27T16:47:34","slug":"combining-multiple-contains-predicates-sql-server-2012","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/","title":{"rendered":"Combining multiple CONTAINS predicates in SQL Server 2012"},"content":{"rendered":"

The SQL Server 2005\u00a0 \u201cPerformance Tuning and Optimization (Full-Text Search)<\/a>\u201d books online topic has the following recommendation:<\/p>\n

\u201cCombine multiple CONTAINS predicates into one CONTAINS predicate. In SQL Server you can specify a list of columns in the CONTAINS query<\/em>.\u201d<\/p><\/blockquote>\n

While this shows up for the SQL Server 2005 topic, there is no such statement made for the 2008 and 2012 versions of the the books online topic.<\/p>\n

I was curious if this 2005-era recommendation still applied for more recent versions.\u00a0 To test this scenario I made the following changes to the AdventureWorks2012 sample database on version Microsoft SQL Server 2012 (SP1), 11.0.3000.0 Developer Edition:<\/p>\n

\r\nUSE [AdventureWorks2012];\r\nGO\r\nALTER TABLE [Production].[ProductDescription]\r\nADD [Description2] NVARCHAR(400) NOT NULL DEFAULT '';\r\nGO\r\n\r\n-- Populating the new description column\r\nUPDATE [Production].[ProductDescription]\r\nSET [Description2] = [Description];\r\nGO\r\n\r\nCREATE FULLTEXT INDEX ON [Production].[ProductDescription] KEY INDEX [PK_ProductDescription_ProductDescriptionID] ON ([AW2008FullTextCatalog])\r\nWITH (CHANGE_TRACKING AUTO);\r\nGO\r\n\r\nALTER FULLTEXT INDEX ON [Production].[ProductDescription] ADD ([Description]);\r\nALTER FULLTEXT INDEX ON [Production].[ProductDescription] ADD ([Description2]);\r\nGO\r\n<\/pre>\n

Now for an initial test, I executed the following single<\/em> CONTAINS predicate query:<\/p>\n

\r\nSET STATISTICS IO ON;\r\n\r\nSELECT\u00a0 [ProductDescriptionID] ,\r\n[Description] ,\r\n[rowguid] ,\r\n[ModifiedDate]\r\nFROM [Production].[ProductDescription]\r\nWHERE CONTAINS([Description], 'bike');\r\n\r\nSET STATISTICS IO OFF;\r\n<\/pre>\n

The query execution plan tree (from SQL Sentry Plan Explorer) was as follows:<\/p>\n

\"image\"<\/a><\/p>\n

And the STATISTICS IO output was as follows:<\/p>\n

Table ‘ProductDescription’. Scan count 0, logical reads 28<\/span>, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p><\/blockquote>\n

Now for a multi-CONTAINS predicate, I executed the following example:<\/p>\n

\r\nSET STATISTICS IO ON;\r\n\r\nSELECT\u00a0 [ProductDescriptionID] ,\r\n[Description] ,\r\n[rowguid] ,\r\n[ModifiedDate]\r\nFROM [Production].[ProductDescription]\r\nWHERE CONTAINS([Description], 'bike') OR\r\nCONTAINS([Description2], 'bike');\r\n\r\nSET STATISTICS IO OFF;\r\n<\/pre>\n

The query execution plan tree (from SQL Sentry Plan Explorer) was as follows:<\/p>\n

\"image\"<\/a><\/p>\n

The operators remained the same, but we have a change in estimated subtree cost and also a doubling up of cardinality estimates.<\/p>\n

As for the STATISTICS IO output, it was as follows:<\/p>\n

Table ‘ProductDescription’. Scan count 0, logical reads 34<\/span>, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p><\/blockquote>\n

Logical reads were 34 versus the original 28.<\/p>\n

For the last example, I combined the two CONTAINS predicates as follows:<\/p>\n

\r\nSET STATISTICS IO ON;\r\n\r\nSELECT\u00a0 [ProductDescriptionID] ,\r\n[Description] ,\r\n[rowguid] ,\r\n[ModifiedDate]\r\nFROM [Production].[ProductDescription]\r\nWHERE CONTAINS(([Description], [Description2]), 'bike');\r\n\r\nSET STATISTICS IO OFF;\r\n<\/pre>\n

I found that with the combined CONTAINS, the plan shape for this example remained the same as the multiple-CONTAINS version. Operator costs and estimates also remained the same.<\/p>\n

For SQL Server 2005, if you had multiple CONTAINS predicates referencing columns from the same table, your execution plan would show separate remote scan operators for each reference instead of them being combined natively into a single operator.\u00a0 This behavior seems to have been addressed in recent versions, but if you have seen a variation of this issue given other conditions please share in the comments.\u00a0 Thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"

The SQL Server 2005\u00a0 \u201cPerformance Tuning and Optimization (Full-Text Search)\u201d books online topic has the following recommendation: \u201cCombine multiple CONTAINS predicates into one CONTAINS predicate. In SQL Server you can specify a list of columns in the CONTAINS query.\u201d While this shows up for the SQL Server 2005 topic, there is no such statement made […]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,28],"tags":[],"class_list":["post-1159","post","type-post","status-publish","format-standard","hentry","category-full-text-search","category-performance"],"yoast_head":"\nCombining multiple CONTAINS predicates in SQL Server 2012 - Joe Sack<\/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\/joe\/combining-multiple-contains-predicates-sql-server-2012\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Combining multiple CONTAINS predicates in SQL Server 2012 - Joe Sack\" \/>\n<meta property=\"og:description\" content=\"The SQL Server 2005\u00a0 \u201cPerformance Tuning and Optimization (Full-Text Search)\u201d books online topic has the following recommendation: \u201cCombine multiple CONTAINS predicates into one CONTAINS predicate. In SQL Server you can specify a list of columns in the CONTAINS query.\u201d While this shows up for the SQL Server 2005 topic, there is no such statement made […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/\" \/>\n<meta property=\"og:site_name\" content=\"Joe Sack\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-27T16:43:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-01-27T16:47:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-content\/uploads\/2014\/01\/image_thumb.png\" \/>\n<meta name=\"author\" content=\"Joseph Sack\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joseph Sack\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/\",\"name\":\"Combining multiple CONTAINS predicates in SQL Server 2012 - Joe Sack\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#website\"},\"datePublished\":\"2014-01-27T16:43:25+00:00\",\"dateModified\":\"2014-01-27T16:47:34+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/533eb0113a15fb5a6e8067a49e4ae648\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Full-Text Search\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/category\/full-text-search\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Combining multiple CONTAINS predicates in SQL Server 2012\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/\",\"name\":\"Joe Sack\",\"description\":\"SQL Server Performance Tuning, High Availability and Disaster Recovery Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/533eb0113a15fb5a6e8067a49e4ae648\",\"name\":\"Joseph Sack\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a4b39a7719a6bfff1add3ec00527810734579ee114d6d983e8e68f937b77be96?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a4b39a7719a6bfff1add3ec00527810734579ee114d6d983e8e68f937b77be96?s=96&d=mm&r=g\",\"caption\":\"Joseph Sack\"},\"description\":\"Joe Sack is a Principal Consultant with SQLskills. He has worked as a SQL Server professional since 1997 and has supported and developed for SQL Server environments in financial services, IT consulting, manufacturing, retail and the real estate industry. Prior to joining SQLskills he worked at Microsoft as a Premier Field Engineer supporting very large enterprise customer environments. He was responsible for providing deep SQL Server advisory services, training, troubleshooting and ongoing solutions guidance. His areas of expertise include performance tuning, scalability, T-SQL development and high-availability. In 2006 Joe earned the \u201cMicrosoft Certified Master: SQL Server 2005\u201d certification and in 2008 he earned the \u201cMicrosoft Certified Master: SQL Server 2008\u201d certification. In 2009 he took over responsibility for the entire SQL Server Microsoft Certified Master program and held that post until 2011. He was given the SQL Server MVP award in 2013.\",\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/joe\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/josephsack\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/joe\/author\/joe\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Combining multiple CONTAINS predicates in SQL Server 2012 - Joe Sack","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\/joe\/combining-multiple-contains-predicates-sql-server-2012\/","og_locale":"en_US","og_type":"article","og_title":"Combining multiple CONTAINS predicates in SQL Server 2012 - Joe Sack","og_description":"The SQL Server 2005\u00a0 \u201cPerformance Tuning and Optimization (Full-Text Search)\u201d books online topic has the following recommendation: \u201cCombine multiple CONTAINS predicates into one CONTAINS predicate. In SQL Server you can specify a list of columns in the CONTAINS query.\u201d While this shows up for the SQL Server 2005 topic, there is no such statement made […]","og_url":"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/","og_site_name":"Joe Sack","article_published_time":"2014-01-27T16:43:25+00:00","article_modified_time":"2014-01-27T16:47:34+00:00","og_image":[{"url":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-content\/uploads\/2014\/01\/image_thumb.png"}],"author":"Joseph Sack","twitter_misc":{"Written by":"Joseph Sack","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/","url":"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/","name":"Combining multiple CONTAINS predicates in SQL Server 2012 - Joe Sack","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#website"},"datePublished":"2014-01-27T16:43:25+00:00","dateModified":"2014-01-27T16:47:34+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/533eb0113a15fb5a6e8067a49e4ae648"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/combining-multiple-contains-predicates-sql-server-2012\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/joe\/"},{"@type":"ListItem","position":2,"name":"Full-Text Search","item":"https:\/\/www.sqlskills.com\/blogs\/joe\/category\/full-text-search\/"},{"@type":"ListItem","position":3,"name":"Combining multiple CONTAINS predicates in SQL Server 2012"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/joe\/","name":"Joe Sack","description":"SQL Server Performance Tuning, High Availability and Disaster Recovery Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/joe\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/533eb0113a15fb5a6e8067a49e4ae648","name":"Joseph Sack","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/joe\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a4b39a7719a6bfff1add3ec00527810734579ee114d6d983e8e68f937b77be96?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a4b39a7719a6bfff1add3ec00527810734579ee114d6d983e8e68f937b77be96?s=96&d=mm&r=g","caption":"Joseph Sack"},"description":"Joe Sack is a Principal Consultant with SQLskills. He has worked as a SQL Server professional since 1997 and has supported and developed for SQL Server environments in financial services, IT consulting, manufacturing, retail and the real estate industry. Prior to joining SQLskills he worked at Microsoft as a Premier Field Engineer supporting very large enterprise customer environments. He was responsible for providing deep SQL Server advisory services, training, troubleshooting and ongoing solutions guidance. His areas of expertise include performance tuning, scalability, T-SQL development and high-availability. In 2006 Joe earned the \u201cMicrosoft Certified Master: SQL Server 2005\u201d certification and in 2008 he earned the \u201cMicrosoft Certified Master: SQL Server 2008\u201d certification. In 2009 he took over responsibility for the entire SQL Server Microsoft Certified Master program and held that post until 2011. He was given the SQL Server MVP award in 2013.","sameAs":["http:\/\/3.209.169.194\/blogs\/joe","https:\/\/twitter.com\/https:\/\/twitter.com\/josephsack"],"url":"https:\/\/www.sqlskills.com\/blogs\/joe\/author\/joe\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/posts\/1159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/comments?post=1159"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/posts\/1159\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/media?parent=1159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/categories?post=1159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/joe\/wp-json\/wp\/v2\/tags?post=1159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}