我正在为自己创建一个小工具来查询大型数据库(1.7GB,只有一个表)
首先,它查询:
SELECT ip FROM player_analytics WHERE auth= :auth GROUP BY ip
之后,对于返回的每一行,它会查询:
SELECT auth FROM player_analytics WHERE ip= :ip AND auth<> :auth GROUP by auth
但是,整个过程需要大约2分钟,有时甚至更多,我想知道是否有任何方法可以加快速度并减少资源。
我会感激任何帮助,谢谢!
答案 0 :(得分:0)
试试这个:
SELECT DISTINCT pa2.auth
FROM (
SELECT DISTINCT pa.ip, pa.auth
FROM player_analytics pa
WHERE pa.auth= :auth
) pa1
JOIN player_analytics pa2
ON p2.ip = p1.ip
AND p2.auth <> p1.auth
auth
的{{1}}索引和联接的WHERE
索引。
答案 1 :(得分:0)
您可以尝试将其作为单个查询进行短语:
select distinct pa2.auth
from player_analytics pa join
player_analytics pa2
on pa.ip = pa2.ip and
pa.auth = :auth and
pa2.auth <> :auth;
对于此查询,您需要player_analytics(auth, ip)
和`player_analytics(ip,auth)上的两个索引。