Forum OpenACS Q&A: Re: Great tree_sortkey Documentation!

Collapse
Posted by Don Baccus on
Frank, key values between 0 and 127 are encoded in a single byte.  Key values greater than 128 are stored as the value + 2^32 in four bytes.

What "strange effects" are you seeing?  The keys sort correctly using this scheme...

Collapse
Posted by Frank Bergmann on
Hi Don,

that's correct. However, I see some differences between the "SQL for smarties" stuff and yours:

Your representation allows to query directly:

    "give me all children of project X"

All other queries are probably quite slow because they require PxSQL iterations for each item:

    "in which level of the hierarchy do I live" and
    "give me my parent" and
    "give me the list of my siblings"

However, "give me my parent" is already covered by the parent_id that is usually present in any hierarchical data type and asking for the level is normally associated with a db_foreach loop in order to draw the indentation, so speed shouldn't matter that much anyway.

I think what most confused us is that the documentation refers to one, two, three and four byte representations and that it doesn't explain the use of the first bit as a separator between your one-byte and your four-byte representations...

Great stuff anyway!
Frank

http://www.project-open.com/