title: BigQuery - Group By with multiple fields extremely slow
body: <p>I'm trying to group by multiple fields, such as Dates that spans through a few years with unique days (so 5*365 days maximum), and some unique IDs (a few thousand I believe).</p>
  
  <p>The query is pretty simple:</p>
  
  <pre><code>SELECT
    cs.CriterionId,
    cs.AdGroupId,
    cs.CampaignId,
    cs.Date,
    SUM(cs.Impressions) AS Sum_Impressions,
    SUM(cs.Clicks) AS Sum_Clicks,
    SUM(cs.Interactions) AS Sum_Interactions,
    (SUM(cs.Cost) / 1000000) AS Sum_Cost,
    SUM(cs.Conversions) AS Sum_Conversions,
    cs.AdNetworkType1,
    cs.AdNetworkType2,
    cs.AveragePosition,
    cs.Device,
    cs.InteractionTypes
  FROM
    `adwords.Keyword_{customer_id}` c
  LEFT JOIN
    `adwords.KeywordBasicStats_{customer_id}` cs
  ON
    c.ExternalCustomerId = cs.ExternalCustomerId
  WHERE
    c._DATA_DATE = c._LATEST_DATE
    AND c.ExternalCustomerId = {customer_id}
  GROUP BY
    1, 2, 3, 4, 10, 11, 12, 13, 14
  ORDER BY
    1, 2, 3, 4, 10, 11, 12, 13, 14
  </code></pre>
  
  <p>The keywordBasicStats table has around 700MB of data, and Keyword has around 50MB, and it's running for around a few hours now.</p>
  
  <p>Not sure if there's a way to optimize this SQL query.</p>
  
  <p>If anyone at Google is interested, the Job ID is:</p>
  
  <pre><code>blissful-land-197118:US.bquijob_668c014c_164b8710acc
  </code></pre>