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

Chandru <>
Mon Jun 17 12:42:57 CEST 2013


On 16 June 2013 22:49, Jonathan Leivent <> wrote:

> 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.


Yes, sorry I didn't notice that. AFAIK, table info such as size is metadata
which is maintained for each table, and not something which is determined
each time you issue the command.

Chandru


>
>
>
>> On 16 June 2013 20:14, Jonathan Leivent <> 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
>>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130617/9eff1612/attachment.html>


More information about the erlang-questions mailing list