title: count aggregate in query select on laravel4
body: <p>I have the select like this:    </p>
  
  <pre><code>StoreProduct::where('user_id', Auth::user()-&gt;main_id)
              -&gt;whereNotExists(function($query)
              {
                   $query-&gt;select(DB::raw(1))
                         -&gt;from('store_products')
                         -&gt;whereRaw('store_products.store_product_id = store_product.id');
              })
              -&gt;orderBy('id', 'desc')-&gt;paginate($perPage) 
  </code></pre>
  
  <p>In my database are 20K rows, and this select execute about 65 seconds.</p>
  
  <p>Im using laravel debugbar. Queries dump 2 select: </p>
  
  <pre><code>select count(*) as aggregate from `store_product` where `store_product`.`deleted_at` is null and `user_id` = '20' and not exists (select 1 from `store_products` where store_products.store_product_id = store_product.id)65.88s
  select * from `store_product` where `store_product`.`deleted_at` is null and `user_id` = '20' and not exists (select 1 from `store_products` where store_products.store_product_id = store_product.id) order by `id` desc limit 24 offset 0
  </code></pre>
  
  <p>Why laravel do <code>select count(*) as aggregate</code>? How to optimizate this query?</p>