[ejabberd] Implementing XEP-0059 (question for mnesia gurus)

Alexander Tsvyashchenko lists at ndl.kiev.ua
Fri Oct 10 16:22:43 MSD 2008


On Fri, 10 Oct 2008 12:11:53 +0200, Eric Cestari <eric at ohmforce.com> wrote:

> Thank you for pointing me to mod_archive.
> The solution implemented looks quite inefficient (seems like it's  
> using tail recursion and that's O(n))
> After a bit of browsing I feel QLC cursor and next answer are part of  
> the solution.
> http://www.erlang.org/doc/man/qlc.html
> But then again, will it scale ?

Thanks in turn for pointing me to QLC ;-)

However, please correct me if I'm wrong, but it looks like it allows to
implement LIMIT part of paging only, not the OFFSET one - this means the
complexity is still linear, thus leading, I believe, to the speed
comparable with mod_archive implementation for worst-case scenarios (small
requests near the end of table), which represent quite typical use case for
RSM. Memory usage, on the other hand, should be indeed improved in this
case, though.

One solution to that problem I also though about in the past (and that
might work well with the QLC approach) is creation of special indices,
which main function is to allow to implement OFFSET indirectly, by
providing the appropriate query condition (Key >= Offset && Key < Offset +
Limit). However, this approach is quite difficult to implement & maintain
because at least for archiving you will need different indices for
different types of queries (as there are different ways to formulate
queries which influence the ordering of results included), and in the
presence of many updates it might become too expensive (as these indices
will also require up to the linear update on each one-item update), so in
the end I discarded that idea and in fact would not recommend that to
anyone ;-)

Good luck!                                     Alexander

More information about the ejabberd mailing list