I am running a query on around 1M records, using LIMIT and OFFSET to get a page of items.
The query looks like this:
select userId, max(score) as score, nick from gamebucket
where score is not null and app = "game_pc"
group by userId
order by score desc
limit 35 offset 10000
Result set looks like this:
[
{
"nick": "Zigzag Deadline",
"score": 24989,
"userId": "user_-qcZnaNpZ7rLo6jPxX-b"
},
{
"nick": "Zigzag Shoulder",
"score": 24989,
"userId": "user_-Y3G4w-BfIx-x6VLktcw"
}
]
Currently the query takes around 4-5 min to complete.
Is there some way to optimize it?
Thank you!