[elephant-devel] Re: traversing btree using multiple indices
Alex Mizrahi
killerstorm at newmail.ru
Thu Apr 3 17:34:25 UTC 2008
SR> I'm hoping that someone can point me in the right direction here.
SR> Given 2 secondary indices on an indexed btree is it at all possible to
SR> create/use a derived index which is the union of the 2 created indices
SR> without requiring the explicit creation of a 3rd index
i'm not sure what do you mean, but subject suggests that you just want to
walk through both indices simultaneously as if they were just one sorted
index.
if so, you can use lower-level cursor APIs, without creating anything on
database level.
something like that:
(let ((c1 (ele:make-inverted-cursor 'foo 'bar))
(c2 (ele:make-inverted-cursor 'foo 'baz)))
(ele:cursor-first c1)
(ele:cursor-first c2)
(loop for cc = (whichever-less c1 c2)
while cc
for (exists k v) = (multiple-value-list (ele:cursor-current cc))
while exists
do (something-with k v)
do (ele:cursor-next cc))
(ele:cursor-close c1) ; it's better to put this in unwind protect
(ele:cursor-close c2))
actually i've made some macro to do this in easier (and more general) way,
but it's somewhat ugly so i'm not sure if i want to share it :)
More information about the elephant-devel
mailing list