[erlang-questions] More Mnesia Questions

Bill Robertson <>
Thu May 8 04:52:25 CEST 2008

Thanks to all for the help on creating tables.  I like the {atomic, ok} = mnesia:create_table() badmatch idiom, and I have rewritten other parts of the code I'm working on to take advantage of that.

I have a couple more questions though.  (always...)  If any of them are already answered in documentation, please point me to what I obviously missed.

1.  I think the answer is no, but is it possible to define a constraint in mnesia?  for example a foreign key constraint?  

Maybe you could define a fun() and pass that to mnesia for it to store for a table and mnesia would check the return value of that fun before allowing the modification to the table occur?  I see some notion of events in the ref manual (http://www.erlang.org/doc/man/mnesia.html).  Would it be possible to roll that into mnesia myself?

2.  I want to track the selection frequency of terms, and then frequently retrieve the N most popular terms.  In a relational database, I would just create an index in descending order and use an appropriate order by clause.  I don't see any options to do that with an mnesia index though.  Would qlc be smart enough to figure it out walk the index backwards?  How would you even do that in qlc?

3.  If I want "building block" functions to do primitive operations in mnesia, I think it would be necessary to have these functions return funs, and then collect all of the funs in a larger fun that would define larger behaviors and then execute the entire thing in a single call to transaction.  Is there a way to start a transactions, call arbitrary mnesia functions, and then either commit or rollback the transaction?  It does not appear this would work from what I see in the api.

4.  Is it possible for mnesia to have a disk table that only has a subset of its contents in memory? (without work on my part of course)


And, in the event that I decide I'm spending too much time spinning my wheels...  I hear there is a native erlang mysql driver.  Where is it?  

Is it the project on google code?  (http://code.google.com/p/erlang-mysql-driver/)  Is there a shred of documentation for it?

Thanks again

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

More information about the erlang-questions mailing list