[erlang-questions] slow mnesia query

Rik Ribbers rik.ribbers@REDACTED
Fri Jan 8 14:51:51 CET 2016


Hello,

Being relatively new to Erlang I got a mnesia database with a record that contains a key and a value. The key is a string (list) and the value another string.

I want to search for all records where the key contains parts of a provided substring (a list) . The code is below:

handle_get(PartialKey1, MaxResults) ->
  PartialKey2 = string:to_lower(PartialKey1),
  F = fun() ->
    C = qlc:cursor( qlc:q(
      [{R, Key, Value} || {R, Key, Value} <- mnesia:table(retro), (string:str(Key, PartialKey2) > 0), (string:len(Value) > 0)]
    )
    ),
    R = qlc:next_answers(C, MaxResults),
    ok = qlc:delete_cursor(C),
    R
  end,
  Result = mnesia:async_dirty(F),
  Result.

The code is working it does what is should do, however it does not perform very well… I guess this does have to do with the string:str comparison that needs to go over all records every time. This shouldn’t be that hard to optimise for performance, however I don’t have any idea how… 

Any help is appreciated 

Gr,
Rik 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4409 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160108/1dab41ce/attachment.bin>


More information about the erlang-questions mailing list