From 7514e93a8a3b583bfe42c433b53f8bac590f41f7 Mon Sep 17 00:00:00 2001 From: Zwelf Date: Sat, 30 May 2020 18:42:40 +0200 Subject: [PATCH] Optimize /top5points SQL query --- src/game/server/score/sql_score.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index fcbe407cd..7a74e036d 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -1317,23 +1317,13 @@ bool CSqlScore::ShowTopPointsThread(CSqlServer* pSqlServer, const CSqlDataexecuteSql("SET @prev := NULL;"); - pSqlServer->executeSql("SET @rank := 1;"); - pSqlServer->executeSql("SET @pos := 0;"); str_format(aBuf, sizeof(aBuf), "SELECT Rank, Points, Name " "FROM (" - "SELECT Name, " - "(@pos := @pos+1) pos, " - "(@rank := IF(@prev = Points,@rank, @pos)) Rank, " - "(@prev := Points) Points " - "FROM (" - "SELECT Name, Points " - "FROM %s_points " - "GROUP BY Name " - "ORDER BY Points DESC" - ") as a" - ") as b " + "SELECT RANK() OVER w AS Rank, Points, Name " + "FROM %s_points " + "WINDOW w as (ORDER BY Points DESC)" + ") as a " "ORDER BY Rank %s " "LIMIT %d, 5;", pSqlServer->GetPrefix(), pOrder, LimitStart