In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
SELECT
TIMESTAMP_SECONDS(visitStartTime) AS stamp,
customDimension.value AS UserID,
CONCAT(CAST(fullVisitorId AS STRING),
CAST(visitId AS STRING)) AS visit_ref,
COUNT(DISTINCT CONCAT(CAST(fullVisitorId AS STRING),
CAST(visitId AS STRING))) OVER (PARTITION
BY
customDimension.value ) AS total_visits_in_cycle,
RANK() OVER (PARTITION
BY
CONCAT(CAST(fullVisitorId AS STRING),
CAST(visitId AS STRING)),
TIMESTAMP_SECONDS(visitStartTime)
ORDER BY
TIMESTAMP_SECONDS(visitStartTime)) AS visitrank,
COUNT(DISTINCT transaction.transactionid) AS orders
FROM
`xxx.xxx.ga_sessions_20*` AS t CROSS
JOIN
UNNEST(hits) AS hits CROSS
JOIN
UNNEST(t.customdimensions) AS customDimension
WHERE
parse_date('%y%m%d', _table_suffix) BETWEEN DATE_sub(current_date(), INTERVAL 3 day) AND DATE_sub(current_date(), INTERVAL 1 day)
AND customDimension.index = 2
GROUP BY
1,
2,
3,
fullVisitorId,
visitid,
visitStartTime
ORDER BY
UserID LIMIT 500