[erlang-questions] mnesia and lazy loading?

3 views
Skip to first unread message

Andy Kriger

unread,
Nov 30, 2010, 7:18:43 AM11/30/10
to erlang-q...@erlang.org
In SQL, it's possible to request specific fields on a table.
Is it possible to do something similar in mnesia?
Which is to say, only return the values in certain fields of the record?
Yes or no determines a design decision on which data belongs in the
record and which data requires an secondary record associated to the
first by id.

thx

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questio...@erlang.org

Håkan Mattsson

unread,
Nov 30, 2010, 8:02:07 AM11/30/10
to an...@householder-yogi.net, erlang-q...@erlang.org
On Tue, Nov 30, 2010 at 1:18 PM, Andy Kriger <andy....@gmail.com> 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.

/Håkan

Armando Di Cianno

unread,
Nov 30, 2010, 9:10:06 AM11/30/10
to Håkan Mattsson, an...@householder-yogi.net, erlang-q...@erlang.org
2010/11/30 Håkan Mattsson <h...@tail-f.com>:

> On Tue, Nov 30, 2010 at 1:18 PM, Andy Kriger <andy....@gmail.com> 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

Reply all
Reply to author
Forward
0 new messages