Performance of mnesia:select/2
Dan Gudmundsson
dangud@REDACTED
Fri Feb 26 11:16:18 CET 2021
Without doing measurements, I would guess the second one,
you can combine that with taking a read table_lock first in your
transaction.
On Fri, Feb 26, 2021 at 11:03 AM Vance Shipley <vances@REDACTED> wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210226/f89aa4ec/attachment.htm>
More information about the erlang-questions
mailing list