title: Slow query with where clause
body: <p>I have following sql query that take only 1 second to execute:</p>
  
  <pre><code>select a.date, b.rate, c.type, a.value from
  
  a inner join b on a.id = b.aid
  c inner join b.id = c.bid
  where a.name = 'xxx'
  </code></pre>
  
  <p>But I need a resultset to get the results that has rate greater than 0. So when I change the query to this it takes 7 minutes to execute:</p>
  
  <pre><code>select a.date, b.rate, c.type, a.value from
  
  a inner join b on a.id = b.aid
  c inner join b.id = c.bid
  where a.name = 'xxx' and b.rate&gt;0
  </code></pre>
  
  <p>Why would this make the query time go up from 1 sec to 7 mins? Since the b table is huge I even tried to use CTE but that did not improve the performance either. I thought with the CTE there will be smaller set of values to filter from so it should be faster but that did not help:</p>
  
  <pre><code>;with x as
  (select a.date, b.rate, c.type, a.value from
  
  a inner join b on a.id = b.aid
  c inner join b.id = c.bid
  where a.name = 'xxx')
  select * from x where rate&gt;0
  </code></pre>
  
  <p>I cannot include the execution plan as I don't have permissions to db other than querying.</p>