Hi Richard,

I'm not a SQL guru, but I believe that OFFSET and LIMIT are typically performed on the result of a query. The resulting OFFSET and/or LIMIT is typically going to be O(q) rather than O(n). However, many query optimizers use arrays to store the active query set rather than BTrees, and of course it's easy to skip to the n'th value in a query array. I'm hoping our new query system will be able to do something like this.

>>
>> 4) What is the intended use of `add-class-derived-index'? I must say
>> that the documentation isn't very clear about it (specially figuring
>> out what is a valid `derived-defun' wasn't trivial). Tight now I think >> I am supposed to run it once (it complains about a duplicate index if
>> run a second time). This isn't exactly handy, because I would prefer
>> that defining a derived index to left a clear trace in my code. Right
>> now I am calling it wrapped with `handler-case'.

> Uhhh....Ian will have to answer that.

The dynamic nature of add-dynamic-index has annoyed me for awhile too. Originally, I didn't want to implement the metaprotocol support to do this in the class definition and didn't take the time to provide a top-level macro to take care of this. I have now put support into the persistent-object metaprotocol on the unstable branch for the following construct:

(defclass foo ()
  ((slot1 :accessor slot1)
   (slot2 :accessor slot2)
   (didx :accessor didx
         :derived-fn (lambda (inst) (+ slot1 slot2))
         :slot-deps (slot1 slot2))))

didx is now an indexed slot which is a function of the value of other slots. It is only updated when slot1 or slot2 are written. Be warned that derived functions can be expensive as they are updated when any dependent slot is written. If not slot-dep argument is provided, the derived index value is recomputed on each slot write to that instance.


The unstable branch is at beta quality. It passes prior tests, some new tests but the new features and overall stability have not been proven out. I'm using it extensively with BDB, but we're still waiting on the relational data store maintainers (clsql and postmodern) to find the time to add the required support. So as Robert said, use it if you're experimenting or developing with elephant, but don't use it in production until it's finalized (a few weeks to a month or two from now).

The feature set in unstable includes a much more robust schema evolution mechanism along with inherited slot indices (a base class can index instances of its subclasses), a number of new slot types including read-caching slots, collection slots, and associations.

A more extensive update can be found at:
http://common-lisp.net/pipermail/elephant-devel/2008-March/001646.html

Hi, I've started using Elephant and I must say I am really surprised how easy and nice to use it is. However, there are some areas where I feel a bit lost, and I couldn't find the answers in the manual. I am using Elephant 0.9.1 with a BDB backend. 1) What is the right way of doing something similar to a UNIQUE constraint in a relational database? The solution on top of my head is to write a method for `initialize-instance' that will check the existence of an object with the same value as the provided for the unique slot (which should of course be indexed), and raise a condition if yes. 2) What is the right way to do many-to-many relationships? At the moment I have slot with a pset, and add object A to the pset of object B and vice versa, in a transaction. 3) How do I implement something to do efficient (i.e. not O(n)) LIMIT and OFFSET queries? I was thinking of maintaining a counter (my intuition would be to use a class allocated slot, but I think that class objects are not serialized--- am I right?) for classes where I need it, and using some method to update it. For decreasing the counter my candidate is drop-pobject, for increasing initialize-instance, but I am not sure about it (btw Elephant complains if you try to trace `initialize-instance'). 4) What is the intended use of `add-class-derived-index'? I must say that the documentation isn't very clear about it (specially figuring out what is a valid `derived-defun' wasn't trivial). Tight now I think I am supposed to run it once (it complains about a duplicate index if run a second time). This isn't exactly handy, because I would prefer that defining a derived index to left a clear trace in my code. Right now I am calling it wrapped with `handler-case'. Finally, how stable is the unstable version of Elephant and what are the most important changes that have already been implemented? I am specially interested in the query language part. Thanks in advance, -- Richard
_______________________________________________
elephant-devel site list
elephant-devel@common-lisp.net
http://common-lisp.net/mailman/listinfo/elephant-devel

Reply via email to