Max
Max

Reputation: 2343

Sort entities in query by reverse order of creation w/o timestamp. GAE/J

We use GAE w Java and JDO 2.3. Is there way to sort entities of JDO query in reverse of creation order? I think that if we will use index columns instead of timestamp it will increase performance. Is it right?

Upvotes: 0

Views: 539

Answers (2)

proppy
proppy

Reputation: 10504

You can't rely on ids to be continuously allocated by the datastore service.

But you can either set a timestamp as part of your keyname, or allocate a continuous id range using DatastoreService.allocateIds, to ensure your keys monotonically increasing.

You should then be able to sort the entities key using KEY_RESERVED_PROPERTY.

Compared to an indexed timestamp property, you would would save the additional index lookup if you are querying the full entities, but it would make no different for key only queries.

Note that a descending sort order will require an additional index as described in the App Engine JDO Query documentation

Also beware of hot tablet issues if you have a high write-throughput of entities with monotonically keys or indexes.

Upvotes: 1

Rick Mangi
Rick Mangi

Reputation: 3769

If you're doing a query and sorting on a single timestamp column appengine will create an index for you and the query will be very fast.

Upvotes: 1

Related Questions