[erlang-questions] Mnesia: select random record

Christian S <>
Sat Sep 30 12:26:06 CEST 2006


What are you really trying to accomplish?

Maybe you could traverse the whole table for their primary keys, then
permute that list to get a sequence of records in random order?

Do you want some kind of fair scheduling? Then maybe you want to build
a scheduler that subscribes to table events so it can remove and add
records to the scheduler as the table change?

On 9/30/06, datacompboy <> wrote:
>
> Hello, all!
>
> I have asked @trapexit, but think there will wider discussion...
>
> How effective select an random record from mnesia table?
> I have table with user statuses:
> {us, id, status}.
> I have additional index on status field.
> And I need to get any random record with status=X.
>
> Any easy and fast way?
> Or only have tables for every status, and then:
> Table=list_to_atom("status"++"_"++X),
> X=mnesia:table_size(Table),
> record=mnesia_geti(Table, random:uniform(X))
> ?
>
> There about 4-5 (and may be extended to 10-12 later) of statuses, and about 1000 IDs, that query called often (about 10-30 times per second), so I can left just read on whole table, but question intersting in general.
> --
> --- suicide proc near\n call death\n suicide endp
> _________________________________________________________
> Post sent from http://www.trapexit.org
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list