Is ETS table of type ordered_set able to do efficient range search with match spec?

For example, suppose an ETS table of type ordered_set with key is timestamp, using
ets:select(Ets, ets:fun2ms(fun({Timestamp,Value} = Term) when Timestamp > Time1, Timestamp < Time2 -> Term end).
Is ETS smart enough to know that it is doing a range search then it just uses binary search to just compare the limited set of items, or does it need to scan the whole table and compare all items?

2 Likes

ETS is not smart enough to utilize guards like Timestamp > Time1 to limit the search space. It will only utilize fully bound keys and partially bound keys in the head of the match spec as described at the bottom of this section:
https://www.erlang.org/doc/man/ets.html#table-traversal

See also this recent forum thread:

3 Likes

This seems like a reasonable issue/request to open on the GitHub project

2 Likes

Thanks for the replies. Will open a feature request on the GitHub OTP project.

2 Likes
2 Likes