Composite key vs Single key append strings

左心房为你撑大大i 提交于 2019-12-20 06:19:33

问题


Watching many examples in Hyperledger Fabric I found two ways to achieved a key:

Let's suposse we have two fields visa and type of visa.

Visa: "1212323"

Type of Visa: "Student Visa"

So we can create a key neither:

  1. Using CompositeKey function provide by stub

key, err := stub.CreateCompositeKey(indexName,[]string{visa, typeVisa}) stub.PutState(key, value)

  1. Concatenating the two fields

stub.PutState(visa+typeVisa, value)

What is the difference between those two approaches? What is the best performance?


回答1:


By using Composite Keys you will have access to extra methods in your chaincode e.g. getStateByPartialCompositeKey so you could potentially retrieve all "Student Visa". If you make your own keys you would have to retrieve all the Visas then filter the set youself, or write queries to retrieve the data by attributes (assuming you are using JSON data in a CouchDB state database.) . So I would think the performance differential is in efficient retrieval rather than the original writing of the keys.

There is a good doc in the Fabric docs on CouchDB as the State Database which covers this information.



来源:https://stackoverflow.com/questions/55360962/composite-key-vs-single-key-append-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!