使用我们的测试数据集运行以下查询花了18分钟:
SELECT count(distinct S1.visitorId, 50000) as returningVisitors,
STRFTIME_UTC_USEC(UTC_USEC_TO_DAY(PARSE_UTC_USEC(S1.timeStamp)), '%Y-%m-%d') AS day,
S1.dimension1, S1.dimension2
FROM [myDataset.MyTable] as S1
JOIN EACH [myDataset.MyTable] as S2 on S1.visitorId= S2.visitorId
WHERE UTC_USEC_TO_DAY(PARSE_UTC_USEC(S1.timeStamp)) < UTC_USEC_TO_DAY(NOW()) and
S2.timeStamp < STRFTIME_UTC_USEC(UTC_USEC_TO_DAY(PARSE_UTC_USEC(S1.timeStamp)), '%Y-%m-%d')
GROUP EACH BY S1.dimension1, S1.dimension2, day
ORDER BY S1.dimension1, S1.dimension2, day;
最后,我在网络浏览器中收到以下消息: “查询完成( 1112.1s已过去,1.62 MB处理)”
我想知道为什么花了这么长时间。我通常使用BigQuery获得更快的结果。
查询在同一个表上执行JOIN,以获取每天和维度的返回访问者数量。我希望查询可能需要5-6分钟而不是18分钟,特别是因为表格不是那么大。
我的表大约有31000行,总大小为4.25 Mb。 我的职位是:job_b657aceeb1004994b0b0332d461cdcd2
答案 0 :(得分:3)
此查询仍然需要很长时间才能处理吗?如果只发生一次,“为什么”可能是一个罕见的内部性能问题。
告诉我,如果我做对了:你自己加入桌子的唯一原因是检查用户是否曾经去过那里?在这种情况下,您正在产生指数增长(我使用这个词吗?)组合的数量,而不需要。查询仅引用S2一次,以检查它是否小于当前行的时间戳日。
如果您更换,该怎么办?
JOIN EACH [myDataset.MyTable] as S2 on S1.visitorId= S2.visitorId
使用:
JOIN EACH
(SELECT visitorId, MIN(timeStamp) timeStamp FROM [myDataset.MyTable] GROUP EACH BY 1) S2
ON S1.visitorId= S2.visitorId
得到:
SELECT count(distinct S1.visitorId, 50000) as returningVisitors,
STRFTIME_UTC_USEC(UTC_USEC_TO_DAY(PARSE_UTC_USEC(S1.timeStamp)), '%Y-%m-%d') AS day,
S1.dimension1, S1.dimension2
FROM [myDataset.MyTable] as S1
JOIN EACH
(SELECT visitorId, MIN(timeStamp) timeStamp FROM [myDataset.MyTable] GROUP EACH BY 1) S2
ON S1.visitorId= S2.visitorId WHERE UTC_USEC_TO_DAY(PARSE_UTC_USEC(S1.timeStamp)) < UTC_USEC_TO_DAY(NOW()) and
S2.timeStamp < STRFTIME_UTC_USEC(UTC_USEC_TO_DAY(PARSE_UTC_USEC(S1.timeStamp)), '%Y-%m-%d')
GROUP EACH BY S1.dimension1, S1.dimension2, day
ORDER BY S1.dimension1, S1.dimension2, day;
一些注意事项: