time for deleting records from mnesia

Ulf Wiger (AL/EAB) <>
Tue May 9 09:57:35 CEST 2006


When deleting 100000 records inside one transaction,
mnesia has to check the transaction store for each
delete.

Just to separate what is overhead from transaction-
protected delete and what is storage overhead,
try doing the same thing with dirty access.

Hint: If you use mnesia:activity(Type, F) instead
of mnesia:transaction(F), you only need to change
Type from 'transaction' to e.g. 'async_dirty'. The
funs you've written will work in either case.

BR,
Ulf W

> -----Original Message-----
> From:  
> [mailto:] On Behalf Of Tony Zheng
> Sent: den 9 maj 2006 02:52
> To: 
> Subject: time for deleting records from mnesia
> 
> 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