[elephant-devel] Querying for objects on two slots
Alex Mizrahi
killerstorm at newmail.ru
Tue Jan 6 13:17:13 UTC 2009
YK> Is this a reasonable way of finding an object of type
YK> 'my-class that matches on values val-a and val-b for slots a and b?
yep, it is reasonable if you have relatively low number of objects
in returned by (get-instances-by-value 'my-class 'slot-b val-b) query.
if number of objects is significant and you get a slowdown because
of this, you might want to optimize this. a trivial thing is to try it
symmertrically with slot-a -- whatever returns less objects is better.
less trivial optimizations would be to work on lower-level -- via
map-inverted-index (to avoid allocating whole list but instead test objects
one by one) or even cursor API (this way you can retrieve oids rather
than objects, which should be faster, and also iterating both indices at
once might be a significant benefit if values are not uniformly
distributed).
but the most optimal way doing this in case of high number of objects
in both slot-a and slot-b queries would be building and using multi-column
index. unfortunately, Elephant does not help you with it -- either you'll
have
to serialize slot tuples into a string (e.g (format nil "~a_~a" slot-a
slot-b)),
or reorganize your data to use a custom index structure (like btree of
btrees).
there are also backend-specific considerations. for postmodern
(intersection (get-instances-by-value 'my-class 'slot-b val-b)
(get-instances-by-value 'my-class 'slot-a val-a))
would be much faster then testing objects one by one, for BDB -- i doubt so.
LP> Use MAP-CLASS, this will considerably speed up the query.
how is that? using at least one index is much better than using no index at
all.
More information about the elephant-devel
mailing list