我对twe非常相似的查询的执行时间有疑问。
下面的第二个查询花费的时间比第一个(10次或更多),任何线索为什么?数据大小?
提前谢谢。
QUERY 1:
SELECT DistinctUUsersID.user_guid AS uUserID, d.user_guid AS dUserID, count(*) AS numrows
FROM (SELECT DISTINCT u.user_guid
FROM users u) AS DistinctUUsersID
LEFT JOIN dogs d
ON DistinctUUsersID.user_guid=d.user_guid
GROUP BY DistinctUUsersID.user_guid
ORDER BY numrows DESC;
QUERY 2:
SELECT DistinctUUsersID.user_guid AS uUserID, DistinctDUsersID.user_guid AS dUserID, count(*) AS numrows
FROM (SELECT DISTINCT u.user_guid
FROM users u) AS DistinctUUsersID
LEFT JOIN (SELECT DISTINCT d.user_guid
FROM dogs d) AS DistinctDUsersID
ON DistinctUUsersID.user_guid=DistinctDUsersID.user_guid
GROUP BY DistinctUUsersID.user_guid
ORDER BY numrows DESC;