Search Postgresql Archives

Performance of ORDER BY RANDOM to select random rows?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

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

According to the Django documentation:

https://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by

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:

http://www.peterbe.com/plog/getting-random-rows-postgresql-django

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux