group and reduce rows for foreign key relations for sorted key-value stores like leveldb