What you are looking for, IMHO, is a way to get the top elements of K in a (theoretically) infinite stream of elements.
I would not try to solve this problem directly in mysql, since your input is a stream, not a fixed dataset. In addition, given the size of the data set, redefining the vertex K from scratch on each insert is out of the question.
What I would do is to have a compact representation of the top K, which you update as new items arrive. For each element, take its rating and save a bunch of the top K elements that have been discovered so far.
A bit more formal: given the data flow q1,. ,, qn, add qj to the heap if Score (qj) is greater than the smallest estimate on the heap. In this case, the lowest grade point should be allocated from the heap.
Specific solution
You have several columns with ratings, and the user can query a maximum of 450 for any combination of columns using range queries.
What I would do is conceptually:
- keep the top 450 on the heap for each column of the account separately using the streaming method above
- at query time, get items matching the query column
- aggregate and sort lists as needed, and cut into 450
Hope this helps.
source share