[erlang-questions] Managing the order of rows in mnesia

jm jeffm@REDACTED
Wed Apr 1 08:57:30 CEST 2009

What is a good way to track the order of rows in a mnesia database? What 
I have is a set of records which need to be processed in a set order as 
these define a set of rules to be obeyed. It's an ACL. Further, rules 
may be inserted or delete. I've thought of having an order field which 
is an integer, but this causes problems with guessing a good integer 
value. This lead to the idea of have parent and child pointers which 
would be easier to mantain. Is there a better that I've missed?

Also, along the same lines is there an efficient search algorithm which 
doesn't involve visting every row until a match is found or the end of 
the table is reached?

To make it a little more concrete this is roughly what I'm thinking,

-define(entry, {
                        id,             %% unique identifier
                        parent,      %% id of parent row
                        child,        %% id of child row
                        a,              %% first field to be matched against
                        b,              %% second field to be matched 
                        action       %% action to be returned

Example table ('*' denotes wildcard, using integers where ref() values 
would be used in id, parent, and child columns)
   id parent  child        a          b               action
   15    top      1         denise   '*'               deny
    1     15       2         alice      car              allow
    2     1         5         alice      motorbike   deny
    5     2       11         bob       car               deny
   11    5         6          '*'         car              allow
     6   11   bottom      '*'         motorbike   allow

example searches and results

     {alice, car}             -> allow
     {carol, car}             -> allow
     {alice, motorbike}  -> deny
     {carol, motorbike} -> allow
     {carol, yacht}         -> undefined
     {denise, car}          -> deny



More information about the erlang-questions mailing list