Mnesia data partitioning question
Chris Pressey
cpressey@REDACTED
Tue Apr 16 23:42:43 CEST 2002
Although I don't really expect a concrete answer to this one, I thought it
might be interesting to share opinions on the subject...
Mnesia lacks the concept of a 'secondary key' - that is, using more than one
field to uniquely identify a record. So, is it, generally speaking, wiser
to model a many-to-many relationship in Mnesia as:
- a 'set' table with a compound key, or
- a 'bag' table with an index on a second field?
Perhaps I should give some background. I am currently using Erlang outside
of telecom - in a retail setting - for an order-tracking application. I
chose Erlang partly because the problem is inherently distributed and soft
real-time - users in different physical locations want immediate updates on
the status of orders. Erlang makes this easy - the shipping department
manages a database, and all the other nodes simply subscribe to Mnesia
events, and update their displays accordingly.
Orders go out in shipments. If orders are small, more than one order may be
placed in the same shipment. If an order is large, it may be split across
more than one shipment. So there is a many-many relationship between
shipments and orders, and the key in the main table is order_id+shipment_id.
I've currently implemented this as a compound key, i.e. a 'set' table where
the key is a tuple {order_id, shipment_id}. Unfortunately, I need indexes
on the order_id and shipment_id fields individually, for other purposes, so
they are repeated in the record - wasting space.
I see that I could be using a 'bag' table instead, and this would save me
space in the database, as I would not need to repeat the indexed fields.
However, space is not a crucial issue (there will probably be at the very
most 1000 records in the database at any given time, and each record is
fairly small), and the drawback with the bag seems to be that it does not
ensure that order_id+shipment_id is unique for any given record. There
could be two records with the same order_id and the same shipment_id.
I honestly doubt that either way to do it would be a 'mistake', but I would
be interested to hear if anyone wanted to share similar experiences in
Mnesia table design.
Thanks!
Chris
More information about the erlang-questions
mailing list