<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello,</p>
<p><br>
</p>
<p>Please check:</p>
<p><a class="moz-txt-link-freetext" href="https://github.com/nyczol/otp/tree/mnesia_new_index2">https://github.com/nyczol/otp/tree/mnesia_new_index2</a></p>
<p>for <span class="pl-en">dirty_index_read/4 with limit in mnesia
module.</span></p>
<p><span class="pl-en"><br>
</span></p>
<p><span class="pl-en">Branch was created in 2013 but unfortunately
PR was rejected by OTP.<br>
</span></p>
<p><span class="pl-en"><br>
</span></p>
<p><span class="pl-en">Branch contains 2 features:</span></p>
<p><span class="pl-en">- new index type for mnesia</span></p>
<p><span class="pl-en">- set of functions that operate on secondary
indexes and </span><span class="pl-en"><span class="pl-en"><span
class="pl-en">return limited number of records</span></span></span></p>
<p><span class="pl-en"><br>
</span></p>
<p><span class="pl-en">Used on prod envs from 2013 untli now.<br>
</span></p>
<p><span class="pl-en"><br>
</span></p>
<p><span class="pl-en">Maybe its good time to create PR again for
2nd part only?<br>
</span></p>
<p><br>
</p>
<p><span class="pl-en"></span><span class="pl-en"><span
class="pl-en"><span class="pl-en">Regards</span></span></span></p>
<p><span class="pl-en"><span class="pl-en"><span class="pl-en">Aleksander
Nycz<br>
</span></span></span></p>
<p><span class="pl-en"></span></p>
<br>
<p><br>
</p>
<div class="moz-cite-prefix">W dniu 27.11.2019 o 10:03, Roberto
Ostinelli pisze:<br>
</div>
<blockquote type="cite"
cite="mid:CAFXp3LJbqPUa6Uvfj32a15+xizGvsb-fBY4J5yVT1_1iKBEdNQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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"
moz-do-not-send="true">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>
</blockquote>
</body>
</html>