ETS ordered_set and effective pagination

757 views Asked by At

I keep {Key, Value} data in ETS ordered_set where Key is a datetime. It is pretty easy to select all items in the given time internal [From, To].

Something like that:

ets:select(Tab, [{{'$1', '$2'}, [{'>=', '$1', From}, {'=<', '$1', To}], ['$2']}])

We have Limit parameter in select() function so we are able to limit a number of items to be selected. But how can I specify an offset?

As an input, my module receives time interval and page number. My goal is to return items for the specified time interval and page. Page size (Limit) is a constant. I can calculate an offset as

Offset = Limit * PageNumber - Limit

The question is how can I effectively select items for the given page only?

I know that select() function can receive Continuation parameter, but I have no state from the previous selection. I only have a page number.

Possible, I have to use other data structure. Please, recommend better solution.

1

There are 1 answers

3
Hynek -Pichi- Vychodil On

Even your first select is not effective because ets matching is not smart enough. Follow this discussion.