Re: ORDER BY random() LIMIT 1 slowness
От
Greg Stark
Тема
Re: ORDER BY random() LIMIT 1 slowness
Дата
Msg-id
87u1hc4h65.fsf@stark.dyndns.tv
Ответ на
Re: ORDER BY random() LIMIT 1 slowness (Tom Lane)
Список
Дерево обсуждения
Re: ORDER BY random() LIMIT 1 slowness Jean-Luc Lachance <jllachan@nsd.ca>
Tom Lane writes: > "Gavin M. Roy" writes: > > SELECT * FROM poetry ORDER BY random() LIMIT 1; > > [ is slow for 35000 rows ] > > Yeah. Basically this query is implemented as > (a) select all 35000 rows of "poetry"; > (b) compute a random() value for each row; > (c) sort by the random() values; > (d) take the first row, discard the rest. If you can generate a random value from your application layer you could do select * from poetry LIMIT 1 OFFSET Can offset values be placeholders in prepared queries? If not then this has that disadvantage. -- greg
В списке pgsql-general по дате отправления