[pkg-db-devel] Bug#639421: Bug#639421: libdb5.1: silently creates btree database when hash is requested

Ondřej Surý ondrej at sury.org
Thu Sep 1 18:25:53 UTC 2011


Try this, it's the db_stat which is wrong, the database is correctly
created as DB_HASH.

int main(int argc, char **argv)
{
        int envflags = DB_INIT_TXN | DB_INIT_MPOOL;
        int flags = DB_RDONLY | DB_AUTO_COMMIT;
        DB_ENV *dbenv;
        DBTYPE type;
        DB *dbp;
        const char *filename = argv[1];

        if (argc < 2)
                return 2;

        mkdir(filename, 0700);
        db_env_create(&dbenv, 0);
        dbenv->open(dbenv, filename, envflags, 0700);
        db_create(&dbp, dbenv, 0);
        dbp->open(dbp, NULL, "openpgp", "openpgp", DB_UNKNOWN, flags,
                        0600);
        dbp->get_type(dbp, &type);
        if (type == DB_HASH) {
          printf("DB Type is DB_HASH\n");
        } else {
          printf("DB Type is not DB_HASH\n");
        }
        dbp->close(dbp, 0);
        dbenv->close(dbenv, 0);
        return 0;
}


On Thu, Sep 1, 2011 at 19:41, Florian Weimer <fw at deneb.enyo.de> wrote:
> * brian m. carlson:
>
>> Berkeley DB creates a btree database even though hash is requested, and
>> moreover, it does so silently.
>>
>> Steps to reproduce:
>>
>> * gcc foo.c -ldb
>> * rm -fr /tmp/db
>> * ./a.out /tmp/db
>> * db5.1_stat -d /tmp/db/openpgp | grep Btree
>
> Please try again with the -s option:
>
> | If the database contains multiple databases and the -s flag is not
> | specified, the statistics are for the internal database that
> | describes the other databases the file contains, and not for the
> | file as a whole.
>
> Is there any particular reasony why you want to use hash databases?
> They are rarely better than B-tree databases.
>
>
>
> _______________________________________________
> pkg-db-devel mailing list
> pkg-db-devel at lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-db-devel
>



-- 
Ondřej Surý <ondrej at sury.org>





More information about the pkg-db-devel mailing list