breakfastapi icon indicating copy to clipboard operation
breakfastapi copied to clipboard

DB unnecessary ordering

Open Kulda22 opened this issue 3 years ago • 1 comments

Hi, I've noticed this SQL SELECT * FROM items ORDER BY RANDOM() LIMIT 1 in your database.

What it does, as far as I know, is it orders WHOLE database in some random way, then selects first element. This is really slow way of fetching one random row.

Faster way of doing this is generating random number (between 0 and table size) and then doing something like SELECT * FROM items WHERE ID = <generated number>". (It seems you don't have ID column, but column Unnamed: 0 looks like ID-like column, so making it primary key is a good idea)

Kulda22 avatar Feb 08 '22 21:02 Kulda22

Hey, thanks for your reply! Yes I agree that it's not the most efficient way to do it! Will fix this in the next update and close the issue. Cheers!

MariiaSizova avatar Feb 11 '22 07:02 MariiaSizova