Index in Mnesia

Situation: We have running Erlang code that is executing about 20 transactions every 10 minutes. So, after 5 days we have something 25000 records in mnesia, which is not a great number. But some time ago it was impossible to restart an application. I got the following error:

exception exit: {{badmatch,{aborted,{no_exists,TABLENAME}}}

Then I checked:

ets:lookup_element(mnesia_gvar, {TABLENAME, where_to_read},2).

and got


The reason was in building indexes and missing function calling:

mnesia:wait_for_tables([TABLENAME], TIME)

Indexes are rebuilt on every load, except for disc_only_copies (disc_copies preferable then disc_only_copies because of performance reason). So, starting mnesia takes perceptible time even for not huge amount of data. And you need to choose whether you want quick start or better performance.