For example, given record
-record(item, {
id,
time,
status}).
I want to search the 1000 to 1100 items, ordered by time and status =:= <<"finished">>
Any suggestions?
For example, given record
-record(item, {
id,
time,
status}).
I want to search the 1000 to 1100 items, ordered by time and status =:= <<"finished">>
Any suggestions?
It depends on what your queries look like. If you need to order by lots of different columns, then I'd consider using SQL instead of Mnesia.
But if you only need the kind of query you described, you should be able to use the
ordered_set
type of table to handle the ordering andmnesia:select/4
to handle pagination and the constraint.Here's some untested code to give you the gist:
Basically,
mnesia:select/4
gives you a page of results and a continuation for the next page of results. There's not a built-in way to jump to the 1000th result like in a SQL DB, so if you needed that ability you'd build it yourself (keep an index of times so you can quickly look up that the 1000th time in your table is{{2015,4,12},{23,53,8}}
and then use that as a guard when runningselect
.You might to use QLC Cursor, something like this:
The manual of QLC is here Qlc:reference but this way isn't fastest way in production, for middle heavy load is enought (10000 connection per second it tested), but more you will got a problems within memory free space, you will need to rise it up
I think, you should use
mnesia:select/2
to select the objects whichstatus =:= <<"finished">>
, then you can uselists:sort
to sort the results bytime
, at last you can uselists:sublist/3
to subtract the element from1000
to1100
.Here is the link: http://www.erlang.org/doc/man/mnesia.html#select-2 http://www.erlang.org/doc/man/lists.html#sort-2 http://www.erlang.org/doc/man/lists.html#sublist-3