<div dir="ltr">Here's another try, this one too is very slow:<div><br></div><div><font face="monospace">QH = qlc:q([E || E <- mnesia:table(my_table), E#my_table.pid == Pid]),<br>mnesia:async_dirty(fun() -><br> QC = qlc:cursor(QH),<br> R = qlc:next_answers(QC, N),<br> qlc:delete_cursor(QC),<br> R<br>end).<br></font></div><div><br></div><div>Any ideas?</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 26, 2019 at 6:33 PM Roberto Ostinelli <<a href="mailto:ostinelli@gmail.com">ostinelli@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">All,<div>I've got a mnesia table that I create with:</div><div><br></div><div><font face="monospace">mnesia:create_table(my_table, [<br> {type, set},<br> {attributes, record_info(fields, my_table)},<br> {index, [#my_table.pid]},<br> {storage_properties, [{ets, [{read_concurrency, true}, {write_concurrency, true}]}]}<br>]).</font><br></div><div><br></div><div>If I want to get all records for the secondary index, I do:</div><div><br></div><div><font face="monospace">mnesia:dirty_index_read(my_table, Pid, #my_table.pid).<br></font></div><div><br></div><div>This operation if very fast. Now, sometimes I just need the <i>first</i> matching record and if there are many entries with the secondary index, the operation becomes a bottleneck. So I'm trying:</div><div><font face="monospace"><br></font></div><div><font face="monospace">S = fun() -><br> MatchHead = #my_table{pid = Pid, _ = '_'},<br> Guards = [],<br> Result = '$_',<br> mnesia:select(my_table, [{MatchHead, Guards, [Result]}], 1, read)<br>end,<br>case mnesia:activity(sync_dirty, S) of<br> {[Entry], _} -> Entry;<br> _ -> undefined<br>end.</font><br></div><div><br></div><div>This works, however this operation does not seem to be using the secondary index as it becomes extremely slow. I also tried:</div><div><br></div><div><font face="monospace">S = fun() -><br> MatchHead = #my_table{pid = '$1', _ = '_'},<br> Guard = {'=:=', '$1', Pid},<br> Result = '$_',<br> mnesia:select(my_table, [{MatchHead, [Guard], [Result]}], 1, read)<br>end,<br>case mnesia:activity(sync_dirty, S) of<br> '$end_of_table' -> undefined;<br> {[Entry], _} -> Entry<br>end.</font><br></div><div><br></div><div>And this is also slow. What can I do to dirty_select a limited number of records from a mnesia table?</div><div><br></div><div>Thank you,</div><div>r.</div></div>
</blockquote></div>