Does anyone have an idea of how to limit size of result set in mnesia
similar to the effect of LIMIT clause in the SQL query below in MySQL?
SELECT * FROM Topic LIMIT 5;
Best regards,
Ahmed Al-Issaei
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
You can use qlc
http://www.erlang.org/doc/man/qlc.html
or you can use
mnesia:select/4 in combination with mnesia:select/1
http://www.erlang.org/doc/man/mnesia.html#select-4
/Kenneth Erlang/OTP, Ericsson
Just to confirm, for qlc, I should write the query first and then run
qlc:info/2 on it in order to do the limiting, as the example below
shows. Is this it?
e.g.:
Q = qlc:q(...),
qlc:info(Q, [{n_elements, 5}]
Best regards,
Ahmed Al-Issaei
C = qlc:cursor(qlc:q([X || X <- qlc:append(QH1, QH2)],{unique,true})),
R = qlc:next_answers(C, 5),
ok = qlc:delete_cursor(C),
R.Thanks for the clarification. However, I still don't understand what's
the point of n_elements in qlc:info(Q,[{n_elements,N}]). In QLC
documentation, it names 2 kinds of options, "Option = EvalOption |
ReturnOption" which suggests that qlc:info/2 can be used to set
evaluation time options.
Also, I'm assuming I can remove {unique, true} option from
qlc:append/2 and the result is still the same.
Best regards,
Ahmed Al-Issaei
>
> Hi All,
>
> Does anyone have an idea of how to limit size of result set in mnesia
> similar to the effect of LIMIT clause in the SQL query below in MySQL?
>
> SELECT * FROM Topic LIMIT 5;
>From Mnesia Reference Manual (http://www.erlang.org/doc/man/mnesia.html) :
"select(Tab, MatchSpec, NObjects, Lock) -> transaction abort | {[Object],Cont} | '$end_of_table'
Matches the objects in the table Tab using a match_spec as described in ERTS users guide, and returns a chunk of terms and a continuation, the wanted number of returned terms is specified by the NObjects argument. The lock argument can be read or write. The continuation should be used as argument to mnesia:select/1, if more or all answers are needed.
Note: for best performance select should be used before any modifying operations are done on that table in the same transaction, i.e. don't use mnesia:write or mnesia:delete before a mnesia:select. For efficiency the NObjects is a recommendation only and the result may contain anything from an empty list to all available results.
select(Cont) -> transaction abort | {[Object],Cont} | '$end_of_table'
Selects more objects with the match specification initiated by mnesia:select/4.
Note: Any modifying operations, i.e. mnesia:write or mnesia:delete, that are done between the mnesia:select/4 and mnesia:select/1 calls will not be visible in the result.
"
Cheers,
Jani Launonen
This can have a beneficial effect on garbage collection, as the
process may be able to perform the work with a fairly small
heap. In simple queries (no joins or complex filter expressions),
it's not likely to help much, but it can improve memory
characteristics in some cases.
BR,
Ulf W
2008/4/28 Ahmed Ali <ahmed....@gmail.com>: