<div dir="ltr">Thanks a lot, I solved my problem...<br><br>/Greg<br><br><div class="gmail_quote">On Fri, Oct 3, 2008 at 1:36 AM, Pablo Polvorin <span dir="ltr"><<a href="mailto:pablo.polvorin@gmail.com">pablo.polvorin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
there has been a discussion of this some months ago,<br>
search for "Index Overhead In Mnesia"<br>
<br>
<br>
2008/10/2 Greg Burri <<a href="mailto:greg.burri@gmail.com">greg.burri@gmail.com</a>>:<br>
<div><div></div><div class="Wj3C7c">> Hi,<br>
> I use mnesia for a little project and I observed a strange (but maybe right)<br>
> behavior from the function mnesia:write/1 when an extra index has alway the<br>
> same value.<br>
> In this case the complexity of the insertion appears to be in O(n) where n<br>
> is the number of tuple in the table.<br>
><br>
> My record :<br>
> -record(minichat,<br>
> {<br>
> id,<br>
> auteur_id, %indexed<br>
> date,<br>
> pseudo,<br>
> contenu,<br>
> troll_id = undefined, %indexed<br>
> racine_id = undefined<br>
> }).<br>
><br>
> So, I made a little benchmark to see what happen in three cases :<br>
> 1) '#minichat.troll_id' is undefined for all tuple<br>
> 2) same as 1) but without the index on 'troll_id'<br>
> 3) 'troll_id' is indexed but some random values are put in it<br>
><br>
> You can see the results here :<br>
> 1) O(n) : <a href="http://www.gburri.org/mnesia_write/results_100_000.png" target="_blank">http://www.gburri.org/mnesia_write/results_100_000.png</a><br>
> 2) O(1) :<br>
> <a href="http://www.gburri.org/mnesia_write/results_100_000_without_index_on_troll_id.png" target="_blank">http://www.gburri.org/mnesia_write/results_100_000_without_index_on_troll_id.png</a><br>
> 3) O(1) :<br>
> <a href="http://www.gburri.org/mnesia_write/results_100_000_with_random_data_into_troll_id.png" target="_blank">http://www.gburri.org/mnesia_write/results_100_000_with_random_data_into_troll_id.png</a><br>
><br>
> Is this behavior normal ? Is this the result of the collisions of keys ?<br>
><br>
><br>
> Here is some additional informations about my tests :<br>
><br>
> The creation of the table (called at the beginning of all test) :<br>
> [..]<br>
> mnesia:create_table(minichat, [<br>
> {attributes, record_info(fields, minichat)},<br>
> {disc_copies, [node()]}<br>
> ]),<br>
> mnesia:add_table_index(minichat, auteur_id),<br>
> mnesia:add_table_index(minichat, troll_id). % commented for the second<br>
> case test<br>
><br>
> The benchmark code :<br>
> [..]<br>
> bench_write_minichat(Filename) -><br>
> Times = bench_write_minichat(1, []),<br>
> {ok, File} = file:open(Filename, [write]),<br>
> lists:foreach(<br>
> fun({Id, Time}) -><br>
> io:format(File, "~w ~w~n", [Id, Time])<br>
> end,<br>
> Times<br>
> ),<br>
> file:close(File).<br>
> bench_write_minichat(100000, Temps) -> Temps;<br>
> bench_write_minichat(Id, Temps) -><br>
> {T, _} = timer:tc(mnesia, transaction, [fun() -><br>
> mnesia:write(#minichat{<br>
> id = Id,<br>
> auteur_id = random:uniform(1000),<br>
> date = now(),<br>
> pseudo = "Test",<br>
> contenu = "Blabla blabla bla.",<br>
> racine_id = random:uniform(1000)<br>
> % ,troll_id = random:uniform(1000) % uncommented for the third case<br>
> test<br>
> })<br>
> end]),<br>
> bench_write_minichat(Id + 1, if Id rem 500 =:= 0 -> [{Id, T} | Temps];<br>
> true -> Temps end).<br>
><br>
><br>
> /Greg Burri<br>
><br>
</div></div>> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>