views:

228

answers:

1

While using django.core.paginator import ObjectPaginator, I'm getting this error:

NeedIndexError: The built-in indices are not efficient enough for this query and your data. Please add a composite index for this query.

The original query is written in this form:

query = models.Cdr.all()
query.filter("var1 =", var1 )
query.filter("var2 =", var2)
query.filter("var3 =", var3)

I get this exception when ObjectPaginator tries to count the number of elements, but only for some values of var1.

Why would this query fail for some values of var1, while working with others?

What would you recommend for this case?

+2  A: 

The general procedure recommended to fix NeedIndexError occurrences is this one. I expect the composite index may not have been built on your development depending on the amount and structure of the data (which can change depending on var1 value) but turns out to be needed (to avoid aborting the query for efficiency reasons, as the error msg hints and Nick confirms in this comment) when running on the actual store.

Alex Martelli
If the error message given occurs, it's because it's aborting early due to inefficiency, not due to the 1000 result limit.
Nick Johnson
tx Nick, editing accordingly!
Alex Martelli