[ZODB-Dev] BTrees and PersistentDict keys: bug or feature

Christian Reis kiko at async.com.br
Fri Aug 15 02:04:34 EDT 2003


On Thu, Aug 14, 2003 at 11:52:55PM -0400, Casey Duncan wrote:
> > To explain a tiny bit further, I'm using an OOBTree that maps
> > dictionaries to objects. This is part of the indexing mechanism in
> > IndexedCatalog, which is a simple indexing and query mechanism for the
> > ZODB. This allows us to do queries like:
> > 
> >     "5 in mydict"
> 
> I'm not sure how using dictionaries as keys helps here (it just sounds evil to 
> me ;^), but this is one place where the Python hashing rules for dictionary 

I'm suffering from lack of oxygen (hopefully). The important query here
is, or course:

    "mydict == {foo: bar}"

-- which is handled correctly (AFAICT, and I can't tell much yet because
I still need to test a lot) by simple comparison.

> keys begin to make lots of sense. In Python you are forbidden from using 
> simple mutable objects as keys since generating a stable hash for them is not 
> possible unless you subclass and supply your own hash.
> 
> BTrees make it much easier to shoot yourself in the foot since keys must only 
> be comparible, which mutable objects usually are. So the thing to note (no 
> doubt you have realized this) is that when you use mutable objects as BTree 
> keys (or set members) you are playing with fire and your are very likely to 
> get burned.

I'm keeping a close eye on this particular feature to see how well this
hack holds out. It may be that we'll just revert to sequential scans and
go on with life.

> > I've fixed this to make sure I only store dictionaries as keys. My
> > wrapper class makes sure that the dicts are never mutated while being
> > used as being keys, and so far check() has been reassuring.
> 
> Sounds like mongo pain for a "minor feature".
>
> hoping-the-bandages-and-grafts-heal-soonly y'rs,

Well, I didn't mention I had to implement this for lists too! 

(And to think all this because nobody on python-dev lets me work on
fixing LC_NUMERIC. I should get a night job.)

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL



More information about the ZODB-Dev mailing list