﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
5267	document that order_by('?') is a huge performance issue	GomoX <gomo@…>	Matt Boersma	"order_by('?') generates an SQL query that is horrendous from a performance point of view (the ""ORDER BY RAND() LIMIT"" type query).

Info on this:
http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/

For the current state of affairs, I think at the very least a warning should be added to http://www.djangoproject.com/documentation/db-api/#order-by-fields .
That page happily states that you can use the method for obtaining a random row, but in a real scenario that is a very bad idea, and should be avoided at all costs.

On a more useful approach, maybe extra code could be added to a model's Meta class if you plan on grabbing random rows from that particular table. This could set up needed tables/columns/constraints in order to extract a random row without such a big performance hit. If you use order_by('?') on a model with this Meta setting, the enhancement would be transparent. How and if this improvement could be implemented is open for discussion, and is probably database dependent. The page I linked above has some discussion on the topic."		closed	Database layer (models, ORM)			fixed		gomo@…	Ready for checkin	1	0	0	0	0	0
