[ZODB-Dev] How do you handle changes to BTree key values?
Steve Alexander
steve@cat-box.net
Tue, 09 Oct 2001 09:12:02 +0100
Patrick K. O'Brien wrote:
>
> So if all I wanted was a collection of users, why would I want to use any of
> the BTrees, which required a key? What does the key buy you in ZODB? Should
> the key be a value that never changes? Does the key become an attribute in
> other objects similar to a foreign key in a relational database? Wouldn't
> you just use an object reference itself? Why am I finding this so difficult
> to get my brain around? (Too many years with relational?)
If I'm storing Person objects in a BTree, and using aPerson.name as the
key, then it is because I anticipate that later I will be given a name,
and I will want to retrieve the Person object that has that name, quickly.
If more than one person has the same name, I'd store a dict of Person
objects at that key in the BTree.
If a person's name changed, I'd remove that Person from the BTree,
change their name attribute, and then add them again with the new name.
Here, the BTree is acting like a simple index in a relational database.
For more complex situations, I would store the Person objects by the key
they would be most often retrived by, and also keep other indexes if I
needed random access via other attributes of a Person. This is what the
Catalog product (wrapped in ZCatalog in Zope) is for.
--
Steve Alexander
Software Engineer
Cat-Box limited