in reply to Re: What is a fast way to get keys of a Berkeley DB into an array?
in thread What is a fast way to get keys of a Berkeley DB into an array?

I guess I must be missing something but for a btree to work, you need to be able to compare the key you are looking for against the values in the internal index nodes of the tree. If the values in the index nodes are actual keys and not some analyzed version of them (which is what I was incorrectly calling the hashed key) then it seems there would be a way to construct the keys in the db by only visiting the index nodes. Since the number and size of these nodes shouldn't be affected by the amount of data in each row, I was a little surprised to see the performance change that I did. Obviously I'm missing something about the implementation but that was my reasoning and where my comment came from.

Yes, your solution is the one I have in mind. The concern is maintaining coherency and that's why I was hoping to avoid it.
  • Comment on Re^2: What is a fast way to get keys of a Berkeley DB into an array?

Replies are listed 'Best First'.
Re^3: What is a fast way to get keys of a Berkeley DB into an array?
by BrowserUk (Patriarch) on Jun 10, 2010 at 16:47 UTC
    If the values in the index nodes are actual keys and not some analyzed version of them (which is what I was incorrectly calling the hashed key) then it seems there would be a way to construct the keys in the db by only visiting the index nodes.

    Berkeley's BTree DBs are actually B+Trees, where all the values (*), are kept in the leaf nodes along with their respective keys. In-order traversal is done by locating the leaf block for the 'lowest' key, and then following peer-level pointers to move from leaf to leaf. Therefore, traversing the entire key-space will mean reading all the keys & values from disk.

    (*)Unless the data values are too large to store in the chosen page-size, in which case 'overflow records' are used.

    The concern is maintaining coherency and that's why I was hoping to avoid it.

    If you use the tied hash interface, you could override the STORE() and DELETE() methods to maintain the key list entry. You could also use the fact that BDB allows you to maintain more than one DB in a single file to store that list as the only record in a second DB. That ought to ensure that single record is perpetually cached.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.