Reputation: 14279
I have a Message table with range key CreationDate...
How would I Query to an arbitrary page? Is this possible without having to supply LastEvaluatedKey returned by the previous query? That means the client has to also track this and return it with each request. And this does not allow you to jump to an arbitray page without making every intermediate query.
Would I have to update yet another table MessagePageKeys that just contains PageKey = someTimestamp to achieve fast page retreival?
QueryRequest queryReq = new QueryRequest();
queryReq.WithTableName(tableName);
queryReq.WithLimit(perPage);
var startIndex = startPage * perPage;
queryReq.WithExclusiveStartKey(new Key
{
HashKeyElement = new AttributeValue().WithN(hashKeyValue),
RangeKeyElement = new AttributeValue().WithN(prevKey.ToString() )
});
// sort by newest (highest time signature)
queryReq.ScanIndexForward = false;
Upvotes: 4
Views: 2108
Reputation: 7304
No, it's not possible without using the "lastEvaluatedKey".
It may be of use to you that the last evaluated key doesn't have to exist, it only has to be a valid key. For example, if you had the following range keys under the same hash key:
6
9
12
15
And you wanted everything with a range key greater than 10, you could create an exclusiveStartKey with range key 10
, and you would get back
12
15
This combined with a more useful definition of "page boundary" (like I want to see every item from this hour, or this minute, etc) might be of use to you. I feel like it's rare that a data consumer would ever know "my result is on the eighth page, regardless of how other data has changed since I last queried this table".
Upvotes: 1