[erlang-questions] Mnesia index foldl

datacompboy datacompboy@REDACTED
Sat May 26 07:51:32 CEST 2007


Is there any way to foldl() on index value?
I have in database some log, indexed on date (records have date and time fields, index on date only).
I need to select all on date, filter result on some other field, and calculate sum of 3rd field. f.e., standard statistic are:
stat(Date, Types) ->
  TypeFilter = fun(#stats{type=X})->ordsets:is_element(X, Types) end,
  CalcStat = fun(#stats{count=X}, S)->S+X  end,
  Log = mnesia:index_read(statlog, Date, #stats.date),
  TypeLog = lists:filter(TypeFilter, Log),
  Stat = lists:foldl(CalcStat, 0, TypeLog).
So it load into memory all log (up to 10k records) while they needs only for filtering and sum.

So, is there way to foldl() on index, without reading whole key records?
--
--- suicide proc near\n call death\n suicide endp
_________________________________________________________
Post sent from http://www.trapexit.org



More information about the erlang-questions mailing list