Database code

Andrew Tridgell tridge at
Wed Dec 29 22:06:29 GMT 1999

> ok, what i should have explicitly stated is:
> - is it possible to have two (or more) unique primary keys
> - is it possible to do fast lookups on all those keys

yes, thats what I described. It is slightly slower (a few
microseconds) looking up on the 2nd key, but that certainly won't
matter in this case.

> can that be abstracted to another level?

sure, just write a fn. 

void my_store(TDB_CONTEXT *tdb, TDB_DATA key1, TDB_DATA key2, TDB_DATA data)
	tdb_store(tdb, key2, key1, TDB_REPLACE);
	tdb_store(tdb, key1, data, TDB_REPLACE);

TDB_DATA my_fetch1(TDB_CONTEXT *tdb, TDB_DATA key1)
	return tdb_fetch(tdb, key1);

TDB_DATA my_fetch2(TDB_CONTEXT *tdb, TDB_DATA key2)
	TDB_DATA key1;
	key1 = tdb_fetch(tdb, key2);

	if (key1.dptr == NULL) return key1;

	return tdb_fetch(tdb, key1);

ok? just add error checking to the above, stir and simmer over a hot
debugger for 10 minutes. Voila, database-al-la-2key.

Cheers, Tridge

More information about the samba-technical mailing list