<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: yarkul</title>
    <description>The latest articles on DEV Community by yarkul (@yarkul).</description>
    <link>https://dev.to/yarkul</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1013283%2Fd0fb5580-244d-4cce-8c51-1e520e406546.png</url>
      <title>DEV Community: yarkul</title>
      <link>https://dev.to/yarkul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yarkul"/>
    <language>en</language>
    <item>
      <title>The Simple SQL Question You May Be Asked on Interview and Fail</title>
      <dc:creator>yarkul</dc:creator>
      <pubDate>Wed, 25 Jan 2023 12:04:43 +0000</pubDate>
      <link>https://dev.to/yarkul/the-simple-sql-question-you-may-be-asked-on-interview-and-fail-2l09</link>
      <guid>https://dev.to/yarkul/the-simple-sql-question-you-may-be-asked-on-interview-and-fail-2l09</guid>
      <description>&lt;p&gt;At the interview, you may be asked a question about database indexes. And here is a very simple question that even an experienced developer can stumble on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Question
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The table has an index(IX_Salary) on the Salary column. Will it work for this SQL Statement?&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT Count(1)&lt;br&gt;
FROM [YarkulTestDb1].[dbo].[Person]&lt;br&gt;
WHERE Salary + 50 &amp;gt; 1000&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Answer
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;No&lt;/strong&gt;, because index does not work in case there is an operation on column in &lt;em&gt;WHERE&lt;/em&gt; expression. It will not be able to use that index to optimize the query because it is not filtering on the salary column directly. Instead, it is performing a calculation on the salary column (Salary + 50) and then filtering on the result of that calculation (&amp;gt; 1000). In this case, the query optimizer will likely have to scan the entire table to find the rows that match the condition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Case IX_Salary works well
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6xssfpt3zuzplbj9bsu6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6xssfpt3zuzplbj9bsu6.png" alt="Image description" width="780" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Case IX_Salary does &lt;strong&gt;not&lt;/strong&gt; do its job
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxdwkdqgp93d8dpjnme6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxdwkdqgp93d8dpjnme6o.png" alt="Image description" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About Me
&lt;/h2&gt;

&lt;p&gt;I am a Full Stack Developer with +15 years of experience. Learning new concepts and always looking for new challenges. Visit my personal blog &lt;a href="https://yarkul.com/" rel="noopener noreferrer"&gt;https://yarkul.com/&lt;/a&gt; to learn .NET, SQL, and Web Development.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
