views:

78

answers:

1

I'm using the low-level google datastore api and I want to query by the key property and another property (let's call it category).

I need to query based on a list of keys for which I'll use the IN operator. I know that the max. number of values you can provide for the IN clause is 30.

I have 2 questions:

  1. Does the limit of 30 IN values apply to the key property as well?
  2. Do I need to create a composite index on {_key_ + category} or just on {category} for this query?

Thanks, Keyur

A: 
  1. No, the limit is only on the IN values.
  2. No, you won't need an index.

If you can avoid doing IN queries, though, do so - an IN query is internally evaluated as multiple equality queries, one per element in the IN.

Nick Johnson
Thanks, Nick. Other than IN is there another way for me to filter on a set of keys? The DatastoreService.get(keys) returns me all entities corresponding to the keys but doesn't let me apply another filter on them.
Keyur
Retrieve all the keys in your list, then filter manually. It'll still be substantially faster than doing one query per entity!
Nick Johnson