In Google App Engine I have a model with 10K entities with an index on the property foo. What is the most efficient way to find the 1st quartile, 2nd quartile (the median), and the 3rd quartile entities? I can fetch the sorted list of keys and find the three quartile keys programmatically, but downloading all the keys won't scale. What is the more elegant approach?
sortedValues = MyModel.all(keys_only=True).order('foo').fetch(limit=10000)
Have you tried .fetch(2500,limit=1)
, .fetch(5000,limit=1)
, and .fetch(7500,limit=1)
? The first argument corresponds to the offset.
The documentation reads the following, however, so this approach won't afford you O(1)
performance.
Note: The query has performance characteristics that correspond linearly with the offset amount plus the limit amount.
From here.