<div dir="ltr"><div><div><div><div><div>Consider a key-value store. You might have records<br><br></div><font face="monospace,monospace">-record(kv, {key, val}).<br><br></font></div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif">which would be stored as 3-tuples<br><br></font></font></div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace">{kv, Key, Val}<br><br></font></font></font></div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif">in a mnesia table<font face="monospace,monospace"><font face="arial,helvetica,sans-serif"> kv. A call</font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><br></font></font></font></font></font></font></div><div><span style="font-family:monospace,monospace">mnesia:match_object({kv, 42, '_'})<br></span></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><br></font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif">has a pattern where the key position is bound to an actual value (42) but the value position is unbound ('_' is the wildcard which matches anything). This call would then find all records in the kv table having key 42. On the other hand, a call</font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><br></font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace">mnesia:match_object({kv, '_', foo})</font></font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><br></font></font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif">has a pattern where the key position is unbound but the value position is bound to the value foo. This call would then find all records in the kv table having value foo.</font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><br></font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif">The significance of the key is that it's the _index_ for the table, meaning that any access to the table that supplies the key can quickly locate where the relevant records are stored. Accesses that do not supply the key generally have to enumerate all records and inspect them to see which ones match the pattern. This means that accesses with a key are much quicker than those without.</font></font></font></font></font></font></div><div><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><font face="monospace,monospace"><font face="arial,helvetica,sans-serif"><br></font></font></font></font></font></font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 31, 2017 at 10:48 PM, Karlo Kuna <span dir="ltr"><<a href="mailto:kuna.prime@gmail.com" target="_blank">kuna.prime@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">i still don't fully grasp the concept. short example would be greatly appreciated.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 31, 2017 at 8:15 PM, Mikael Pettersson <span dir="ltr"><<a href="mailto:mikpelinux@gmail.com" target="_blank">mikpelinux@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Presumably you're referring to mnesia:match_object/1 or /3. It means that the key position of the pattern is a ground value and not a variable.<br></div><div class="gmail_extra"><br><div class="gmail_quote"><span>On Tue, Oct 31, 2017 at 7:24 PM, Karlo Kuna <span dir="ltr"><<a href="mailto:kuna.prime@gmail.com" target="_blank">kuna.prime@gmail.com</a>></span> wrote:<br></span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div dir="ltr">i was wondering what exactly "key is bound" means in context of mnesia</div>
<br></span>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</blockquote></div><br></div>