title: Optimizing Group By in Flux
body: <p>I have a measurement with a few million rows of data containing information about around 20 thousand websites.</p>
  
  <pre><code>show tag keys from site_info:  
  domain 
  proxy  
  http_response_code
  
  show field keys from site_info:
  responseTime
  uuid
  source
  </code></pre>
  
  <p>What I want to do is count all of the uuid's for each website over a given time frame. I have tried writing a query like this one:  </p>
  
  <pre><code>from(bucket: "telegraf/autogen")            
      |&gt; range($range)            
      |&gt; filter(fn: (r) =&gt;                            
           r._measurement == "site_info"
           r._field == "uuid")    
      |&gt; group(columns:["domain"])        
      |&gt; count()
  </code></pre>
  
  <p>However this query will take up to 45 minutes to run for a time range of just <code>now()-6h</code> (assumingly due to the fact that I am trying to group data into 20k+ buckets)   </p>
  
  <p>Any suggestions on how to optimize the query to not take such extended amounts of time without altering the data schema?</p>