Sort Orders Are Ignored on Multi-ValuedProperties?

15 views
Skip to first unread message

Waleed Abdulla

unread,
Jun 22, 2012, 9:03:11 PM6/22/12
to google-appengine
I have a model with a multi-valued property, "events", and I want to filter by a specific range of events and sort by them at the same time:

class MyModel(db.Model):
  events = db.StringListProperty(indexed=True)

print MyModel.all().filter("events >=", x).filter("events <=", y).order("events").fetch(100)


    I expect the results to be sorted by whichever value in the list property that matched the range condition (and that's how I understand the indexs to be organized). This seems to be working as expected in the SDK, and if I reverse the order ("-events") it returns the results in reverse as well, which is great. 

However, I'm concerned about the section below from the documentation which states that sort orders are ignored. It's not clear to me, though, if the sort order is ignored completely or ignored only for the "other" values in the property list that did not match the range condition. And if it is ignored, then how come reversing the sort oder in the code above also reversed the order of the results I get?

Sort Orders Are Ignored on Properties with Equality Filters

One important caveat is queries with both an equality filter and a sort order on a multi-valued property. In those queries, the sort order is disregarded. For single-valued properties, this is a simple optimization. Every result would have the same value for the property, so the results do not need to be sorted further.

However, multi-valued properties may have additional values. Since the sort order is disregarded, the query results may be returned in a different order than if the sort order were applied. (Restoring the dropped sort order would be expensive and require extra indices, and this use case is rare, so the query planner leaves it off.)


Michael Hermus

unread,
Jun 25, 2012, 4:53:12 PM6/25/12
to google-a...@googlegroups.com
I have not tried this myself, but the documentation states that sort orders are ignored if you use an Equality filter and a sort order; you are using inequality filters and a sort order.
Reply all
Reply to author
Forward
0 new messages