Suppose I have a simple database with a single table and no foreign key that refers to itself. Would MYSQL or MongoDB be better at randomly selecting a record? (Suppose there are 1 million records.)
I gathered that for SQL I would use:
SELECT col1, col2 FROM table WHERE col3 = x ORDER BY RAND() LIMIT n
FOR MongoDB, I would use:
collection.aggregate([
{$match:{col3:{$eq: x}}},
{$sample:{size:n}}
])
Anyone with real-world experience with the performance of this type of queries as the number of records grows?
Of course, if there's no "WHERE" condition I would keep a continuous INT id and randomly draw a number.
Aucun commentaire:
Enregistrer un commentaire