[erlang-questions] Mnesia - select with placeholder in table key

Ulf Wiger ulf@REDACTED
Mon May 27 06:44:05 CEST 2013


In that case, mnesia will search the entire table. 

If the table is an ordered_set and the first parts of the key are bound - e.g. {a, x,'$1'} - then ets can (and does) limit the search. 

BR,
Ulf W

Ulf Wiger, Feuerlabs, Inc.
http://www.feuerlabs.com

27 maj 2013 kl. 00:33 skrev Evgeny M <donpedrothird@REDACTED>:

> 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 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130527/6d351f19/attachment.htm>


More information about the erlang-questions mailing list