On Sep 16, 8:19 am, Blake HAN <blake...@gmail.com> wrote:
> I try to get the total row number of a table which has more than
> 1,000,000 data. I got error message "query is too large. may not have
> more than 100 filters + sort orders + ancestor total". Anyone can help
> on that?
>
> My code looks like this:
>
> def get_count(query):
>     BATCH_SIZE = 1000 # Maximum number of results returned by a query
>     query = query.order('__key__')
>     results = query.fetch(BATCH_SIZE)
>     count = len(results)
>
>     while True:
>         if not results:
>             return count
>         last_key = results[-1]
>         results = query.filter('__key__ > ', last_key).fetch
> (BATCH_SIZE)
>         count = count + len(results)
>
> count = get_count(MyModel.all(keys_only=True))

The problem is that you're taking a single query and adding new
filters to it in a loop.  You want to run multiple queries instead.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to