Reputation: 4429
Assume I have the following entity kind:
class ExampleModel(db.Model):
name = db.StringProperty()
mdl = ExampleModel(key_name='blah', name='abcd')
mdl.put()
Is there any performance difference between
ExampleModel.get_by_key_name('blah')
and
ExampleModel.all().filter('name = ', 'abcd').get()
If there's a performance difference, how much is it (roughly)? How does ExampleModel
having an index for name
influence the result?
Upvotes: 3
Views: 74
Reputation: 10504
Yes, there is a performance (and price) difference.
In the query case you need to do 2 read operations:
In the get_by_key case you only do 1 read operation:
Also note that indexed property also affect write performance and cost, as you need to do 1 additional write in the index table for reach indexed propery.
Feel free to take a look at this presentation about Datastore performance patterns and anti-patterns. By clicking the Run
button on each side you can see the interactive appstats traces for each code snippets.
Upvotes: 6