Mnesia Speed Optimization

Hakan Mattsson hakan@REDACTED
Mon Jan 19 15:58:05 CET 2004

On Fri, 16 Jan 2004, Younès HAFRI wrote:

Younès> I have a great optimization problem with Mnesia.
Younès> My database is not replicated and its works in the local node.

If the storage type is ram_copies you could try this:

  do_insert_if_not_exists(ListOfRecords) ->
   lists:foreach(fun(Record) ->
			 case mnesia:read({table_index, Record}) of
			     [] ->  
			       mnesia:write(#table_index{field1= Record});
			     [Exists] -> 
		 end, ListOfRecords).

  insert_if_not_exists(ListOfRecords) ->
    ram_copies = mnesia:table_info(table_index, storage_type), % Assert
    mnesia:ets(fun do_insert_if_not_exists/1, [ListOfRecords]).


Håkan Mattsson
High Availability Software, DBMS Internals

More information about the erlang-questions mailing list