Data/File Structure and Algorithm for Retrieving Sorted Data Chunk Efficiently

Josiah Carlson jcarlson at uci.edu
Fri Oct 8 11:38:24 EDT 2004


> > Or even the included bsddb.btree database (remember to translate to/from
> > strings, open using bsddb.btopen() ).
> 
> But, given a bsdsb btree with, say, 10,000 entries in it (in virtually
> sorted order), how does one speedily say "get entries 4020 to 4030", for
> example?  That was the original poster's problem as originally posed.
> If you call somedb.set_location(4020), you learn that integer keys are
> only allowed for Recno and Queue DBs, not for BTree ones...
> 
> I think the crucial step (with current versions of bsddb) is to have
> btflags=bsddb.db.DB_RECNUM at creation time; then, say xx is the
> variable that's your database, xx.dbc.set_recno(4019) should position
> the cursor as required.  Sleepycat does warn that DB_RECNUM can degrade
> performance for some applications, though, so be sure to do some
> benchmarks if you want to do things this way.

I would hope that bsddb keeps track of tree location information in an
intelligent way, so even if it is slower, it still beats a flat text
file hands-down.

It would likely not beat a real dbms, but it all depends on if the
original poster finds that necessary.

 - Josiah




More information about the Python-list mailing list