[erlang-questions] How performant is ets:select ?

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sun Jul 5 20:11:03 CEST 2015


On Sat, Jul 4, 2015 at 10:56 AM, Benoit Chesneau <bchesneau@REDACTED>
wrote:

> Also how does it works internally, the doc let me think it is traversing
> all the keys but not sure about it.


IIRC select makes the optimizations it can. If the key is present in the
selection it can narrow the amount of work it has to do by a lookup on the
key. If, on the other hand, the key is not present, then it has to scan the
full table. Jachym notes the special case on ordered_set tables: If the key
is a composite tuple, and you are searching a prefix of that tuple, then
the system can use the ordering to narrow down the keys to search. For
example, searching for a key {8, '_'} on an ordered_set only has to look at
the range {8, X} for all X, and this is a O(lg n) operation to find the
bound and then a linear scan over the ordered set.

select that has to do a full table scan are best limited to small'ish
tables (for some notion of small mostly defined by your memory bandwidth)
or rarely executed work that can run in the background.


-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150705/d39038e6/attachment.htm>


More information about the erlang-questions mailing list