0
votes

How many indexes are created for entity with 50 indexed properties when only single property queries are executed in GAE NDB Python. There are no repeated properties

class X(ndb.Model): 
    p1 = ndb.KeyProperty(indexed=False) 

    p2 = ndb.StringProperty(indexed=True) 
    p3 = ndb.StringProperty(indexed=True) 
    :: 
    p51 = ndb.StringProperty(indexed=True) 

my query structure(all queries would be only single property queries without AND, OR, IN):

q = X.query(X.pn==data)  # pn could be p2, p3, .., p51 
record_list, next_curs, more = q.fetch_page(15)  

How many indexes would be needed for such queries(it would be great if you show the calculation step too)

Would all these indexes be autogenerated

Would it be a better idea to put these indexes myself in the index.yaml file

I would have 75,000,000 (75 million) entities of the above model. Does the number of entities affect the total number of indexes for a model

Would I hit the default limit on indexes or composite indexes(if any composite index would be needed for above entity or query)

Would there be any change in the above answers if i add sort order based on one of three properties(say, p2 or p3 or p4)

I have referred the following link but could not understand it properly
https://developers.google.com/appengine/articles/indexselection

1
If you run your queries in dev appserver it should put them in the index.yaml automatically, so you can see what its automatically done and adjust if required. - Paul Collingwood
@PaulCollingwood Thanks for your suggestion.. I am yet to decide the database design and have not yet coded it.. but i would go ahead and try this out.. i was apprehensive to check it that way since my local development server did not generate any indexes when i tried with a subset of the above model with 10k entities.. - gsinha
If you ran no queries then, iirc, no indexes would be generated. - Paul Collingwood
@PaulCollingwood i ran fetch_page(15) queries with multiple conditions in AND, OR, IN combination for a matching result set of ~6k.. i also ran count.. - gsinha
It notes it only generates indexes where required. - Paul Collingwood

1 Answers

2
votes

You will have 51 indexes: one for an entity kind and one for each indexed property. These indexes are generated automatically.

If you need to create queries on multiple properties, you will need additional custom indexes.

The number of indexes does not depend on the number of entities.

At 75m entities you will need a lot of storage space. Also, your writing costs will be very high as every change to an entity will trigger updates in all indexes.

I can hardly imagine a use case for an entity with 50 indexed properties.