time for deleting records from mnesia

Martin Bjorklund <>
Tue May 9 22:16:54 CEST 2006


Hi,

You might want to try to add a

   mnesia:lock({table, t_test}, write)

first in your fun.

I.e. grab a single lock in the entire table instead of a lock on each
item.  (hi klacke!)

Not sure how much of the overhead is there though...



/martin




Tony Zheng <> wrote:
> Hi
> 
> I want to delete some selected records from my mnesia database
> table(t_test). I tried to use mnesia:delete_object(Record) and
> mnesia:delete({Tab, Key}), but both of them needed about 20 minutes when
> I deleted 100000 records. I want to know if there are some other method
> to do it faster? Thanks.
> 
> 1. use mnesia:delete_object(Record) to delete 100000 records, it spent
> 22 minutes.
> 
>    F = fun() ->		
> 	MatchHead = #t_test{transaction_time='$1', _='_'},
> 	GuardDel = {'==', {element, 1, '$1'}, {date()}}, 
> 	Result = '$_',
> 	ListsDel = mnesia:select(t_test,[{MatchHead, [GuardDel], [Result]}]),
> 	lists:foreach(fun(List) -> mnesia:delete_object(List) end, ListsDel)
>    end,
>    mnesia:transaction(F).
> 
> 2. use mnesia:delete({Tab, Key}) to delete 100000 records, it spent 23
> minutes.
>  
>    F = fun() ->		
> 	MatchHead = #t_test{transaction_time='$1', _='_'},
> 	GuardDel = {'==', {element, 1, '$1'}, {date()}}, 
> 	Result = '$_',
> 	ListsDel = mnesia:select(t_test,[{MatchHead, [GuardDel], [Result]}]),
> 	lists:foreach(fun(List) -> mnesia:delete({t_test, element(2, List)})
> end, ListsDel)
>    end,
>    mnesia:transaction(F).
> 
> 
> tony
> 



More information about the erlang-questions mailing list