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