Appengine: NeedIndexError: Built-in indexes are not efficient enough for this query and your data. Add a combined index for this query.

When using django.core.paginator imports ObjectPaginator, I get this error:

NeedIndexError: Built-in indexes are not efficient enough for this query and your data. Add a composite index for this query.

The original request is written in this form:

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

      

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

Why does this query fail with some var1 values ​​when working with others?

What do you recommend for this case?

+2


source to share


2 answers


The general procedure recommended for correcting an occurrence NeedIndexError

is this . I expect that 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 the value var1

), but turns out to be necessary (to avoid interrupting the query for efficiency reasons, as hints from msg and Nick confirm in this comment) when run in live repository.



+2


source


I faced this problem. The problem isn't with your code, but with the GAE indexing system itself. To fix this, you must explicitly write the index to your index.yaml file. This worked for me, but I read elsewhere that explicitly defining your index may not always fix it. Regardless, I recommend that you show the error that I opened .



GAE does not automatically create an index for queries that only have equality filters. Instead, it uses an algorithm that Google calls the "zigzag merge join" (Google it). It looks like this algorithm breaks down in certain situations. It looks like the google team is working on fixing this issue, but it still appears in some situations.

+1


source







All Articles