[erlang-questions] mnesia question - fastest way to tell if ordered_set table is empty or not

Jonathan Leivent jleivent@REDACTED
Sun Jun 16 23:49:41 CEST 2013


On 06/16/2013 05:25 PM, Chandru wrote:
> Have you tried this?
>
> mnesia:table_info(Table_name, size).
>
> Chandru

That's the alternative I mentioned below, just with an ets activity 
wrapped around it.  I just don't know if table_info-size is going to get 
the answer fast in all cases.  For instance, if it actually has to 
iterate to count the records.  Or if it collects more info than just 
size, and then returns only size because that's all that's being asked 
for.  Or if it has to wait for write locks on the table to get dropped, 
even though it is wrapped in an ets activity.

I forgot to mention that the table is local_content, if that makes any 
difference.

>
> On 16 June 2013 20:14, Jonathan Leivent <jleivent@REDACTED> wrote:
>
>> What is the fastest way, avoiding locking, to tell if an ordered_set
>> mnesia table is empty or not?  I'm assuming that if the table is not an
>> ordered set, then:
>>
>>    mnesia:activity(ets, fun mnesia:first/1, [Table]) == '$end_of_table'
>>
>> is the fastest.  However, if the table is an ordered set, this seems like
>> it could take O(logN) time.
>>
>> Would this be faster?:
>>
>>   mnesia:activity(ets, fun mnesia:table_info/2, [Table, size]) == 0
>>
>> Is there a faster alternative?
>>
>> -- Jonathan





More information about the erlang-questions mailing list