[erlang-questions] QLC and mnesia indexes

David King dking@REDACTED
Mon Nov 5 05:47:34 CET 2007

Is there a way to ask mnesia how many results there are for a given  
query without evaluating it (either in QLC or otherwise) if it can  
determine the answer entirely from an index?

That is, if I have a set of employees:


And the mnesia table is created like this:

        {attributes, record_info(fields,author)},

If I wanted to know how many employees started in the last seven  
days, I could do:

length(qlc:e(qlc:q([ X#employee.id
                      || X <- mnesia:table(employee),
                         X#employee.started_on > SevenDaysAgo ]))).

However, I should also be able to find that out without evaluating  
the query at all, since the index on started_on should contain enough  
information to figure it out, and given a large number, it can take  
much less time. Does QLC or Mnesia have a way to do so?

More information about the erlang-questions mailing list