Mnesia index reversing the order of records


I have an ordered_set in Mnesia where the records look like this:

:request_id,   # String, the primary key
:campaign_id,  # String, used often for filtering
:call_id,      # String

The following function returns the records ordered by the primary key, ascending, as expected:

:mnesia.dirty_match_object({:request, :_, "A", :_}) 

However, if I add an index for the second attribute (campaign_id), the records are returned in the reverse order (descending).

Is this expected?

I couldn’t find a way to choose between ascending and descending order when creating the index.

Of course I can reverse the records myself at the application level, but it doesn’t seem right.

And in fact I only need the first record (the table holds one queue per campaign_id), so I could take the last record using or Enum.fetch/2, but they are O(n) anyway.

Thanks for any help.