I would do this outside the Mnesia database. Keep explicit-min and explicit-max, having a process that finds out about these values ββwhenever there is an insert in the table. This gives you a very fast constant search on values.
If you can do this with an O (lg n) time, you can make the table ordered_set. From there, first/1 and last/1 should give you what you want, given that the key contains what you order. But it also slows down other queries in general to O (log n).
The third trick is an approximation. From time to time you look at the table and note the values ββof max and min. Then it materializes into what you want, but the value may not correspond to the date if a lot of time has passed since the last scan.
source share