title: Performance in sql server?
body: <p>2 related questions : </p>
  
  <hr>
  
  <p><strong>question #1 :</strong> </p>
  
  <p>I have a myTable with <code>id , name , lastname</code></p>
  
  <p><code>id</code> is seed (pk).</p>
  
  <p><code>name</code> has index on it. //not nullAble.</p>
  
  <p>which query is faster ? </p>
  
  <ul>
  <li><code>select id , name , lastname from mytable where name = name  //(name has index on it!)</code></li>
  </ul>
  
  <p>or</p>
  
  <ul>
  <li><code>select id , name , lastname from mytable</code></li>
  </ul>
  
  <hr>
  
  <p><strong>question #2 :</strong> *<em>now lets assume name is nullable.</em>*</p>
  
  <p>from the first sample </p>
  
  <p>there is a select query sp which its parameter is <code>@name</code> + <code>@lastName</code></p>
  
  <p>(returning all rows where <code>name  = @name</code> or <code>lastName= @lastName</code>)</p>
  
  <p>which query is faster ? </p>
  
  <pre><code>select id , name , lastname from mytable where 
     (@name is null or  name=@name)
  
  and
  
     (@lastName is null or  lastName=@lastName) 
  </code></pre>
  
  <blockquote>
    <p>here if @name  or @lastName are null  - so it wont compare name=@name</p>
  </blockquote>
  
  <p>or</p>
  
  <pre><code> select id , name , lastname from mytable where 
         (name =  isNull(@name,name))
  
      and
  
        (lastName=  isNull(@lastName,lastName))
  </code></pre>
  
  <blockquote>
    <p>here , if @name or @lastName are null , so there <strong>STILL</strong> will be equalization 
    of  <code>name= name</code>  and <code>lastName=lastName</code> , which i think is bad
    performance.</p>
  </blockquote>
  
  <p>please help ?</p>