Performance of ORDER BY RANDOM to select random rows?

Поиск
Список
Период
Сортировка
От Victor Hooi
Тема Performance of ORDER BY RANDOM to select random rows?
Дата
Msg-id CAMnnoU+K5dh_atGRAXPgYGhzxT5Spfs1ZMPRz8AmZ5CPeFaixQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Performance of ORDER BY RANDOM to select random rows?  (hubert depesz lubaczewski <depesz@depesz.com>)
Re: Performance of ORDER BY RANDOM to select random rows?  (Sergey Konoplev <gray.ru@gmail.com>)
Список pgsql-general
Hi,

I have a Django application where we need to pull random rows out of a table.

According to the Django documentation:


Note: order_by('?') queries may be expensive and slow, depending on the database backend you’re using.  

My understanding is that order_by('?') in the Django ORM will generate a query with ORDER BY RANDOM.

This blog post:


also seems to suggest that using ORDER BY RANDOM() will perform poorly on Postgres.

I'm just wondering if this is still the case?

I just ran those benchmarks on my system (Postgres 9.2.4), and using ORDERY BY RANDOM did not seem substantially to generating random integers in Python and picking those out (and handling non-existent rows).

Has Postgres's behaviour for ORDER BY RANDOM change sometime recently?

Cheers,
Victor

В списке pgsql-general по дате отправления:

Предыдущее
От: Sergey Konoplev
Дата:
Сообщение: Re: Pl/Python runtime overhead
Следующее
От: Sergey Konoplev
Дата:
Сообщение: Re: Self referencing composite datatype