{"id":7342,"date":"2017-02-08T14:43:53","date_gmt":"2017-02-08T16:43:53","guid":{"rendered":"http:\/\/www.fabriciolima.net\/?p=7342"},"modified":"2017-02-08T15:12:29","modified_gmt":"2017-02-08T17:12:29","slug":"improve-the-query-performance-with-like-string-changing-only-the-collation","status":"publish","type":"post","link":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/","title":{"rendered":"Improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8221; changing only the collation"},"content":{"rendered":"<p>Hi Folks,<\/p>\n<p>In this blog post, I will give you a very useful tip to improve the performance of a query that uses <em>&#8221; like &#8216;%String%&#8217; &#8220;<\/em>.<\/p>\n<p>How often do you have to use a query like this?<\/p>\n<pre class=\"lang:tsql decode:true \">Select Columns,...\r\nfrom Table\r\nwhere Name like '%String%'<\/pre>\n<p>Reading the great book <a href=\"https:\/\/www.amazon.com\/Microsoft-Server-Internals-Developer-Reference\/dp\/0735658560\" target=\"_blank\"><em>SQL Server 2012 Internals<\/em><\/a>, on page 230, we have:<\/p>\n<p><em>&#8220;Another case where the collation can make a huge difference is when SQL Server has to look at almost all characters in the strings. For instance, look at the following:<\/em><\/p>\n<p><em>SELECT COUNT(*) FROM tbl WHERE longcol like &#8216;%abc%&#8217;<\/em><\/p>\n<p><em>This might execute 10 time faster or more with a binary collation than a nonbinary Windows colation. Also, with varchar data, this executes up to seven or eight times faster with a SQL collation than with a Windows collation. If you have a varchar column, you can speed this up by forcing the collation as follows:<\/em><\/p>\n<p><em>SELECT COUNT(*) from tbl<\/em><br \/>\n<em> WHERE longcol COLLATE SQL_Latin1_Genneral_CP_CI_AS LIKE &#8216;%abc%&#8217; &#8220;<\/em><\/p>\n<p>That&#8217;s a very important information. Let&#8217;s do some tests and see what&#8217;s happen.<\/p>\n<p>I will create a table with a varchar column and populate it with a lot of data.<\/p>\n<pre class=\"lang:tsql decode:true \">CREATE table dbo.Test_Collation_SQL (\r\nId_Table int identity(1,1) PRIMARY KEY,\r\nDt_Log datetime,\r\nDs_Name varchar(50)\r\n)\r\n\r\n-- Generate a lot of data. Can take a while...\r\nINSERT INTO dbo.Test_Collation_SQL\r\nselect getdate(), REPLICATE('A',50)\r\nGO 10\r\n\r\nINSERT INTO dbo.Test_Collation_SQL(Dt_Log,Ds_Name)\r\nSELECT Dt_Log,Ds_Name\r\nFROM Test_Collation_SQL\r\nGO 22<\/pre>\n<p>Now, I will insert two rows with my name to search later:<\/p>\n<pre class=\"lang:tsql decode:true \">insert into dbo.Teste_Collation_SQL\r\nselect getdate(), 'Fabricio Lima 1'\r\n\r\ninsert into dbo.Teste_Collation_SQL\r\nselect getdate(), '- Fabricio Lima 2'<\/pre>\n<p>Then I will create a index to try do help my query, just like everyone do:<\/p>\n<pre class=\"lang:tsql decode:true \">CREATE NONCLUSTERED INDEX SK01_Test_Collation_SQL ON Test_Collation_SQL(Ds_Name)  WITH(FILLFACTOR=90)<\/pre>\n<p>The size of the table is:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7368 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTable.png\" alt=\"\" width=\"465\" height=\"134\" srcset=\"https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTable.png 514w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTable-300x86.png 300w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTable-410x118.png 410w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTable-100x29.png 100w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTable-275x79.png 275w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTable-20x6.png 20w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/p>\n<p>Now I will enable this option to compare the results<\/p>\n<pre class=\"lang:tsql decode:true \">SET STATISTICS IO ON\r\nSET STATISTICS TIME ON<\/pre>\n<p>I also enable the Actual Execution Plan to see what&#8217;s SQL doing: CTRL+M<\/p>\n<p>My instance has this Windows Collation: Latin1_General_CI_AI<\/p>\n<p>My Database and Column also has the same Collation: Latin1_General_CI_AI<\/p>\n<h6><strong>Test 1: Using my default Windows Collation: Latin1_General_CI_AI <\/strong><\/h6>\n<pre class=\"lang:tsql decode:true \">SELECT COUNT(*)\r\nFROM Test_Collation_SQL\r\nWHERE Ds_Name LIKE '%Fabricio%'<\/pre>\n<p>The results \u00e9 <strong>two rows<\/strong> and this query took<strong> 45 secods<\/strong> to finish. It&#8217;s not cache problems because I&#8217;ve executed it three times.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-7371 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore.png\" alt=\"\" width=\"713\" height=\"293\" srcset=\"https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore.png 832w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore-300x123.png 300w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore-768x316.png 768w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore-700x288.png 700w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore-410x169.png 410w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore-100x41.png 100w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore-275x113.png 275w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeBefore-20x8.png 20w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/p>\n<p><strong>Reads<\/strong><br \/>\nTable &#8216;Test_Collation_SQL&#8217;. Scan count 9, <strong>logical reads<\/strong> <strong>373572<\/strong><\/p>\n<p><strong>CPU Time<\/strong><br \/>\nSQL Server Execution Times:<br \/>\n<strong>CPU time =<\/strong> <strong>348922 ms<\/strong>,\u00a0 elapsed time = 45679 ms.<\/p>\n<h6><\/h6>\n<h6><strong> Teste 2: Forcing a SQL Server collation and searching the same thing<\/strong><\/h6>\n<pre class=\"lang:tsql decode:true \">SELECT COUNT(*)\r\nFROM TreinamentoDBA..Teste_Collation_SQL\r\nWHERE Descri\u00e7\u00e3o COLLATE SQL_Latin1_General_CP1_CI_AI LIKE '%Fabricio%'<\/pre>\n<p>The results is <strong>two rows<\/strong> and this query took only <strong>5 secods<\/strong>!!! <strong>Amazing!!! Unbelievable!!! It&#8217;s like magic!!<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7370 aligncenter\" src=\"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter.png\" alt=\"\" width=\"778\" height=\"257\" srcset=\"https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter.png 1014w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter-300x99.png 300w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter-768x254.png 768w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter-700x231.png 700w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter-410x135.png 410w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter-100x33.png 100w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter-275x91.png 275w, https:\/\/fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTimeAfter-20x7.png 20w\" sizes=\"auto, (max-width: 778px) 100vw, 778px\" \/><\/p>\n<p><strong>Reads<\/strong><br \/>\nTable &#8216;Test_Collation_SQL&#8217;. Scan count 9, <strong>logical reads 374622<\/strong><\/p>\n<p><strong>CPU Time<\/strong><br \/>\nSQL Server Execution Times:<br \/>\n<strong>CPU time =<\/strong> <strong>37265 ms<\/strong>,\u00a0 elapsed time = 5300 ms.<\/p>\n<p>The logical reads is almost the same, but we have a huge difference in the CPU Time.<\/p>\n<p>The two queries have the same execution Plan doing a Scan on the index SK01_Test_Collation_SQL and working on parallel.<\/p>\n<h6><strong>Results<\/strong><\/h6>\n<p>Windows Collation: 45 seconds and 348922 ms of CPU time<\/p>\n<p>SQL Collation: 5 seconds and\u00a0 37265 ms of CPU time<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Unbelievable!!!<\/strong><\/span><\/p>\n<p>Why does it happen?<\/p>\n<p>This article help us to understand:<\/p>\n<p><a href=\"https:\/\/support.microsoft.com\/en-us\/help\/322112\/comparing-sql-collations-to-windows-collations\" target=\"_blank\">https:\/\/support.microsoft.com\/en-us\/help\/322112\/comparing-sql-collations-to-windows-collations<\/a><\/p>\n<p>&#8220;<em>If you are storing and handling your data by using non-Unicode data types (<span class=\"text-base\">char<\/span>, <span class=\"text-base\">varchar<\/span>, <span class=\"text-base\">text<\/span>), and you are using a <strong>SQL collation<\/strong>, string comparisons will be performed with a <strong>non-Unicode SQL sort order<\/strong>.<\/em><\/p>\n<p><em>If you are storing and handling your data by using non-Unicode data types (<span class=\"text-base\">char<\/span>, <span class=\"text-base\">varchar<\/span>, <span class=\"text-base\">text<\/span>), and you are using a <strong>Windows collation<\/strong>, string comparisons will be performed with the <strong>Unicode sorting rules<\/strong>. <strong>This may cause<\/strong> <strong>certain operations that are unusually dependent on string sorting performance to <span style=\"color: #ff0000;\">take longer and to use more CPU<\/span> than a similar operation that is performed with a SQL collation.<\/strong><\/em>&#8221;<\/p>\n<p><strong>I did another test with more data and the results are:<\/strong><\/p>\n<p><strong>Windows Collation:<\/strong> 1 minute and 48 seconds<\/p>\n<p><strong>SQL Collation:<\/strong> 12 seconds<\/p>\n<p><span style=\"color: #ff0000;\">It&#8217;s like a magic! A huge difference!!<br \/>\n<\/span><\/p>\n<p>Enjoy and share with your friends&#8230;<\/p>\n<p>Thanks to my friend Edvaldo (<a href=\"http:\/\/edvaldocastro.com\/\" target=\"_blank\">Blog<\/a>) for the revision of the text.<\/p>\n<p>Fabr\u00edcio Fran\u00e7a Lima<\/p>\n<p>MCITP \u2013 Database Administrator<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8220;. How often do you have to use a query like this? Select Columns,&#8230; from Table where Name like &#8216;%String%&#8217; Reading the great book SQL Server 2012 Internals, on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_post_was_ever_published":false},"categories":[33],"tags":[1459,475,1456,1453,1434,1458,1457,1450,1452,1451,1455,33,1454],"class_list":["post-7342","post","type-post","status-publish","format-standard","hentry","category-sql-server","tag-collate-sql_latin1_general_cp1_ci_ai","tag-collation","tag-collation-bin","tag-collation-performance","tag-collation-sql-server","tag-latin1_general","tag-latin1_general_ci_ai","tag-like","tag-performance-problem","tag-performance-tuning","tag-sql-collation","tag-sql-server","tag-windows-collation"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses &quot; like &#039;%String%&#039; &quot;. How often do you have to use a query like this? Select Columns,... from Table where Name like &#039;%String%&#039; Reading the great book SQL Server 2012 Internals, on\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Fabr\u00edcio Lima\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"pt_BR\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Fabricio Lima | Neg\u00f3cios, Dados e IA - Insights pr\u00e1ticos sobre neg\u00f3cios, dados e intelig\u00eancia artificial.\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Improve the performance of a query that uses \u201d like \u2018%String%\u2019 \u201d changing only the collation - Fabricio Lima | Neg\u00f3cios, Dados e IA\" \/>\n\t\t<meta property=\"og:description\" content=\"Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses &quot; like &#039;%String%&#039; &quot;. How often do you have to use a query like this? Select Columns,... from Table where Name like &#039;%String%&#039; Reading the great book SQL Server 2012 Internals, on\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2017-02-08T16:43:53+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2017-02-08T17:12:29+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Improve the performance of a query that uses \u201d like \u2018%String%\u2019 \u201d changing only the collation - Fabricio Lima | Neg\u00f3cios, Dados e IA\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses &quot; like &#039;%String%&#039; &quot;. How often do you have to use a query like this? Select Columns,... from Table where Name like &#039;%String%&#039; Reading the great book SQL Server 2012 Internals, on\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#blogposting\",\"name\":\"Improve the performance of a query that uses \\u201d like \\u2018%String%\\u2019 \\u201d changing only the collation - Fabricio Lima | Neg\\u00f3cios, Dados e IA\",\"headline\":\"Improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8221; changing only the collation\",\"author\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/author\\\/fabricio\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/www.fabriciolima.net\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/PostCollationTable.png\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#articleImage\"},\"datePublished\":\"2017-02-08T14:43:53-02:00\",\"dateModified\":\"2017-02-08T15:12:29-02:00\",\"inLanguage\":\"pt-BR\",\"commentCount\":4,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#webpage\"},\"articleSection\":\"SQL Server, COLLATE SQL_Latin1_General_CP1_CI_AI, Collation, Collation BIN, collation performance, collation sql server, Latin1_General, Latin1_General_CI_AI, like, performance problem, performance tuning, sql collation, SQL Server, windows collation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fabriciolima.net\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/category\\\/sql-server\\\/#listItem\",\"name\":\"SQL Server\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/category\\\/sql-server\\\/#listItem\",\"position\":2,\"name\":\"SQL Server\",\"item\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/category\\\/sql-server\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#listItem\",\"name\":\"Improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8221; changing only the collation\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#listItem\",\"position\":3,\"name\":\"Improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8221; changing only the collation\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/category\\\/sql-server\\\/#listItem\",\"name\":\"SQL Server\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/#organization\",\"name\":\"Fabricio Lima | Neg\\u00f3cios, Dados e IA\",\"description\":\"Insights pr\\u00e1ticos sobre neg\\u00f3cios, dados e intelig\\u00eancia artificial.\",\"url\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/author\\\/fabricio\\\/#author\",\"url\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/author\\\/fabricio\\\/\",\"name\":\"Fabr\\u00edcio Lima\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bf37320f6a46a98e189640eb70a8304c0ab624d1d7508cea5e99f626f4d56829?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Fabr\\u00edcio Lima\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#webpage\",\"url\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/\",\"name\":\"Improve the performance of a query that uses \\u201d like \\u2018%String%\\u2019 \\u201d changing only the collation - Fabricio Lima | Neg\\u00f3cios, Dados e IA\",\"description\":\"Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses \\\" like '%String%' \\\". How often do you have to use a query like this? Select Columns,... from Table where Name like '%String%' Reading the great book SQL Server 2012 Internals, on\",\"inLanguage\":\"pt-BR\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/2017\\\/02\\\/08\\\/improve-the-query-performance-with-like-string-changing-only-the-collation\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/author\\\/fabricio\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/author\\\/fabricio\\\/#author\"},\"datePublished\":\"2017-02-08T14:43:53-02:00\",\"dateModified\":\"2017-02-08T15:12:29-02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/\",\"name\":\"Fabricio Lima | Neg\\u00f3cios, Dados e IA\",\"description\":\"Insights pr\\u00e1ticos sobre neg\\u00f3cios, dados e intelig\\u00eancia artificial.\",\"inLanguage\":\"pt-BR\",\"publisher\":{\"@id\":\"https:\\\/\\\/fabriciolima.net\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Improve the performance of a query that uses \u201d like \u2018%String%\u2019 \u201d changing only the collation - Fabricio Lima | Neg\u00f3cios, Dados e IA","description":"Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses \" like '%String%' \". How often do you have to use a query like this? Select Columns,... from Table where Name like '%String%' Reading the great book SQL Server 2012 Internals, on","canonical_url":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#blogposting","name":"Improve the performance of a query that uses \u201d like \u2018%String%\u2019 \u201d changing only the collation - Fabricio Lima | Neg\u00f3cios, Dados e IA","headline":"Improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8221; changing only the collation","author":{"@id":"https:\/\/fabriciolima.net\/blog\/author\/fabricio\/#author"},"publisher":{"@id":"https:\/\/fabriciolima.net\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2017\/02\/PostCollationTable.png","@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#articleImage"},"datePublished":"2017-02-08T14:43:53-02:00","dateModified":"2017-02-08T15:12:29-02:00","inLanguage":"pt-BR","commentCount":4,"mainEntityOfPage":{"@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#webpage"},"isPartOf":{"@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#webpage"},"articleSection":"SQL Server, COLLATE SQL_Latin1_General_CP1_CI_AI, Collation, Collation BIN, collation performance, collation sql server, Latin1_General, Latin1_General_CI_AI, like, performance problem, performance tuning, sql collation, SQL Server, windows collation"},{"@type":"BreadcrumbList","@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/fabriciolima.net\/blog#listItem","position":1,"name":"Home","item":"https:\/\/fabriciolima.net\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/#listItem","name":"SQL Server"}},{"@type":"ListItem","@id":"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/#listItem","position":2,"name":"SQL Server","item":"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/","nextItem":{"@type":"ListItem","@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#listItem","name":"Improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8221; changing only the collation"},"previousItem":{"@type":"ListItem","@id":"https:\/\/fabriciolima.net\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#listItem","position":3,"name":"Improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8221; changing only the collation","previousItem":{"@type":"ListItem","@id":"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/#listItem","name":"SQL Server"}}]},{"@type":"Organization","@id":"https:\/\/fabriciolima.net\/blog\/#organization","name":"Fabricio Lima | Neg\u00f3cios, Dados e IA","description":"Insights pr\u00e1ticos sobre neg\u00f3cios, dados e intelig\u00eancia artificial.","url":"https:\/\/fabriciolima.net\/blog\/"},{"@type":"Person","@id":"https:\/\/fabriciolima.net\/blog\/author\/fabricio\/#author","url":"https:\/\/fabriciolima.net\/blog\/author\/fabricio\/","name":"Fabr\u00edcio Lima","image":{"@type":"ImageObject","@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/bf37320f6a46a98e189640eb70a8304c0ab624d1d7508cea5e99f626f4d56829?s=96&d=mm&r=g","width":96,"height":96,"caption":"Fabr\u00edcio Lima"}},{"@type":"WebPage","@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#webpage","url":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/","name":"Improve the performance of a query that uses \u201d like \u2018%String%\u2019 \u201d changing only the collation - Fabricio Lima | Neg\u00f3cios, Dados e IA","description":"Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses \" like '%String%' \". How often do you have to use a query like this? Select Columns,... from Table where Name like '%String%' Reading the great book SQL Server 2012 Internals, on","inLanguage":"pt-BR","isPartOf":{"@id":"https:\/\/fabriciolima.net\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/#breadcrumblist"},"author":{"@id":"https:\/\/fabriciolima.net\/blog\/author\/fabricio\/#author"},"creator":{"@id":"https:\/\/fabriciolima.net\/blog\/author\/fabricio\/#author"},"datePublished":"2017-02-08T14:43:53-02:00","dateModified":"2017-02-08T15:12:29-02:00"},{"@type":"WebSite","@id":"https:\/\/fabriciolima.net\/blog\/#website","url":"https:\/\/fabriciolima.net\/blog\/","name":"Fabricio Lima | Neg\u00f3cios, Dados e IA","description":"Insights pr\u00e1ticos sobre neg\u00f3cios, dados e intelig\u00eancia artificial.","inLanguage":"pt-BR","publisher":{"@id":"https:\/\/fabriciolima.net\/blog\/#organization"}}]},"og:locale":"pt_BR","og:site_name":"Fabricio Lima | Neg\u00f3cios, Dados e IA - Insights pr\u00e1ticos sobre neg\u00f3cios, dados e intelig\u00eancia artificial.","og:type":"article","og:title":"Improve the performance of a query that uses \u201d like \u2018%String%\u2019 \u201d changing only the collation - Fabricio Lima | Neg\u00f3cios, Dados e IA","og:description":"Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses &quot; like '%String%' &quot;. How often do you have to use a query like this? Select Columns,... from Table where Name like '%String%' Reading the great book SQL Server 2012 Internals, on","og:url":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/","article:published_time":"2017-02-08T16:43:53+00:00","article:modified_time":"2017-02-08T17:12:29+00:00","twitter:card":"summary_large_image","twitter:title":"Improve the performance of a query that uses \u201d like \u2018%String%\u2019 \u201d changing only the collation - Fabricio Lima | Neg\u00f3cios, Dados e IA","twitter:description":"Hi Folks, In this blog post, I will give you a very useful tip to improve the performance of a query that uses &quot; like '%String%' &quot;. How often do you have to use a query like this? Select Columns,... from Table where Name like '%String%' Reading the great book SQL Server 2012 Internals, on"},"aioseo_meta_data":{"post_id":"7342","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-07-04 23:43:05","updated":"2026-07-04 23:43:05"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/fabriciolima.net\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/\" title=\"SQL Server\">SQL Server<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tImprove the performance of a query that uses \u201d like \u2018%String%\u2019 \u201d changing only the collation\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/fabriciolima.net\/blog"},{"label":"SQL Server","link":"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/"},{"label":"Improve the performance of a query that uses &#8221; like &#8216;%String%&#8217; &#8221; changing only the collation","link":"https:\/\/fabriciolima.net\/blog\/2017\/02\/08\/improve-the-query-performance-with-like-string-changing-only-the-collation\/"}],"jetpack-related-posts":[{"id":7307,"url":"https:\/\/fabriciolima.net\/blog\/2017\/02\/06\/video-melhorando-a-performance-de-uma-consulta-com-like-string-alterando-a-collation\/","url_meta":{"origin":7342,"position":0},"title":"V\u00eddeo: Melhorando a performance de uma consulta com like &#8216;%String%&#8217; alterando a Collation","author":"Fabr\u00edcio Lima","date":"6 de fevereiro de 2017","format":false,"excerpt":"Fala Pessoal, Nesse v\u00eddeo de hoje vou\u00a0dar uma dica de tuning que\u00a0s\u00f3 aprendi agora em 2017. Uma coisa simples que\u00a0pode melhorar drasticamente uma consulta como essa abaixo: Select\u00a0Colunas,XXX FROM Tabela WHERE Coluna like '%String%' \u00c9 s\u00e9rio... Parece m\u00e1gica... Assista... Teste... Compartilhe... Veja no v\u00eddeo abaixo: https:\/\/www.youtube.com\/watch?v=cyteAND34I0 Segue os scripts utilizados\u2026","rel":"","context":"Em &quot;Administra\u00e7\u00e3o de Banco de Dados&quot;","block_context":{"text":"Administra\u00e7\u00e3o de Banco de Dados","link":"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/administracao-de-bd\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/img.youtube.com\/vi\/cyteAND34I0\/0.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1104,"url":"https:\/\/fabriciolima.net\/blog\/2012\/01\/10\/casos-do-dia-a-dia-erro-de-collation-em-uma-consulta\/","url_meta":{"origin":7342,"position":1},"title":"Casos do Dia a Dia &#8211; Erro de Collation em uma Consulta","author":"Fabr\u00edcio Lima","date":"10 de janeiro de 2012","format":false,"excerpt":"Fala Pessoal, O foco desse post n\u00e3o \u00e9 explicar o que \u00e9 uma collation, mas sim contar uma experi\u00eancia de duas situa\u00e7\u00f5es que j\u00e1 passei. Quando instalamos o SQL Server ele possui uma collation default chamada SQL_Latin1_General_CP1_CI_AS. Eu particularmente, utilizo na maioria das vezes a collation SQL_Latin1_General_CP1_CI_AI. Agora, imaginem que\u2026","rel":"","context":"Em &quot;Administra\u00e7\u00e3o de Banco de Dados&quot;","block_context":{"text":"Administra\u00e7\u00e3o de Banco de Dados","link":"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/administracao-de-bd\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/01\/ErroCollation1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/01\/ErroCollation1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/01\/ErroCollation1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.fabriciolima.net\/blog\/wp-content\/uploads\/2012\/01\/ErroCollation1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":9693,"url":"https:\/\/fabriciolima.net\/blog\/2018\/11\/30\/managed-instance-12-configuracao-da-collation-da-instancia\/","url_meta":{"origin":7342,"position":2},"title":"Managed Instance (#12) \u2013 Configura\u00e7\u00e3o da Collation da inst\u00e2ncia","author":"Fabr\u00edcio Lima","date":"30 de novembro de 2018","format":false,"excerpt":"Fala Pessoal, Esse \u00e9 mais um post da s\u00e9rie sobre o Azure SQL Database Managed Instance. Caso ainda n\u00e3o tenha visto, seguem os posts anteriores: Azure SQL DB Managed Instance \u2013 Introdu\u00e7\u00e3o Managed Instance \u2013 Criando minha primeira inst\u00e2ncia Managed Instance \u2013 Como se conectar direto do SSMS utilizando uma\u2026","rel":"","context":"Em &quot;Azure SQL Database&quot;","block_context":{"text":"Azure SQL Database","link":"https:\/\/fabriciolima.net\/blog\/category\/azure-sql-database\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/11\/Managedinstance_Collation_1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/11\/Managedinstance_Collation_1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/11\/Managedinstance_Collation_1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/11\/Managedinstance_Collation_1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":9911,"url":"https:\/\/fabriciolima.net\/blog\/2018\/12\/05\/managed-instance-15-anuncios-do-dia-04-12-2018\/","url_meta":{"origin":7342,"position":3},"title":"Managed Instance  (#15) \u2013 An\u00fancios do dia 04-12-2018","author":"Fabr\u00edcio Lima","date":"5 de dezembro de 2018","format":false,"excerpt":"Fala Pessoal, Ontem (04\/12\/2018) foi anunciado algumas novidades para o Managed Instance. Segue o post completo do Borko Novakovic: https:\/\/azure.microsoft.com\/en-us\/blog\/migrate-mission-critical-sql-workloads-to-the-most-economical-cloud-destination\/ General Availability (GA) Business Critical Service Tier Esse \u00e9 o an\u00fancio que est\u00e1vamos esperando para o in\u00edcio de Dezembro. Todos os posts e testes que realizei foram em um Preview\u2026","rel":"","context":"Em &quot;Azure SQL Database&quot;","block_context":{"text":"Azure SQL Database","link":"https:\/\/fabriciolima.net\/blog\/category\/azure-sql-database\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/12\/Managedinstance_Anuncioy_7.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/12\/Managedinstance_Anuncioy_7.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/12\/Managedinstance_Anuncioy_7.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/12\/Managedinstance_Anuncioy_7.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2018\/12\/Managedinstance_Anuncioy_7.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":19034,"url":"https:\/\/fabriciolima.net\/blog\/2023\/10\/05\/power-alerts-gerando-uma-documentacao-dinamica-de-configuracoes-da-minha-instancia-sql-server\/","url_meta":{"origin":7342,"position":4},"title":"[Power Alerts] Gerando uma documenta\u00e7\u00e3o din\u00e2mica de configura\u00e7\u00f5es da minha inst\u00e2ncia SQL Server","author":"Fabr\u00edcio Lima","date":"5 de outubro de 2023","format":false,"excerpt":"Fala Pessoal, Passando aqui para deixcar a dica de um v\u00eddeo onde mostrei uma feature top que temos no Power Alerts. https:\/\/www.youtube.com\/watch?v=VOTnFWh5FQ8&t=9s Imagina que voc\u00ea teve um problema grave e precise reinstalar seu SQL Server do ZERO. Qual collation eu utilizava? Em quais pastas estavam minhas bases? Quais logins, Jobs\u2026","rel":"","context":"Em &quot;Administra\u00e7\u00e3o de Banco de Dados&quot;","block_context":{"text":"Administra\u00e7\u00e3o de Banco de Dados","link":"https:\/\/fabriciolima.net\/blog\/category\/sql-server\/administracao-de-bd\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/img.youtube.com\/vi\/VOTnFWh5FQ8\/0.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":18550,"url":"https:\/\/fabriciolima.net\/blog\/2023\/01\/24\/managed-instance-26-maintenance-window\/","url_meta":{"origin":7342,"position":5},"title":"Managed Instance (#26) \u2013 Maintenance Window","author":"Fabr\u00edcio Lima","date":"24 de janeiro de 2023","format":false,"excerpt":"Fala Pessoal, Ap\u00f3s um longo inverno voltei a criar uma inst\u00e2ncia gerenciada no azure (managed Instance) e vi uma op\u00e7\u00e3o que ainda n\u00e3o tinha documentado aqui no Blog, a Maintenance Window: Quando fiz esse post em 2018 n\u00e3o era poss\u00edvel escolher a collation da inst\u00e2ncia: Collation Managed Instance Devo ter\u2026","rel":"","context":"Em &quot;Azure SQL Database&quot;","block_context":{"text":"Azure SQL Database","link":"https:\/\/fabriciolima.net\/blog\/category\/azure-sql-database\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/fabriciolima.net\/blog\/wp-content\/uploads\/2023\/01\/Managed_instance_timezone-e-maintenance-window-297x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_featured_media_url":"","post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts\/7342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/comments?post=7342"}],"version-history":[{"count":0,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/posts\/7342\/revisions"}],"wp:attachment":[{"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/media?parent=7342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/categories?post=7342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabriciolima.net\/blog\/wp-json\/wp\/v2\/tags?post=7342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}