Creos
Creos

Reputation: 2525

Does supplying an ancestor improve filter queries performance in objectify / google cloud datastore?

I was wondering which of these two is superior in terms of performance (and perhaps cost?):

1) ofy().load().type(A.class).ancestor(parentKey).filter("foo", bar).list()

2) ofy().load().type(A.class) .filter("foo", bar).list()

Logically, I would assume (1) will perform better as it restricts the domain on which to perform the filtering (though obviously there's an index). However, I was wondering if I may be missing some consideration/factor.

Thank you.

Upvotes: 0

Views: 926

Answers (1)

Ed Davisson
Ed Davisson

Reputation: 2927

Including an ancestor should not significantly affect query performance (and as you note, each option requires a different index).

The more important consideration when deciding to use ancestor queries is whether you require strongly consistent query results. If you do, you'll need to group your entities into entity groups and use an ancestor query (#1 in your example).

The trade-off of grouping entities into entity groups is that each entity group only supports 1 write per second.

You can find a more detailed discussion of structuring data for strong consistency here: https://developers.google.com/datastore/docs/concepts/structuring_for_strong_consistency

Upvotes: 1

Related Questions