[erlang-questions] Get a range of tuples from a Mnesia table

Edwin Fine erlang-questions_efine@REDACTED
Sat Oct 4 20:11:06 CEST 2008


Looking through the docs, I see that if you are using an mnesia table that
is ram_copies or disc_copies, you can do certain fast operations on the
associated ets table. One such operation (which is recommended only for
debugging, but what the heck) is ets:slot(Tab, I), which returns the I'th
record in the table. So maybe you could find a way to do that on the ETS
table that Mnesia is using, perhaps via the mnesia:ets() function. I have
never tried this so it's just a guess. This is also kind of a hack but other
than reading through the mnesia code, I can't locate something better. Maybe
one of the real Mnesia gurus will have an idea.

2008/10/4 Greg Burri <greg.burri@REDACTED>

> Hi,
> I want to retrieve N tuple with an offset O from the end of a table. N and
> O are integer(). I consider that the acces is based on an ordered table.
>
> Here is an example, I have such tuples in my table t :
> [{t, 1, _},
> {t, 2, _},
> {t, 3, _},
> {t, 4, _},
> {t, 5, _},
> {t, 6, _},
> {t, 7, _}]
>
> For N=2 and O=3 the result will be :
> [{t, 4, _}, {t, 5, _}]
>
> For now I have to use an ordered_set table and the functions mnesia:last/1
> and mnesia:prev/2, it works but the complexity is O(O). If I have to get
> some tuple from the middle of the table it will take long time.
> Is there an another solution than mine ?
>
> Second question : How change the type of a table from set to ordered_set on
> an existing table ?
>
>
> /Greg Burri
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081004/a2444932/attachment.htm>


More information about the erlang-questions mailing list