On Mon, 2008-01-21 at 10:58 +0200, Alex Mizrahi wrote: > JN> I did some reading through the mailing list archives and the Elephant > JN> manual, but cannot find a recommended way of counting the number of > JN> persistent objects of a particular class. > > JN> I have a method that works (using map-class) but this is way too slow > JN> for my purposes. > > JN> I did find some postings from Oct last year about this question but no > JN> definitive answer it seams. > > JN> Any advice? > > as far as i know, most btree implementation do not have a fast way to count > leafs -- you need to iterate through all of them. > in PostgreSQL (and i think in most relational databases like that) query > "SELECT COUNT(*) FROM tree11" takes time proportional to number of elements > in tree11. > of course it would be much faster to do "SELECT COUNT(*)" then reading all > elements on Lisp side, but it will be flawed anyway.
Right, I'm used to doing "SELECT COUNT" SQL statements, which could be on any kind of joins and is *very* fast in a relational database. > > so, the advice would be to count this parameter yourself. for example, make > btree class-name -> instance count. and update it in initialize-instance > (you can move this functionality to some instance-counter-mixin class), and > whereever you delete them.. This is a great suggestion. Just to verify: the writes to the database from the initialize-instance method; will they occur atomically with the consing of the persistent class (i.e. I don't need to explicitly wrap things into a transaction)? Joubert _______________________________________________ elephant-devel site list elephant-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/elephant-devel