复合键与单键追加字符串 [英] Composite key vs Single key append strings

查看:61
本文介绍了复合键与单键追加字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过观看Hyperledger Fabric中的许多示例,我发现了实现密钥的两种方法:

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

假设我们有两个领域的签证和签证类型.

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

签证:"1212323"

Visa: "1212323"

签证类型:学生签证"

我们可以创建一个密钥:

We can create a key either:

  1. 使用存根提供的CompositeKey函数

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

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

  1. 串联两个字段

stub.PutState(visa+typeVisa, value)

这两种方法有什么区别? 就性能而言,以下哪一项是最好的?

What is the difference between these two approaches? Which of these is best in terms of performance?

推荐答案

使用组合键,您将可以访问链码中的其他方法,例如getStateByPartialCompositeKey,因此您可能会检索所有学生签证".如果您使用自己的密钥,则必须检索所有Visa,然后自己过滤该集合,或编写查询以按属性检索数据(假设您在CouchDB状态数据库中使用JSON数据.).因此,我认为性能差异在于有效的检索,而不是密钥的原始编写.

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.

CouchDB作为状态数据库上的Fabric文档中有一个很好的文档涵盖了此信息.

这篇关于复合键与单键追加字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆