[erlang-questions] Mnesia - select with placeholder in table key
Robert Virding
robert.virding@REDACTED
Thu May 30 03:40:13 CEST 2013
As I read it in this case Mnesia cannot use the index as the key contains a variable and Mnesia hashes the key for indexed lookup. So in this case Mnesia must do a scan. This is the same as for ETS.
Robert
----- Original Message -----
> From: "Evgeny M" <donpedrothird@REDACTED>
> To: erlang-programming@REDACTED
> Cc: erlang-questions@REDACTED
> Sent: Monday, 27 May, 2013 12:33:02 AM
> Subject: Re: [erlang-questions] Mnesia - select with placeholder in
> table key
> Sorry, I don't quite understand you. I'm not a native speaker, maybe
> I miss something.
> We select by primary key only. There are no secondary indexes in the
> table, and there are no filters by other fields in the query. But
> the primary key is a tuple and one of the elements of this tuple is
> wildcard, ie we have records with keys {a, x, y}, {b, x, y}, {c, x,
> y}, {a, z, z} and want to select all records that match {'$1', x,
> y}. This tuple is the key, there aresome other fields in the record.
> Will the mnesia use index in this case?
> понедельник, 27 мая 2013 г., 1:17:38 UTC+4 пользователь Ulf Wiger
> написал:
> > If the key position is unbound, mnesia will check if any indexed
> > position is bound, and if so, use the first such value for an index
> > lookup. It then uses match_spec_run() on the result.
>
> > BR,
>
> > Ulf W
>
> > Ulf Wiger, Feuerlabs, Inc.
>
> > http://www.feuerlabs.com
>
> > 26 maj 2013 kl. 22:46 skrev John Doe < donped...@REDACTED >:
>
> > > If I use select when the key is tuple with placeholders,
> > > something
> > > like this (taken from erlang docs and changed a bit):
>
> > > MatchHead = #person{name = {'$1', "K", "Jameson"}, sex = '$2', _
> > > =
> > > '_'},
>
> > > Result = '$2',
>
> > > mnesia:select(Tab,[{MatchHead, [], [Result]}])
>
> > > where name is the table key
>
> > > will mnesia do full table scan in this case? Or it will be
> > > smarter
> > > and select all records with key matching {_, "K", "Jameson"}
> > > using
> > > index somehow?
>
> > > _______________________________________________
>
> > > erlang-questions mailing list
>
> > > erlang-q...@REDACTED
>
> > > http://erlang.org/mailman/listinfo/erlang-questions
>
> > _______________________________________________
>
> > erlang-questions mailing list
>
> > erlang-q...@REDACTED
>
> > http://erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130530/f556e929/attachment.htm>
More information about the erlang-questions
mailing list