Performance of mnesia:select/2
Vance Shipley
vances@REDACTED
Fri Feb 26 11:03:39 CET 2021
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
More information about the erlang-questions
mailing list