How to efficiently query data from FDB?

Few days back I posted on this forum asking about the way to structure data in FDB. I received very patient and informative replies from @markus.pilman

In those replies it was mentioned that a better way to structure data in FDB is to associate the primary key with the complete table data/record as the value, stored in an efficient format such as protobuf. For example, a student table {uuid, name, address} could be represented in FDB as (uuid, {name, address}) where name and address are stored as protobuf encoded value for the uuid key.

So, my question is, how do I efficiently query data that is encoded in the value? Say, I want to find all students whose name is ‘Bandu’; do I need to query the FDB server for each student record, decode the protobuf value, and then check for the name? What will be the performance implications of this approach? Am I thinking in the wrong direction again? What is a better way to query data in FDB?

FDB allows to query by a key or a key range, uuid in your case. So if you need to query by a part of value efficiently, you have create secondary key-value pairs: {name+uuid, }. Then you will be able to query by name using the range with the prefix name and to get a list of uuids of the students with given name, then, to query their data by uuid.

You can use the Record Layer on top of fdb, that does a part of this work automatically. There is a special part Using Layers in this community forum.

What are the performance implications of querying the DB server twice?

Of cause, the performance will be lower.

If it is not acceptable, you may duplicate data and insert two pairs:

  • {uuid, {name, address}}
  • {name+uuid, address}