0
I need to consult a table extracting from it the Infos: <nome>
and <pontuacao>
, my tcc consists of a game in which one of its options is to see a ranking of registered players. as there is the possibility of soft growing in number of users this query may become very heavy if it is to return all tuples of the table.
What I wish is to be able to regain the current player’s position and 5 positions above and 5 below to relieve the load.
What I managed to do was:
select nome,pontuacao from jogador order by pontuacao DESC;
which makes the whole table search and this can harm the system further.
Would anyone know how to limit this query?
Luis, which DBMS do you use? Sql Server, Mysql, Postgresql, etc?
– Tobias Mesquita
If it is possible to change the business rule (show the player’s position plus the 5 top and 5 bottom positions), I would advise to bring only one Top10 through the use of syntax
top()
ofSQL
, one moreunion
to return the current position of the player.– Fellipe Soares
I will apply in Mysql.
– Luís Guilherme Rasch Oliveira
Luiz, I saw your comment just now, unfortunately Mysql is very limited on resources, you could even try to take advantage of my answer and use Subqueries instead of CTE and emulate ROW_NUMBER, but the performance would not be very encouraging, another possibility is to consider using Postgresql instead of Mysql.
– Tobias Mesquita
How would this query be ready in Postgresql ??? If it is good so it may be worth changing ... would change something???
– Luís Guilherme Rasch Oliveira
Perhaps I would have to make a few modifications, but the logic would be the same. Anything posts a new question.
– Tobias Mesquita