mnesia table: mnemosyne query

Hakan Mattsson hakan@REDACTED
Thu Oct 28 10:56:20 CEST 1999


On Thu, 28 Oct 1999, Ulf Wiger wrote:

Uffe> You can try writing like this for now:
Uffe> 
Uffe> essai() ->
Uffe>    {atomic, Objs} =
Uffe>       mnesia:transaction(
Uffe>          fun() ->
Uffe>             mnesia:match_object(ecole, '_')
Uffe>          end),
Uffe>    [D#domaine.id || D <- Objs, D#domain.nom == 4].
Uffe> 
Uffe> For simple queries, this is just as efficient as mnemosyne.

In fact it is more efficient to avoid Mnemosyne...

Instead of first performing a copy of all records from ets to your
process heap (potentially on another node than the ets table), it is
better to let ets do the selection of which records that matches the
constraint (D#domain.nom == 4). It can be done like this:

essai() ->
  Tab = ecole,
  Pat = mnesia:table_info(Tab,wild_pattern),
  Fun = fun() -> mnesia:match_object(Tab, Pat#domaine{nom = 4}) end,
  {atomic, Domains} = mnesia:transaction(Fun),
  [D#domaine.ip || D <- Domains].

The mnesia:transaction/1 call may be replaced with a call to
mnesia:sync_dirty/1 or mnesia:ets/1 if you want it more efficient.
  
/Håkan







More information about the erlang-questions mailing list