[elephant-devel] Querying for objects on two slots
Ian Eslick
eslick at media.mit.edu
Tue Jan 6 13:06:05 UTC 2009
Generally using get-instances-xxx is expensive (you have to cons up
all objects). A more efficient solution would be to map-inverted-
index over slot-b value and filter by the slot-a value. If slot-b
returns a small set, this is pretty darned efficient.
The little query interpreter we have now should do this
automatically. It's something like this (I don't have time to look up
the syntax just now)
(map-query
(select ((?c my-class))
(= (slot-a ?c) val-a)
(= (slot-b ?c) val-b))
However, if you don't have a small set in either a or b, you can
create a virtual slot that is some function of a and b and
automatically updated when slot a and b are updated. For now the best
way to do this is to put them into a string that can be totally
ordered. We need a good solution for sorting on short sequences of
primitive values so we can have pre-computed join indices.0
However, later the query system will allow you to do reasonably
efficient equality joins on the value/ranges in each slot (assuming
both are indexed). In fact the new system in query2.lisp might
actually handle the simple join query you're trying to do above - it
would be worth a quick try.
Ian
On Jan 6, 2009, at 1:36 AM, Yarek Kowalik wrote:
> I've run into several situations where I want to query for objects
> that match values two or more slots. I currently do something like
> this:
>
> (defclass my-class ()
> ((a :accessor slot-a)
> (b :accessor slot-b
> :index b))
> (:documentation "my test class"))
>
> (find-if (lambda (obj)
> (equal (slot-a obj) val-a))
> (elephant:get-instances-by-value 'my-class 'slot-b val-b))
>
>
> Is this a reasonable way of finding an object of type 'my-class that
> matches on values val-a and val-b for slots a and b?
>
> Yarek
> _______________________________________________
> elephant-devel site list
> elephant-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/elephant-devel
More information about the elephant-devel
mailing list