[erlang-questions] mnesia and lazy loading?

Armando Di Cianno armando.dicianno@REDACTED
Tue Nov 30 15:10:06 CET 2010


2010/11/30 Håkan Mattsson <hm@REDACTED>:
> On Tue, Nov 30, 2010 at 1:18 PM, Andy Kriger <andy.kriger@REDACTED> wrote:
>> In SQL, it's possible to request specific fields on a table.
>> Is it possible to do something similar in mnesia?
>
> No, not if the purpose is to gain performance.
> Otherwise you can use  mnesia:select/2 or qlc.

Agreed. I would go with qlc, in this case, as the list comprehension
used makes it make more sense in my mind.

E.g. of qlc with some search constraints.

> {MegaSecs, Secs, _MicroSecs} = now().
> SecondsAtNow = MegaSecs * 1000000 + Secs.
> Q = qlc:q([{X.id, X.other_column} || X <- mnesia:table(x), (SecondsAtNow - X#x.timestamp) > 60]).
> F = fun() -> qlc:e(Q) end.
> {atomic, List} = mnesia:transaction(F),

List now contains tuples of X.id and X.other_column, where X.timestamp
is older than a minute.

__armando




>
> /Håkan
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list