Performance of mnesia:select/2

Vance Shipley <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAMoa0NLR1gjK8ub3HDr8LMyRRqysKEwT=9rXLMtEv_xJwWJZnw@mail.gmail.com>
If I need to lookup a list of keys which is the better approach? Why?

Fselect = fun(Keys) ->
        MatchHead = {'_', '$1', '$2'},
        F = fun(Key) ->
                {'=:=', '$1', Key}
        end,
        MatchConditions = [list_to_tuple(['or' | lists:map(F, Keys)]),
        MatchBody = ['$_'],
        MatchFunction = {MatchHead, MatchConditions, MatchBody},
        MatchExpression = [MatchFunction],
        mnesia:select(Table, MatchExpression)
end,
mnesia:transaction(Fselect, [Keys]).

Fread = fun F([Key | T], Acc) ->
                [R] = mnesia:read(Table, Key),
                F(T, [R | Acc]);
        F([], Acc) ->
                lists:reverse(Acc)
end,
mnesia:transaction(Fread, [Keys. []]).


--
     -Vance
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.