I got the following situation
class M(db.Model):
a = db.ReferenceProperty(A)
x = db.ReferenceProperty(X)
y = db.ReferenceProperty(Y)
z = db.ReferenceProperty(Z)
items = db.StringListProperty()
date = db.DateTimeProperty()
I want to make queries that filter on (a), (x, y or z) and (items), ordered by date i.e.
mm = M.all().filter('a =', a1).filter('x =', x1).filter('items =', i).order('-date')
There will never be a query with filter on x and y at the same time, for example.
So, my questions are:
1) How many (and which) indexes should I create?
2) How many ‘strings’ can I add on items? (I’d like to add in the order of thousands)
3) How many index records will I have on a single “M” if there are 1000 items?
I don’t quite yet understand this index stuff, and is killing me. Your help will be very appreciated 🙂
For the criteria you have given, you only need to create three compound indexes:
a,x,items,-date,a,y,items,-date,a,z,items,-date. Note that a list property creates an index entry for each property in the list.There is a limit of total 5000 index entries per entity. If you only have three compound indexes, than it’s 5000/3 = 1666 (capped at 1000 for a single list property).
In the case of three compound indexes only, 3*1000 = 3000.
NOTE: the above assumes you do not have built-in indexes per property (= properties are save as unindexed). Otherwise you need to account for built-in indexes at 2N, where N in number of single properties (2 is for asc, desc). In your case this would be 2*(5 + no_items), since
itemsis a list property and every entry creates an index entry.