﻿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
12021	.any() method on QuerySet using a known trick	Vlada Macek	nobody	"While inspecting the Django code, I found this trick:
{{{
#!python
# This cute trick with extra/values is the most efficient way to   
# tell if a particular query returns any results.                  
if qs.extra(select={'a': 1}).values('a').order_by():
}}}
It apparently turns off the ordering as well as retrieving and parsing any real value from the db, resulting in something very cheap like:
{{{
#!sql
SELECT (1) AS ""a"" FROM <table> WHERE <previous-qs-filtering>
}}}

Which is what we wanted to get the any/none info.

I think many of us frequently need this, but build unnecessarily complex constructs, while this can easily make it to a new QuerySet method called, say, .any().
"		closed	Database layer (models, ORM)			duplicate		t.django@…	Unreviewed	0	0	0	0	0	0
