title: SQL Server GROUP BY too slow
body: <p>I'm trying to run two queries on SQL LocalDB. One of them executes fast and the other takes 12 seconds although the difference is only one column added to the select and group by clauses.</p>
  
  <p>The following query executes in nearly no time:</p>
  
  <pre><code>select  [Company]
      ,sum([Hours]) as [Hours] 
  from [Operation View]  
  where company_id in (19,53,76,1) 
      and action_id in (5,21,23,30) 
      and [Report Date] &gt;= '2014-04-01' 
  group by [Company] 
  order by Company
  </code></pre>
  
  <p>While the below query takes around 12 seconds:</p>
  
  <pre><code>select  [Company]
      ,Department
      ,sum([Hours]) as [Hours]
  from [Operation View]  
  where company_id in (19,53,76,1) 
      and action_id in (5,21,23,30) 
      and [Report Date] &gt;= '2014-04-01' 
  group by [Company]
      ,Department
  </code></pre>
  
  <p>As you can see, I only added one extra column <code>Department</code> in the select and group by clauses. </p>
  
  <p>If I try to add more columns, the execution time remains at 12 seconds. </p>
  
  <p>Is this a normal behavior? Is there anything I can do to speed up the query?</p>
  
  <p>Note that the [Operation View] is a view that is based on a main table joined by other lookup tables that provides the link between the ID's and the Names of the fields. </p>
  
  <p>I thought about indexing the view but I have a text column which prevented this option.</p>