Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query Failed Error: Resources exceeded during query execution: The query could not be executed in the allotted memory

I am using Standard SQL.Even though its a basic query it is still throwing errors. Any suggestions pls

SELECT 
  fullVisitorId,
  CONCAT(CAST(fullVisitorId AS string),CAST(visitId AS string)) AS session,
  date,
  visitStartTime,
  hits.time,
  hits.page.pagepath
FROM
  `XXXXXXXXXX.ga_sessions_*`,
  UNNEST(hits) AS hits
WHERE
  _TABLE_SUFFIX BETWEEN "20160801"
  AND "20170331"
ORDER BY
  fullVisitorId,
  date,
  visitStartTime
like image 351
HKE Avatar asked Sep 01 '17 17:09

HKE


2 Answers

The only way for this query to work is by removing the ordering applied in the end:

SELECT 
  fullVisitorId,
  CONCAT(CAST(fullVisitorId AS string),CAST(visitId AS string)) AS session,
  date,
  visitStartTime,
  hits.time,
  hits.page.pagepath
FROM
  `XXXXXXXXXX.ga_sessions_*`,
  UNNEST(hits) AS hits
WHERE
  _TABLE_SUFFIX BETWEEN "20160801"
  AND "20170331"

ORDER BY operation is quite expensive and cannot be processed in parallel so try to avoid it (or try applying it in a limited result set)

like image 180
Willian Fuks Avatar answered Nov 04 '22 22:11

Willian Fuks


Besides the accepted answer, you might want to partition your table by date to lessen the amount of memory used with an expensive query.

like image 3
Embedded_Mugs Avatar answered Nov 04 '22 23:11

Embedded_Mugs