Of course, sorting by random query takes some time, but if you have problems regularly using the same requested query, there is something wrong with setting up the database (incorrect indexing / no at all, too little memory, etc. .). I am not a db manager), or you are doing pagination incorrectly:
Terribly wrong: for example. making select * from hugetable where somecondition; into the array, getting the page counter using array.length, select the appropriate indexes and dicard array, and then repeat this for each page ... This is what I call serious wrong.
The best solution for two queries: one gets only the score, and then gets the results using limit and offset . (There may be one query option on some patented, non-standard SQL server, I donβt know)
A bad solution can actually work on small tables (in fact, it is inconceivable that it is faster on very small tables, because the overhead of executing two queries is more than getting all the rows in one query. Saying that it is .. .), but as the database begins to grow, the problems become apparent.
Stein G. Strindhaug
source share