A
A
Arman2020-03-06 13:49:02
Software design
Arman, 2020-03-06 13:49:02

How to quickly select random records from the database and which database is best for this?

There is a task that is very reminiscent of a casino or a game, i.e. some records in the database and you need to choose a random one from them. Of the nuances, each entry has a weight, i.e. some percentage of success.
While I think this percentage of success is to be implemented by separate additional. records.
Can already who implemented and selected for such task of a DB?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2020-03-06
@ThunderCat

A buy rand order is always a load on any RDB, the most effective method is to transfer part of the logic from the database to the application.
A select is made max id, then in the range 1-max. program random indexes, with an overhead 3-4 times, and a request is made already with ready-made random IDs and an order by rand, the limit is as much as necessary.

Of the nuances, each entry has a weight, i.e. some percentage of success.

In your case, a larger overhead is taken, and a buy order is made, so heavier weights are more likely to be selected.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question