time for deleting records from mnesia
Tony Zheng
tzheng@REDACTED
Tue May 9 02:52:08 CEST 2006
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