更新时间:2022-09-09 08:51:37
在检查慢SQL时,发现一条统计SQL执行过慢,如下:
SELECT platform, channel, COUNT(DISTINCT(platformUserId)) as cnt FROM(
SELECT platform, channel, platformUserId, MIN(insertTimestamp) as rtime
FROM tsz_user
GROUP BY platform, channel, platformUserId
) a where a.rtime >= 1392393600 and a.rtime < 1392480000
GROUP BY platform, channel;
|
耗时2分33秒
SELECT platform, channel, COUNT(DISTINCT(platformUserId)) as cnt FROM(
SELECT platform, channel, platformUserId, MIN(insertTimestamp) as rtime
FROM tsz_user
GROUP BY platform, channel, platformUserId order by null
) a where a.rtime >= 1392393600 and a.rtime < 1392480000
GROUP BY platform, channel order by null;
|