speed up by indexing database reference keys

Signed-off-by: Andreas Zöllner <andi@go-for-fun.de>