[erlang-questions] Looking for some advice on mnesia with multi-column indexes
Dave Challis
dsc@REDACTED
Tue Apr 26 14:31:05 CEST 2011
I'm wondering what's the best way (or at least what some of the
considerations are) when dealing with indexes across multiple fields of
a table.
Assuming I've got a record to store in mnesia, which looks something like:
-record(foo, {id, a, b}).
which might contain:
#foo{id=1, a="A", b="B"}.
I can create an index on the 'a' or 'b' fields when I create an mnesia
table, but what about creating an index on the two combined?
I could create a new record/table structure which looks like:
-record(foo, {id, a, b, a_and_b}).
which might contain:
#foo{id=1, a="A", b="B", a_and_b={"A", "B"}}.
Or, I could create an additional table to hold the indexes:
-record(foo_ab_index, {a_and_b, id}).
containing:
#foo_ab_index{a_and_b={"A", "B"}, id=1}.
Or is there some other pattern/practice I should be looking at instead?
It feels wrong to store the same value in multiple places (especially
if 'a' or 'b' contain large chunks of data), but that could just be my
SQL background kicking in.
Cheers,
--
Dave Challis
dsc@REDACTED
More information about the erlang-questions
mailing list