当我在MySQL DB上运行此查询时,它会在200毫秒内返回:
SELECT Players.id, Players.level, Players.firstName, Players.lastname, RankedPlayers.rank, Players.points
FROM Players
INNER JOIN
(
SELECT
id,
@curRank := @curRank + 1 AS rank
FROM Players p, (SELECT @curRank := 0) r
ORDER BY points DESC
) as RankedPlayers
ON RankedPlayers.id = Players.id
ORDER BY rank;
但是当我添加WHERE player.id = 231145
时,需要 9秒!
SELECT Players.id, Players.level, Players.firstName, Players.lastname, RankedPlayers.rank, Players.points
FROM Players
INNER JOIN
(
SELECT
id,
@curRank := @curRank + 1 AS rank
FROM Players p, (SELECT @curRank := 0) r
ORDER BY points DESC
) as RankedPlayers
ON RankedPlayers.id = Players.id
WHERE Players.id = 231145
ORDER BY rank;