我有一个纸牌游戏,用户根据他们赢得的游戏数量排名。总体评级是预先计算的,以便能够快速加载,但我在排名计算方面存在问题。
排名计算如下:
SET @userRank = 0;
UPDATE t_ratings AS r
JOIN
(
SELECT
userId, (@userRank := @userRank + 1) as rank
FROM (
SELECT
r.userId,
r.solvedCount,
r.playedCount
FROM
t_ratings AS r
ORDER BY r.solvedCount DESC , r.playedCount ASC) AS t
) AS rt
ON rt.userId = r.userId
SET r.rank = rt.rank
但最近我有时开始收到以下错误:
Deadlock found when trying to get lock; try restarting transaction
因此我想知道是否有更好的方法来计算用户等级以避免死锁?