mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Optimize /top5points SQL query
This commit is contained in:
parent
fa8972deb6
commit
7514e93a8a
|
@ -1317,23 +1317,13 @@ bool CSqlScore::ShowTopPointsThread(CSqlServer* pSqlServer, const CSqlData<CSqlP
|
|||
try
|
||||
{
|
||||
char aBuf[512];
|
||||
pSqlServer->executeSql("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
|
||||
|
|
Loading…
Reference in a new issue