Re: Performance of mnesia:select/2
Dan Gudmundsson <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CANX4uuM02cigXUH=AtJDWJkBsG00fkFXfo8TVMPX12+3bcK-GQ@mail.gmail.com> |
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 <[email protected]> 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 >