mnesia query

Sebastian Bello <>
Thu Jul 14 18:05:58 CEST 2005


We are using select. Ok, I'll check for that. Three more questions (please
tell me if they have already been aswered in the list):

1- what are the options to get the result ordered by the key (in this
particular case)?
2- is it possible to perform a query using two indexes?
3- is there a guide from where to read about performance issues in mnesia?

Thanks you for your complete response.
    Sebastian-

----- Original Message -----
From: "Ulf Wiger" <>
To: <>
Sent: Thursday, July 14, 2005 12:14 PM
Subject: Re: mnesia query


> Den 2005-07-14 15:49:53 skrev Sebastian Bello <>:
>
> > Hi all,
> >
> > imagine I have a query which returns a very big number of records, but
> > am interested in just a fixed small number of them. Is there a way to
> > retrieve, let's say, just the first N or just N of them? Not doing, ie
> > getting the whole result, implies a performance penalty other than
> > memory consumption?
>
> What type of query is it? Mnemosyne? QLC? or is it just select()?
> With select(), you can add an argument, Limit, that makes the function
> break out, and return the objects found so far, together with a
> continuation. This works for ets and mnesia, even though with mnesia,
> I think you also have to specify a bunch of other arguments.
>
> With QLC and Mnemosyne, you can use cursors. Read the appropriate
> manual to figure out how they work.
>
> In the Mnemosyne user guide, you can find the following example:
>
> "Use the cursor with a query evaluation to produce a few solutions only.
> With a handle we create a cursor by calling mnemosyne:cursor/1. With the
> cursor we can repeatedly call mnemosyne:next_answers to get more
solutions.
> When an empty list is returned there are no more possible solutions.
Delete
> the cursor with mnemosyne:delete_cursor/1.
>
>      Handle =
>          query
>             [ S.snb || S <- table(subscriber),
>                        S.li = none]
>          end,
>
>      AFewAnswers =
>          mnesia:transaction(
>               fun() ->
>                       Cursor = mnemosyne:cursor(Handle),
>                       % now get at least two but not
>                       % more than five solutions:
>                       L = mnemosyne:next_answers(Cursor,2,5),
>                       mnemosyne:delete_cursor(Cursor),
>                       L
>               end)"
>
>
>
> /Uffe
>
>





More information about the erlang-questions mailing list