Performance of mnesia:select/2

Vance Shipley vances@REDACTED
Fri Feb 26 23:46:14 CET 2021


On Fri, Feb 26, 2021 at 10:12 PM Jacob <jacob01@REDACTED> wrote:
> assuming that the match spec compiler does clever things with patterns,
> I'd use select with the following
>
>    MatchExpression = [ {{'_', K, '_'}, [], ['$_']} || K <- Keys ]

Sure, that's better, my example is simplified from my real use case
which has a more complicated fun().

> If did some quick measurements with plain ETS, timer:tc and 500 keys out
> of 1000000 table entries and got:

Thanks a bunch for doing what I should have.  I understand that
empirical test on your own environment is the last word but also
interested in the 'why?' question.  My intuition was that select could
benefit from a lower level (C) implementation while interactive reads
may involve more context switching.

>    * using pattern, [ordered_set]: 4532605 us
>    * using pattern, [set]              :  4645525 us
>    * using pattern, [ordered_set, {keypos, 2}]: 3826 us (!!!)
>    * using pattern, [set, {keypos, 2}]: 5714 us (!!!)

Yes, the point was to use the actual keys of the table.  As I
understand it {ets,mnesia}:select/? will optimize when keys or indexes
are involved.

-- 
     -Vance


More information about the erlang-questions mailing list