mnesia power index

Ulf Wiger ulf@REDACTED
Thu Feb 17 21:14:00 CET 2005


Den 2005-02-17 19:06:22 skrev Ulf Wiger (AL/EAB) <ulf.wiger@REDACTED>:

> I thought I'd share a small hack I made to mnesia-4.2.
>
> The purpose of the hack was to make room for more
> flexible index functionality.
>
> You can now create an index in the following manner:
>
> mnesia:add_table_index(Tab, Pos :: integer() | atom());
> mnesia:add_table_index(Tab, {{Pos,Tag}, M, F, Arg, IsOrdered}).
>
>    Pos : integer() | atom()   The attribute position or name,
>                               as with old-style indexes
>    Tag : atom()               A user-friendly tag; {Pos,Tag}
>                               uniquely identifies the index
>    M   : atom()               Module name
>    F   : atom()               Function name
>    Arg : term()               Extra argument
>    IsOrdered : bool()         true means an ordered index
>
> With the new syntax, you can have several indexes on a given
> attribute. A special case is if Pos == 1. Then the index works
> on the whole object.
>
> The index callback function is called like this:
>
> M:F(Data, Arg) -> [IndexValue].


I should add a few comments:

- If you use the new index functionality, and then try to
   start an unmodified mnesia-4.2 node on the same schema,
   mnesia will dump core. Perhaps this can be handled a bit
   better.

- The index callbacks execute in the 'commit' phase, so there's
   no possibility to abort (this will cause mnesia to dump core).
   They simply have to work. Oh, and keep them side-effect free.

/Uffe



More information about the erlang-questions mailing list