Badger: options for storing parent-child relations

Hello

What are my options for storing parent-child relations in badger? Basically I would like to store parent as key and children as a list of values.
There is a merge operator that can be used to create lists, but as I understand it’s quite expensive performance-wise because Badger creates a goroutine for each merge operator.
Another option is to append parent to child and save that as key with no value. Then it’s possible to iterate by parent prefix.

What is the best approach?

Hey @roganov,
Apologies for the late reply. I somehow missed the notification.

There is a merge operator that can be used to create lists, but as I understand it’s quite expensive performance-wise because Badger creates a goroutine for each merge operator.

If all the keys you insert would be on parent-child relationship, it might actually be expensive. I believe you would be appending children to the value field of the parent. Apart from too many go routines, you might end up with large values and they might get stored in the value log file. Reading from value log file is expensive.

Another option is to append parent to child and save that as key with no value. Then it’s possible to iterate by parent prefix.

This should be much cheaper than the first approach. Dgraph actually does something similar. You can use a key iterator to iterate over all keys with the same prefix. You should also set opt.PrefetchValues=false in iterator options.