[erlang-questions] Re: Some tips on Mnesia

Igor Ribeiro Sucupira igorrs@REDACTED
Mon May 24 20:49:55 CEST 2010


On Mon, May 24, 2010 at 1:45 AM, Rapsey <rapsey@REDACTED> wrote:
> About that key value approach. My solution is a bit different. Let's say I
> have a database of nodes and store a list of IP addresses to them. I save
> them like so:
> {node,{address,NodeName}}, {IP,Port}

I assume you meant {node, {address,NodeName}, {IP,Port}}, so that the
key would be {address, NodeName}. Is that correct?

The problem I was addressing was "adding a field in a flexible
manner". With your solution, you would, for example, add a "status"
field by inserting new keys like {status, NodeName}, with values that
could be "active", "down" or whatever. Is that the idea?

I'm just not sure you can efficiently retrieve all the information
about a node. Won't the query for this key {'_',NodeName} perform a
full table scan?
Even if that query was very smart (or you knew in advance what fields
you need), it would still need to retrieve several keys, which could
even be in different nodes (in the case of a fragmented table).
Certainly slower than reading one, longer record (as is the case with
a "key-value" table).

So, in short, compared to the "key-value" approach, your solution
favors retrieving a single field (only slightly, if the records are
smaller than a block/page), but turns it slower to retrieve all the
fields of an entity.

Best regards.
Igor.

> This way I can query for that exact information mnesia:(dirty_)read, or I
> can get a list of all node addresses with mnesia:select -
> {node,{address,'_'}}, or get a list of all node information with {node,'_'},
> or get all info about a node {node,{'_',NodeName}}.
>
>
> Sergej
>
> On Sun, May 23, 2010 at 10:46 PM, Igor Ribeiro Sucupira <igorrs@REDACTED>wrote:
>
>> Second and third posts:
>> http://igorrs.blogspot.com/2010/05/mnesia-one-year-later-part-2.html
>> http://igorrs.blogspot.com/2010/05/mnesia-one-year-later-part-3.html
>>
>> On Thu, May 20, 2010 at 12:53 PM, Igor Ribeiro Sucupira
>> <igorrs@REDACTED> wrote:
>> > For those people who are starting to work with Mnesia, I'm writing a
>> > short sequence of blog posts that are intended to point out some
>> > relevant facts that don't seem to be well-known and could hurt you in
>> > the beginning.
>> >
>> > I'll try to focus on the information that you can't google.  ;-)  But
>> > maybe in the end I'll also summarize the important tips that I learned
>> > from other blogs.
>> >
>> > Here is the first post:
>> > http://igorrs.blogspot.com/2010/05/mnesia-one-year-later.html
>> >
>> > Good luck.
>> > Igor.
>> >
>> > --
>> > "The secret of joy in work is contained in one word - excellence. To
>> > know how to do something well is to enjoy it." - Pearl S. Buck.
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>
>>
>



-- 
"The secret of joy in work is contained in one word - excellence. To
know how to do something well is to enjoy it." - Pearl S. Buck.


More information about the erlang-questions mailing list