CN118312532A - Hybrid storage blockchain query optimization method for business environment evaluation - Google Patents
Hybrid storage blockchain query optimization method for business environment evaluation Download PDFInfo
- Publication number
- CN118312532A CN118312532A CN202410419897.5A CN202410419897A CN118312532A CN 118312532 A CN118312532 A CN 118312532A CN 202410419897 A CN202410419897 A CN 202410419897A CN 118312532 A CN118312532 A CN 118312532A
- Authority
- CN
- China
- Prior art keywords
- query
- chain
- block
- transaction
- data
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2453—Query optimisation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2237—Vectors, bitmaps or matrices
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/28—Databases characterised by their database models, e.g. relational or object models
- G06F16/284—Relational databases
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/62—Protecting access to data via a platform, e.g. using keys or access control rules
- G06F21/6218—Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
- G06F21/6227—Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database where protection concerns the structure of data, e.g. records, types, queries
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/64—Protecting data integrity, e.g. using checksums, certificates or signatures
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q40/00—Finance; Insurance; Tax strategies; Processing of corporate or income taxes
- G06Q40/04—Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Business, Economics & Management (AREA)
- Data Mining & Analysis (AREA)
- Software Systems (AREA)
- Bioethics (AREA)
- Computer Hardware Design (AREA)
- Accounting & Taxation (AREA)
- Finance (AREA)
- Health & Medical Sciences (AREA)
- General Health & Medical Sciences (AREA)
- Strategic Management (AREA)
- Economics (AREA)
- General Business, Economics & Management (AREA)
- Marketing (AREA)
- Development Economics (AREA)
- Technology Law (AREA)
- Computational Linguistics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明涉及面向营商环境评估的混合存储区块链查询优化方法,属于区块链数据查询领域。本发明对混合区块链模型引入关系语义,对企业原始数据进行高效查询。首先,该方法将数据存储在链上和链下相结合的混合数据存储架构中,并为区块数据添加关系语义,设计三种索引机制以加速数据访问;然后,基于三种索引机制各自适用的查询类型设计相应的查询优化方法,进一步优化查询处理;最后,在区块链上为轻客户端实现了丰富的身份验证查询,用户可以验证查询结果的健全性和完整性。本发明显著降低了存储开销,对三种不同的查询类型具有较短的查询延迟,具有较好的检索性能和验证效率。
The present invention relates to a hybrid storage blockchain query optimization method for business environment assessment, and belongs to the field of blockchain data query. The present invention introduces relational semantics into the hybrid blockchain model to efficiently query the original data of the enterprise. First, the method stores the data in a hybrid data storage architecture that combines on-chain and off-chain, adds relational semantics to the block data, and designs three indexing mechanisms to accelerate data access; then, based on the query types applicable to each of the three indexing mechanisms, corresponding query optimization methods are designed to further optimize the query processing; finally, a rich identity authentication query is implemented for the light client on the blockchain, and the user can verify the soundness and integrity of the query results. The present invention significantly reduces storage overhead, has a shorter query delay for three different query types, and has better retrieval performance and verification efficiency.
Description
技术领域Technical Field
本发明属于区块链数据查询领域,特别涉及区块链查询系统设计,具体涉及一种面向营商环境评估的混合存储区块链查询优化方法设计。The present invention belongs to the field of blockchain data query, and in particular to the design of a blockchain query system, and specifically to the design of a hybrid storage blockchain query optimization method for business environment assessment.
背景技术Background technique
营商环境包括市场主体在准入、生产经营和退出过程中涉及的政务环境、市场环境、法治环境和人文环境等有关外部因素和条件的总和。良好的营商环境对于现代化经济高质量发展具有重要意义。但由于营商环境包含的信息源种类复杂,政务、市场、法治以及企业经营等数据存在信息孤立、跨域访问效率低、中心化存储易被篡改、可信度差等问题。因此,如何对企业营商环境信息高效存储和查询,提高信息的可信度和安全性,进而有效支持营商环境的评估,是领域研究的热点和难点。The business environment includes the sum of relevant external factors and conditions such as the government environment, market environment, legal environment and cultural environment involved in the process of market entities' access, production and operation, and exit. A good business environment is of great significance to the high-quality development of a modern economy. However, due to the complex types of information sources contained in the business environment, data such as government affairs, market, rule of law and business operations have problems such as information isolation, low cross-domain access efficiency, centralized storage that is easily tampered with, and poor credibility. Therefore, how to efficiently store and query enterprise business environment information, improve the credibility and security of information, and effectively support the evaluation of the business environment is a hot spot and difficulty in field research.
近年来,人们对区块链技术的兴趣广泛增加。从数据管理的角度来看,区块链可以看作是一个分布式数据库,它通过块链式数据结构存储并验证数据,辅以密码学方法保证数据传输和访问的安全性、不可篡改和不可伪造,能够很好的解决数据存储对第三方的信任问题。目前已在供应链、金融基础设施、数据共享等领域得到应用。随着区块链的广泛采用,对区块链执行分析查询的需求也越来越大,传统的区块链查询方法已经无法满足愈发复杂的领域应用场景。In recent years, people have shown a growing interest in blockchain technology. From a data management perspective, blockchain can be seen as a distributed database that stores and verifies data through a block chain data structure, supplemented by cryptographic methods to ensure the security, non-tampering and non-forgeability of data transmission and access, and can effectively solve the problem of trust in third parties for data storage. It has been applied in supply chain, financial infrastructure, data sharing and other fields. With the widespread adoption of blockchain, the demand for blockchain to perform analytical queries is also increasing, and traditional blockchain query methods can no longer meet the increasingly complex application scenarios.
相比于传统数据库丰富的查询功能,现有区块链在在查询语言和查询处理效率方面还存在以下几个方面的不足:一些方法数据语义不够丰富,现有区块链大多使用表达能力有限的Key-Value模型,查询数据时,用户只能根据区块或交易的编号或哈希值进行查询;一些方法数据操作不足,现有区块链大多将区块数据存储在Key-Value数据库或者文件系统中,无法支持交易数据上的关系操作;一些方法链上/链下数据集成困难,由于一致性和隐私性问题,用户无法使用智能合约访问链下数据。因此,设计一种高效的面向营商环境评估的混合存储区块链查询优化方法,对营商环境企业大数据高效查询具有重要意义。Compared with the rich query functions of traditional databases, the existing blockchain still has the following deficiencies in query language and query processing efficiency: some methods do not have rich data semantics. Most existing blockchains use the Key-Value model with limited expression capabilities. When querying data, users can only query based on the block or transaction number or hash value; some methods do not have sufficient data operations. Most existing blockchains store block data in Key-Value databases or file systems and cannot support relational operations on transaction data; some methods have difficulty integrating on-chain/off-chain data. Due to consistency and privacy issues, users cannot use smart contracts to access off-chain data. Therefore, designing an efficient hybrid storage blockchain query optimization method for business environment assessment is of great significance for efficient query of business environment enterprise big data.
发明内容Summary of the invention
为了解决现有营商环境区块链查询方法的不足,本发明提供一种面向营商环境评估的混合存储区块链查询优化方法,能够有效地进行营商环境企业实体及其活动的数据查询。In order to address the shortcomings of existing business environment blockchain query methods, the present invention provides a hybrid storage blockchain query optimization method for business environment assessment, which can effectively perform data queries on business environment enterprise entities and their activities.
本发明是通过以下技术方案实现的:面向营商环境评估的混合存储区块链查询优化方法,包括以下步骤:The present invention is implemented by the following technical solution: a hybrid storage blockchain query optimization method for business environment evaluation, comprising the following steps:
步骤一:构建混合存储区块链架构:混合存储区块链架构由链上复合链、链下MySQL数据库、查询客户端三个模块组成。Step 1: Build a hybrid storage blockchain architecture: The hybrid storage blockchain architecture consists of three modules: on-chain composite chain, off-chain MySQL database, and query client.
在混合存储区块链架构中,链上数据存储的是需要在所有参与者间共享的数据,即营商环境评估中评价指标对应的企业属性信息,按照区块结构组织;链下数据存储企业的隐私、大规模数据,即企业的财务信息、员工信息以及具体交易信息,由本地RDBMS管理,存储在链下关系表中;混合存储区块链架构由链上复合链、链下MySQL数据库、查询客户端三个模块组成。In the hybrid storage blockchain architecture, the on-chain data stores data that needs to be shared among all participants, that is, the enterprise attribute information corresponding to the evaluation indicators in the business environment assessment, which is organized according to the block structure; the off-chain data stores the enterprise's privacy and large-scale data, that is, the enterprise's financial information, employee information and specific transaction information, which are managed by the local RDBMS and stored in the off-chain relational table; the hybrid storage blockchain architecture consists of three modules: on-chain composite chain, off-chain MySQL database, and query client.
(1)链上复合链:由于营商环境数据类型多样,且有些数据不对外开放,设计链上复合链存储营商环境数据;复合链由公有链和联盟链组成,联盟链存储不公开数据,公有链存储公开数据;链上复合链由应用层、查询验证处理层、存储和索引层、共识层以及网络层五个部分组成。(1) On-chain composite chain: Since the types of business environment data are diverse and some data are not open to the public, an on-chain composite chain is designed to store business environment data; the composite chain consists of a public chain and a consortium chain. The consortium chain stores private data and the public chain stores public data; the on-chain composite chain consists of five parts: application layer, query verification processing layer, storage and index layer, consensus layer, and network layer.
应用层由API、访问控制和智能合约组成,访问控制在请求执行前验证请求权限,采用多通道方式保护隐私;混合存储区块链支持智能合约来定义去中心化应用程序DApp,其中嵌入了SQL语言来访问数据;查询验证处理层负责解析、优化和执行SQL查询请求,并验证查询结果的准确性和完整性;存储和索引层创建和维护索引、Merkle树、缓存的存储结构,以及区块数据的搜索、扫描和插入;由于不同的共识协议适用于不同的场景,混合存储区块链采用插件模式,允许用户根据需求选择不同的共识协议;网络层采用Gossip作为基础网络设施,提供节点之间的通信和数据传输功能。The application layer consists of API, access control and smart contracts. Access control verifies request permissions before request execution and uses a multi-channel approach to protect privacy. The hybrid storage blockchain supports smart contracts to define decentralized applications DApp, in which the SQL language is embedded to access data. The query verification processing layer is responsible for parsing, optimizing and executing SQL query requests, and verifying the accuracy and completeness of query results. The storage and indexing layer creates and maintains indexes, Merkle trees, cache storage structures, and searches, scans and inserts block data. Since different consensus protocols are suitable for different scenarios, the hybrid storage blockchain adopts a plug-in mode, allowing users to choose different consensus protocols according to their needs. The network layer uses Gossip as the basic network infrastructure to provide communication and data transmission functions between nodes.
(2)链下MySQL数据库:每个链上数据类型节点对应一个链下MySQL,存储企业对应的详细交易信息。(2) Off-chain MySQL database: Each on-chain data type node corresponds to an off-chain MySQL, which stores the detailed transaction information corresponding to the enterprise.
(3)查询客户端:由轻节点和全节点组成。全节点是完全验证和存储交易和区块的节点,存在于P2P网络中,与其他全节点交换信息,所有全节点都参与共识过程;轻节点是一个客户端,存储区块链的区块头信息,并从全节点请求其他所有内容,根据区块头中Merkle树根来验证数据的有效性。(3) Query client: It consists of light nodes and full nodes. A full node is a node that fully verifies and stores transactions and blocks. It exists in the P2P network and exchanges information with other full nodes. All full nodes participate in the consensus process. A light node is a client that stores the block header information of the blockchain and requests all other content from the full node. It verifies the validity of the data based on the Merkle tree root in the block header.
步骤二:添加关系语义:根据交易发生时间,将同一类型的交易通过统一的关系模式描述,并声明关系表模式确定交易结构。Step 2: Add relational semantics: Based on the time when the transaction occurred, describe the same type of transactions through a unified relational model, and declare the relational table model to determine the transaction structure.
为区块数据添加关系语义,支持区块数据上的丰富查询;在区块链中,根据交易发生的时间,交易被结构化并存储在区块中,交易包含两种属性:系统属性和用户自定义属性;系统属性包含交易哈希、交易发送者、交易类型、交易ID和签名,用户自定义属性包含智能合约参数;调用同种操作的交易具有相同的结构;将同一类型的交易通过统一的关系模式描述,通过声明关系表模式来确定交易结构;所有属性分为两类:系统属性和应用属性,系统属性在创建表模式时自动添加;应用属性由用户显式指定,是与应用相关的参数。Add relational semantics to block data to support rich queries on block data. In the blockchain, transactions are structured and stored in blocks according to the time when the transaction occurs. Transactions contain two attributes: system attributes and user-defined attributes. System attributes include transaction hash, transaction sender, transaction type, transaction ID and signature, and user-defined attributes include smart contract parameters. Transactions that call the same operation have the same structure. Transactions of the same type are described by a unified relational model, and the transaction structure is determined by declaring a relational table model. All attributes are divided into two categories: system attributes and application attributes. System attributes are automatically added when creating a table model. Application attributes are explicitly specified by the user and are application-related parameters.
通过发送一个特殊交易来创建表模式,通过共识算法同步节点之间的表模式信息,系统使用SQL语言来管理数据,即使用CREATE、INSERT和SELECT子句分别创建表、添加新交易和获取查询结果;支持GET BLOCK、TRACE、JOIN操作来查询区块链。The table schema is created by sending a special transaction, and the table schema information between nodes is synchronized through the consensus algorithm. The system uses SQL language to manage data, that is, using CREATE, INSERT and SELECT clauses to create tables, add new transactions and obtain query results respectively; GET BLOCK, TRACE, and JOIN operations are supported to query the blockchain.
复合链中的每个区块由区块头和区块体组成,区块头记录元信息,包括前一个区块的哈希值prevHash,该区块的区块高度blockHeight,该区块被打包时间的时间戳timestamp,区块中所有交易的Merkle树根transRoot,区块的打包者签名Signature和当前的区块哈希blockHash;区块体中包含多个交易,每个交易都包括Tid、Ts、Sig、SenID、Tname和用户自定义的应用级属性,其中Tid是交易id,Ts记录交易发送的时间,Sig保证交易的不可伪造性,SenID记录交易发送者的身份,Tname表示交易类型名称;每个交易类型都与用户定义的模式相关联,模式作为常规表进行存储和维护。Each block in the composite chain consists of a block header and a block body. The block header records meta information, including the hash value prevHash of the previous block, the block height blockHeight of the block, the timestamp of the time when the block was packaged, the Merkle tree root transRoot of all transactions in the block, the block packager signature Signature and the current block hash blockHash; the block body contains multiple transactions, each of which includes Tid, Ts, Sig, SenID, Tname and user-defined application-level attributes, where Tid is the transaction id, Ts records the time when the transaction is sent, Sig ensures the unforgeability of the transaction, SenID records the identity of the transaction sender, and Tname represents the transaction type name; each transaction type is associated with a user-defined pattern, and the pattern is stored and maintained as a regular table.
步骤三:定义查询类型:将混合存储区块链中的查询分为三类:链上查询、链下查询和链上链下联合查询。Step 3: Define query types: Divide queries in the hybrid storage blockchain into three categories: on-chain queries, off-chain queries, and on-chain and off-chain joint queries.
在混合存储区块链中,存在三种查询任务:(1)链上查询,查询区块链中存储的数据;(2)链下查询,查询链下关系数据库中的数据;(3)链上链下联合查询,同时查询链上、链下数据;链上查询可细分成三类,第一类是区块和交易查询;第二类是追溯查询,支持历史交易追溯;第三类是关系查询,借助所引入的关系语义。In a hybrid storage blockchain, there are three types of query tasks: (1) on-chain query, querying data stored in the blockchain; (2) off-chain query, querying data in the off-chain relational database; (3) on-chain and off-chain joint query, querying on-chain and off-chain data at the same time; on-chain query can be divided into three categories. The first category is block and transaction query; the second category is traceability query, which supports historical transaction tracing; the third category is relational query, which uses the introduced relational semantics.
1)区块与交易查询:对于区块查询,给定区块号,返回相应的区块;对于交易查询,给定交易号,返回交易信息。1) Block and transaction query: For block query, given the block number, the corresponding block is returned; for transaction query, given the transaction number, the transaction information is returned.
2)追溯查询:追溯查询表示为:Q=<Trace,P,[c,e]>,其中Trace表示查询类型为追溯,P表示查询条件,[c,e]表示时间窗口,其中o表示交易发送者,p表示交易类型,(SendID,o)表示SendID属性值为o,(Tname,p)表示Tname属性值为p;该查询返回在[c,e]内,满足查询条件的所有交易;支持从两个维度追溯历史交易:交易发送者维度和交易类型维度,支持三种典型的追溯操作:给定交易发送者、给定交易类型或者给定交易发送者与交易类型时的查询。2) Trace query: Trace query is expressed as: Q = <Trace, P, [c, e] >, where Trace indicates that the query type is trace, P indicates the query condition, and [c, e] indicates the time window. Where o represents the transaction sender, p represents the transaction type, (SendID,o) represents that the SendID attribute value is o, and (Tname,p) represents that the Tname attribute value is p. This query returns all transactions in [c,e] that meet the query conditions. It supports tracing historical transactions from two dimensions: the transaction sender dimension and the transaction type dimension, and supports three typical tracing operations: querying for a given transaction sender, a given transaction type, or a given transaction sender and transaction type.
3)链上关系查询:由于区块数据通过关系模型描述,传统关系数据库中的关系查询适用于区块链,用户通过关系查询方式查询所有的区块数据,通过指定时间窗口[c,e],获取该时间段内的查询结果。3) On-chain relational query: Since block data is described by a relational model, relational queries in traditional relational databases are applicable to blockchains. Users query all block data through relational queries and obtain query results within a specified time window [c, e].
有关同一实体的数据同时存储在链上和链下数据库中,通过链上链下连接操作支持链上/链下数据集成,称为联合查询;联合查询表示为:Q=<Onoff,r,s,θ,[c,e]>,其中Onoff表示查询类型为联合查询,r,s分别为链上关系表和链下关系表,θ表示等值连接条件,[c,e]表示时间窗口;该查询返回在[c,e]内,属于链上表r的交易与链下表s中的元组在谓词θ下的连接结果,对于查询“获取某一评价指标的某一属性对应的企业详细交易数据”,通过区块链上的评价指标表与链下的企业交易数据表进行连接操作获取查询结果。Data about the same entity is stored in both on-chain and off-chain databases, and on-chain/off-chain data integration is supported through on-chain and off-chain connection operations, which is called joint query; the joint query is expressed as: Q = <Onoff, r, s, θ, [c, e]>, where Onoff indicates that the query type is a joint query, r and s are the on-chain relationship table and the off-chain relationship table respectively, θ represents the equi-join condition, and [c, e] represents the time window; the query returns the connection result of the transactions belonging to the on-chain table r and the tuples in the off-chain table s in [c, e] under the predicate θ. For the query "obtain detailed enterprise transaction data corresponding to a certain attribute of a certain evaluation indicator", the query result is obtained by connecting the evaluation indicator table on the blockchain with the enterprise transaction data table off-chain.
步骤四:设计索引机制:针对混合存储区块链查询操作设计三种索引结构:区块索引、表级位图索引和层次索引。Step 4: Design index mechanism: Design three index structures for hybrid storage blockchain query operations: block index, table-level bitmap index, and hierarchical index.
同一类型的交易通过同一关系表模式来描述,链上复合链支持关系查询;设计三种索引结构:区块索引、表级位图索引和层次索引来加速数据访问,包括三种基本操作:(1)给定区块号、交易号或者时间戳获取区块;(2)获取属于某张表的所有交易数据;(3)给定查询条件下获取满足条件的交易。Transactions of the same type are described by the same relational table model, and the on-chain composite chain supports relational queries. Three index structures are designed to accelerate data access: block index, table-level bitmap index, and hierarchical index, including three basic operations: (1) Get a block given a block number, transaction number, or timestamp; (2) Get all transaction data belonging to a table; (3) Get transactions that meet the conditions under given query conditions.
区块索引适用于处理第一种操作类型,记录了区块链上的所有区块信息,支持通过区块号、交易号、时间戳查询区块信息;区块索引是一棵B+树,其搜索码为一个三元组(bid,tid,Ts),其中bid为区块号,tid为区块中的第一个交易号,交易号用于唯一地标识一笔交易,使用递增的整数标识,Ts表示区块的时间戳,叶子节点存储了指向区块存储位置的指针;对于任意两个区块bi和bj,如果区块bi的打包时间比bj早,那么(bi.tid<bj.bid)∧(bi.tid<bj.tid)∧(bi.Ts<bj.Ts)总是成立的;通过这种方式,在执行查询时给定区块号、交易号、时间戳中任意一维,得到其它两维的数据和区块的存储位置。The block index is suitable for processing the first type of operation. It records all block information on the blockchain and supports querying block information by block number, transaction number, and timestamp. The block index is a B+ tree whose search code is a triple (bid, tid, Ts), where bid is the block number, tid is the first transaction number in the block, the transaction number is used to uniquely identify a transaction and is identified by an increasing integer. Ts represents the timestamp of the block, and the leaf node stores a pointer to the block storage location. For any two blocks b i and b j , if the packaging time of block b i is earlier than that of b j , then (b i .tid < b j .bid) ∧ (b i .tid < b j .tid) ∧ (b i .Ts < b j .Ts) is always true. In this way, when executing a query, if any one of the block number, transaction number, and timestamp is given, the data of the other two dimensions and the storage location of the block can be obtained.
表级位图索引适用于处理第二种操作类型,表级位图索引记录了关系表的数据分布,用于过滤不需要读取的区块;区块链上的每张表都对应一个位图,位图中的每一位对应一个区块,位图中的第i位代表第i个区块,如果为1,那么该区块包含相应表的交易数据;反之,则不包含相应表的交易;当生成一个新表时,将添加一个新的位图,当一个新区块到达时,通过设置相应的位图来更新位图索引。Table-level bitmap indexes are suitable for processing the second type of operation. Table-level bitmap indexes record the data distribution of relational tables and are used to filter blocks that do not need to be read. Each table on the blockchain corresponds to a bitmap, and each bit in the bitmap corresponds to a block. The i-th bit in the bitmap represents the i-th block. If it is 1, then the block contains the transaction data of the corresponding table; otherwise, it does not contain transactions of the corresponding table. When a new table is generated, a new bitmap will be added. When a new block arrives, the bitmap index is updated by setting the corresponding bitmap.
层次索引适用于处理第三种操作类型,层次索引建立在指定的属性上;层次索引的第一层由一个记录属性值分布的等深直方图和一系列的索引项组成,对于离散属性,直方图中的每一个桶表示一个属性值,对于连续属性等深直方图根据交易属性值分布情况生成,桶表示连续的属性值范围,每个区块对应一个索引项,索引项记录了区块中的数据范围;第二层由每个区块索引属性上的B+树组成,区块链上存储所有的历史交易数据,最近的数据更有容易被查询,当索引占用内存过大时,将早期的索引结构存储在磁盘上,将近期的索引结构缓存在内存中。Hierarchical indexing is suitable for processing the third type of operation. Hierarchical indexing is established on specified attributes. The first layer of the hierarchical index consists of an equi-depth histogram that records the distribution of attribute values and a series of index items. For discrete attributes, each bucket in the histogram represents an attribute value. For continuous attributes, an equi-depth histogram is generated based on the distribution of transaction attribute values. Buckets represent continuous attribute value ranges. Each block corresponds to an index item, which records the data range in the block. The second layer consists of a B+ tree on the index attribute of each block. All historical transaction data is stored on the blockchain, and the most recent data is easier to query. When the index occupies too much memory, the early index structure is stored on the disk and the recent index structure is cached in the memory.
步骤五:基于索引机制的查询优化:针对追溯查询、链上连接查询和联合查询,设计查询优化方法;Step 5: Query optimization based on index mechanism: Design query optimization methods for traceability query, on-chain connection query and joint query;
基于三个索引结构优化基本查询算子的实现,包括追溯操作、链上连接操作以及联合操作,提升不同查询类型的查询性能。The implementation of basic query operators is optimized based on three index structures, including traceback operations, on-chain connection operations, and joint operations, to improve the query performance of different query types.
(1)追溯查询:(1) Traceability query:
追溯操作是一元操作,从两个维度进行交易追溯,即交易发送者维度与交易类型维度,表示谁发送了交易以及哪个交易完成了;当追溯某一发送者发出的所有交易时,通过该发送者对应的位图获取包含发送者的交易的区块,然后扫描这些区块获取查询结果,从而避免扫描所有区块。The tracing operation is a unary operation that traces transactions from two dimensions, namely the transaction sender dimension and the transaction type dimension, indicating who sent the transaction and which transaction was completed; when tracing all transactions sent by a sender, the blocks containing the sender's transactions are obtained through the bitmap corresponding to the sender, and then these blocks are scanned to obtain the query results, thereby avoiding scanning all blocks.
(2)链上连接查询:(2) On-chain connection query:
链上连接操作是二元操作,用于支持交易之间的可追溯性;链上连接查询表示为Q=<On,r,s,θ,[c,e]>,On表示链上连接查询,r,s表示连接表,θ表示等值连接条件,[c,e]表示时间窗口;采用扫描哈希连接算法实现连接,对于表r与表s上的连接查询,首先,扫描所有的区块,并使用哈希函数h构造r和s的交易分区,对于s的每个分区si,在si上建立一个哈希索引;对于分区中的每一笔交易,通过探查该哈希索引来获取满足连接条件的交易,从而获得连接结果,通过使用表级位图索引,只有包含r或s的交易的区块需要被读取。The on-chain connection operation is a binary operation used to support traceability between transactions. The on-chain connection query is expressed as Q = <On, r, s, θ, [c, e]>, where On represents the on-chain connection query, r, s represent the connection table, θ represents the equi-connection condition, and [c, e] represents the time window. The connection is implemented using the scanning hash connection algorithm. For the connection query on table r and table s, first, all blocks are scanned, and the transaction partitions of r and s are constructed using the hash function h. For each partition s i of s, a hash index is established on s i . For each transaction in the partition, the hash index is explored to obtain the transactions that meet the connection condition, thereby obtaining the connection result. By using the table-level bitmap index, only the blocks containing transactions of r or s need to be read.
(3)联合查询:(3)Joint query:
联合操作是二元操作,用于链上和链下数据的集成,在链上、链下表上进行的连接操作,对于联合查询Q=<Onoff,r,s,r.attr=s.attr,[c,e]>,通过扫描哈希连接算法实现;首先,通过ODBC、JDBC接口从链下MySQL数据库获取关系表s的数据,然后使用表级位图索引读取包含属于r的交易的区块,最后,对连接结果执行哈希连接算法获取查询结果。The join operation is a binary operation used to integrate on-chain and off-chain data. It is a join operation performed on on-chain and off-chain tables. For the join query Q = <Onoff, r, s, r.attr = s.attr, [c, e]>, it is implemented through the scanning hash join algorithm. First, the data of the relational table s is obtained from the off-chain MySQL database through the ODBC and JDBC interfaces, and then the table-level bitmap index is used to read the block containing the transaction belonging to r. Finally, the hash join algorithm is executed on the join result to obtain the query result.
步骤六:轻客户端查询验证:设计基于分层索引的认证索引结构和验证查询处理方法,得到轻客户端查询结果。Step 6: Light client query verification: Design an authentication index structure and verification query processing method based on hierarchical indexing to obtain light client query results.
轻客户端只存储区块头,以验证来自不可信节点的数据的正确性;将在层次索引的基础上设计一种验证索引结构,提出基于该索引的查询验证方法;对于层次索引,用MB树取代第二层的B+树,称这种索引为验证层次索引ALI,由于每个区块都维护第二层索引,因此每个区块的高度都对应一个快照,支持多版本Merkle根的快照验证。The light client only stores the block header to verify the correctness of the data from the untrusted node. A verification index structure will be designed based on the hierarchical index, and a query verification method based on the index will be proposed. For the hierarchical index, the second-layer B+ tree will be replaced by the MB tree, and this index is called the verification hierarchical index ALI. Since each block maintains the second-layer index, the height of each block corresponds to a snapshot, which supports snapshot verification of multiple versions of Merkle roots.
轻客户端查询验证流程如下:The light client query verification process is as follows:
(1)轻客户端向随机选择的全节点发送查询请求;(1) The light client sends a query request to a randomly selected full node;
(2)全节点根据ALI执行查询,并在VO中添加验证信息和区块高度h;(2) The full node executes the query based on ALI and adds verification information and block height h in VO;
(3)全节点向轻客户端返回VO和R;(3) The full node returns VO and R to the light client;
(4)客户端将查询和从第一阶段收到的h一起发送到另一个随机选择的节点,即辅助全节点;(4) The client sends the query together with h received from the first phase to another randomly selected node, the auxiliary full node;
(5)辅助全节点根据查询和h获取区块,并根据查询访问的MB树的根生成摘要,然后将摘要返回给轻客户端;(5) The auxiliary full node obtains the block based on the query and h, generates a summary based on the root of the MB tree accessed by the query, and then returns the summary to the light client;
(6)轻客户端使用接收到的VO重新构造摘要,并与正确的摘要进行比较,以验证查询结果R的健全性和完整性。(6) The light client reconstructs the digest using the received VO and compares it with the correct digest to verify the soundness and integrity of the query result R.
轻客户端通过从多个节点采样来降低风险,假设拜占庭节点与总节点的数量之比为p,客户端向n个辅助节点发出n个请求,接收m个相同的摘要,考虑最多有max个拜占庭节点,摘要错误的概率θ如上描述,用户通过调整n和m实现不同的可信度。Light clients reduce risks by sampling from multiple nodes. Assuming that the ratio of the number of Byzantine nodes to the total number of nodes is p, the client sends n requests to n auxiliary nodes and receives m identical summaries. Considering that there are at most max Byzantine nodes, the probability θ of a summary error is as described above. Users can achieve different credibility by adjusting n and m.
本发明创造的有益效果为:本发明对混合存储区块链引入关系语义,对企业原始数据进行高效查询。首先,将数据存储在链上和链下相结合的混合数据存储架构中,并为区块数据添加关系语义,设计三种索引机制以加速数据访问;然后,基于三种索引机制各自适用的查询类型设计相应的查询优化方法,进一步优化查询处理;最后,在区块链上为轻客户端实现了丰富的身份验证查询,用户可以验证查询结果的健全性和完整性。本发明显著降低了存储开销,对三种不同的查询类型具有较短的查询延迟,具有较好的检索性能和验证效率。The beneficial effects created by the present invention are as follows: the present invention introduces relational semantics into the hybrid storage blockchain and performs efficient query on the original data of the enterprise. First, the data is stored in a hybrid data storage architecture that combines on-chain and off-chain, and relational semantics are added to the block data, and three indexing mechanisms are designed to accelerate data access; then, corresponding query optimization methods are designed based on the query types applicable to each of the three indexing mechanisms to further optimize query processing; finally, a rich identity authentication query is implemented for the light client on the blockchain, and the user can verify the soundness and integrity of the query results. The present invention significantly reduces storage overhead, has a shorter query delay for three different query types, and has better retrieval performance and verification efficiency.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1为本发明混合存储区块链架构示意图;FIG1 is a schematic diagram of a hybrid storage blockchain architecture of the present invention;
图2为本发明营商环境评估交易关系表示例图;FIG2 is an example diagram of a business environment evaluation transaction relationship representation of the present invention;
图3为本发明索引机制示意图;FIG3 is a schematic diagram of an indexing mechanism of the present invention;
图4为本发明轻节点和全节点通信示意图。FIG4 is a schematic diagram of communication between a light node and a full node according to the present invention.
具体实施方式Detailed ways
面向营商环境评估的混合存储区块链查询优化方法,包括如下步骤:A hybrid storage blockchain query optimization method for business environment evaluation includes the following steps:
步骤1:构建混合存储区块链架构:混合存储区块链架构由链上复合链、链下MySQL数据库、查询客户端三个模块组成;Step 1: Build a hybrid storage blockchain architecture: The hybrid storage blockchain architecture consists of three modules: on-chain composite chain, off-chain MySQL database, and query client;
具体为:在混合存储区块链架构中,链上数据存储的是需要在所有参与者间共享的数据,即营商环境评估中评价指标对应的企业属性信息,按照区块结构组织;链下数据存储企业的隐私、大规模数据,即企业的财务信息、员工信息以及具体交易信息,由本地RDBMS管理,存储在链下关系表中。混合存储区块链架构由链上复合链、链下MySQL数据库、查询客户端三个模块组成。Specifically, in the hybrid storage blockchain architecture, the on-chain data stores data that needs to be shared among all participants, that is, the enterprise attribute information corresponding to the evaluation indicators in the business environment assessment, which is organized according to the block structure; the off-chain data stores the privacy and large-scale data of the enterprise, that is, the financial information, employee information and specific transaction information of the enterprise, which is managed by the local RDBMS and stored in the off-chain relational table. The hybrid storage blockchain architecture consists of three modules: on-chain composite chain, off-chain MySQL database, and query client.
(1)链上复合链:由于营商环境数据类型多样,且有些数据不对外开放,如司法、政务等类型数据,因此,设计链上复合链存储营商环境数据。复合链由公有链和联盟链组成,联盟链存储不公开数据,公有链存储公开数据。链上复合链模块由应用层、查询验证处理层、存储和索引层、共识层以及网络层五个部分组成。(1) On-chain composite chain: Since the types of business environment data are diverse and some data are not open to the public, such as judicial and government data, an on-chain composite chain is designed to store business environment data. The composite chain consists of a public chain and a consortium chain. The consortium chain stores private data and the public chain stores public data. The on-chain composite chain module consists of five parts: application layer, query verification processing layer, storage and index layer, consensus layer, and network layer.
应用层由API、访问控制和智能合约组成,访问控制在请求执行前验证请求权限,采用多通道方式保护隐私;混合存储区块链支持智能合约来定义去中心化应用程序DApp,其中嵌入了SQL语言来访问数据。查询验证处理层负责解析、优化和执行SQL查询请求,并验证查询结果的准确性和完整性。存储和索引层创建和维护索引、Merkle树、缓存的存储结构,以及区块数据的搜索、扫描和插入。由于不同的共识协议适用于不同的场景,混合存储区块链采用插件模式,允许用户根据需求选择不同的共识协议。网络层采用Gossip作为基础网络设施,提供节点之间的通信和数据传输功能。The application layer consists of API, access control and smart contracts. Access control verifies the request permission before the request is executed and uses a multi-channel approach to protect privacy. The hybrid storage blockchain supports smart contracts to define decentralized applications DApp, which embeds the SQL language to access data. The query verification processing layer is responsible for parsing, optimizing and executing SQL query requests, and verifying the accuracy and completeness of query results. The storage and indexing layer creates and maintains indexes, Merkle trees, cache storage structures, and searches, scans and inserts block data. Since different consensus protocols are suitable for different scenarios, the hybrid storage blockchain adopts a plug-in mode, allowing users to choose different consensus protocols according to their needs. The network layer uses Gossip as the basic network facility to provide communication and data transmission functions between nodes.
(2)链下MySQL数据库:每个链上数据类型节点对应一个链下MySQL,存储企业对应的详细交易信息。(2) Off-chain MySQL database: Each on-chain data type node corresponds to an off-chain MySQL, which stores the detailed transaction information corresponding to the enterprise.
(3)查询客户端:由轻节点和全节点组成。全节点是完全验证和存储交易和区块的节点,如政府部门用户。它存在于P2P网络中,与其他全节点交换信息。所有全节点都参与共识过程。轻节点是一个客户端,如普通企业用户,它存储区块链的区块头信息,并从全节点请求其他所有内容,然后根据区块头中Merkle树的根来验证数据的有效性。(3) Query client: It consists of light nodes and full nodes. A full node is a node that fully verifies and stores transactions and blocks, such as government users. It exists in the P2P network and exchanges information with other full nodes. All full nodes participate in the consensus process. A light node is a client, such as an ordinary enterprise user, which stores the block header information of the blockchain and requests everything else from the full node, and then verifies the validity of the data based on the root of the Merkle tree in the block header.
步骤2:添加关系语义:根据交易发生时间,将同一类型的交易通过统一的关系模式描述,并声明关系表模式确定交易结构;Step 2: Add relational semantics: Based on the transaction occurrence time, describe transactions of the same type through a unified relational model, and declare the relational table model to determine the transaction structure;
具体为:数据语义的缺失使得区块链难以支持复杂查询,为了支持区块数据上的丰富查询,本发明为区块数据添加关系语义。在区块链中,根据交易发生的时间,交易被结构化并存储在区块中,交易一般包含两种属性:系统属性和用户自定义属性。系统属性包含交易哈希、交易发送者等,用户自定义的属性包含智能合约参数。调用同种操作的交易具有相同的结构。基于此,将同一类型的交易通过统一的关系模式描述,通过声明关系表模式来确定交易结构,属性类型可以是字符、数字或者其它类型。所有属性分为两类:系统属性和应用属性。系统属性在创建表模式时自动添加,如交易类型、交易发送者、交易ID和签名;应用属性由用户显式指定,通常是与应用相关的参数。Specifically: the lack of data semantics makes it difficult for blockchain to support complex queries. In order to support rich queries on block data, the present invention adds relational semantics to block data. In the blockchain, transactions are structured and stored in blocks according to the time when the transaction occurs. Transactions generally contain two attributes: system attributes and user-defined attributes. System attributes include transaction hash, transaction sender, etc., and user-defined attributes include smart contract parameters. Transactions that call the same operation have the same structure. Based on this, transactions of the same type are described by a unified relational model, and the transaction structure is determined by declaring a relational table model. The attribute type can be character, number or other types. All attributes are divided into two categories: system attributes and application attributes. System attributes are automatically added when creating a table model, such as transaction type, transaction sender, transaction ID and signature; application attributes are explicitly specified by the user, usually application-related parameters.
通过发送一个特殊交易来创建表模式,通过共识算法同步节点之间的表模式信息。同时,系统使用SQL语言来管理数据,即使用CREATE、INSERT和SELECT子句分别创建表、添加新交易和获取查询结果。还支持GET BLOCK、TRACE、JOIN操作来查询区块链。The table schema is created by sending a special transaction, and the table schema information between nodes is synchronized through the consensus algorithm. At the same time, the system uses SQL language to manage data, that is, using CREATE, INSERT and SELECT clauses to create tables, add new transactions and obtain query results respectively. It also supports GET BLOCK, TRACE, and JOIN operations to query the blockchain.
复合链中的每个区块由区块头和区块体组成。区块头记录元信息,包括前一个区块的哈希值prevHash,该区块的区块高度blockHeight,该区块被打包时间的时间戳timestamp,区块中所有交易的Merkle树根transRoot,区块的打包者签名Signature和当前的区块哈希blockHash。区块体中包含多个交易,每个交易都有几个属性,包括Tid、Ts、Sig、SenID、Tname和一些用户自定义的应用级属性,其中Tid是交易id,Ts记录交易发送的时间,Sig保证交易的不可伪造性,SenID记录交易发送者的身份,Tname表示交易类型名称。每个交易类型都与用户定义的模式相关联,模式可以作为常规表进行存储和维护。Each block in the composite chain consists of a block header and a block body. The block header records meta information, including the hash value prevHash of the previous block, the block height blockHeight of the block, the timestamp of the time when the block was packaged, the Merkle tree root transRoot of all transactions in the block, the block packager signature Signature and the current block hash blockHash. The block body contains multiple transactions, each of which has several attributes, including Tid, Ts, Sig, SenID, Tname and some user-defined application-level attributes, where Tid is the transaction id, Ts records the time when the transaction was sent, Sig ensures the unforgeability of the transaction, SenID records the identity of the transaction sender, and Tname represents the transaction type name. Each transaction type is associated with a user-defined pattern, which can be stored and maintained as a regular table.
步骤3:定义查询类型:将混合存储区块链中的查询分为三类:链上查询、链下查询和链上链下联合查询;Step 3: Define query types: Divide queries in the hybrid storage blockchain into three categories: on-chain queries, off-chain queries, and on-chain and off-chain joint queries;
具体为:在混合存储区块链中,存在三种查询任务:(1)链上查询,即查询区块链中存储的数据;(2)链下查询,查询链下关系数据库中的数据;(3)链上链下联合查询,即同时查询链上、链下数据。由于链下查询可直接在本地数据库执行,本发明主要面向第一种和第三种查询类型。链上查询又可细分成三类,第一类是区块和交易查询;第二类是追溯查询,支持历史交易追溯;第三类是关系查询,借助所引入的关系语义。Specifically, in a hybrid storage blockchain, there are three types of query tasks: (1) on-chain query, i.e. querying data stored in the blockchain; (2) off-chain query, querying data in the off-chain relational database; (3) on-chain and off-chain joint query, i.e. querying on-chain and off-chain data at the same time. Since off-chain queries can be executed directly in the local database, the present invention is mainly aimed at the first and third query types. On-chain queries can be further divided into three categories. The first category is block and transaction queries; the second category is traceability queries, which support historical transaction tracing; and the third category is relational queries, which use the introduced relational semantics.
1)区块与交易查询。区块与交易查询是区块链的基本查询,对于区块查询,给定区块号,返回相应的区块。对于交易查询,给定交易号,返回交易信息。1) Block and transaction query. Block and transaction query is the basic query of blockchain. For block query, given the block number, the corresponding block is returned. For transaction query, given the transaction number, the transaction information is returned.
2)追溯查询。追溯查询表示为:Q=<Trace,P,[c,e]>,其中Trace表示查询类型为追溯,P表示查询条件,[c,e]表示时间窗口。其中o表示交易发送者,p表示交易类型,(SendID,o)表示SendID属性值为o,(Tname,p)表示Tname属性值为p。该查询返回在[c,e]内,满足查询条件的所有交易。本发明支持从两个维度追溯历史交易,即交易发送者维度和交易类型维度,支持三种典型的追溯操作:给定交易发送者、给定交易类型或者给定交易发送者与交易类型时的查询。2) Trace query: Trace query is expressed as: Q = <Trace, P, [c, e]>, where Trace indicates that the query type is trace, P indicates the query condition, and [c, e] indicates the time window. Where o represents the transaction sender, p represents the transaction type, (SendID,o) represents that the SendID attribute value is o, and (Tname,p) represents that the Tname attribute value is p. This query returns all transactions in [c,e] that meet the query conditions. The present invention supports tracing historical transactions from two dimensions, namely, the transaction sender dimension and the transaction type dimension, and supports three typical tracing operations: query for a given transaction sender, a given transaction type, or a given transaction sender and transaction type.
3)链上关系查询。由于区块数据通过关系模型描述,因此,传统关系数据库中的关系查询也适用于区块链。用户可以通过关系查询方式查询所有的区块数据,通过指定时间窗口[c,e],还可以获取指定时间段内的查询结果。3) On-chain relational query. Since block data is described by relational models, relational queries in traditional relational databases are also applicable to blockchains. Users can query all block data through relational queries, and can also obtain query results within a specified time period by specifying a time window [c, e].
有关同一实体的数据同时存储在链上和链下数据库中,本发明通过链上链下连接操作支持链上/链下数据集成,称之为联合查询。联合查询表示为:Q=<Onoff,r,s,θ,[c,e]>,其中Onoff表示查询类型为联合查询,r,s分别为链上关系表和链下关系表,θ表示等值连接条件,[c,e]表示时间窗口。该查询返回在[c,e]内,属于链上表r的交易与链下表s中的元组在谓词θ下的连接结果。例如,对于查询“获取某一评价指标的某一属性对应的企业详细交易数据”,可以通过区块链上的评价指标表与链下的企业交易数据表进行连接操作获取查询结果。Data about the same entity is stored in both on-chain and off-chain databases. The present invention supports on-chain/off-chain data integration through on-chain and off-chain connection operations, which is called joint query. Joint query is expressed as: Q = <Onoff, r, s, θ, [c, e]>, where Onoff indicates that the query type is a joint query, r and s are the on-chain relationship table and the off-chain relationship table, respectively, θ represents the equivalent connection condition, and [c, e] represents the time window. The query returns the connection result of the transaction belonging to the on-chain table r and the tuple in the off-chain table s in [c, e] under the predicate θ. For example, for the query "obtain detailed enterprise transaction data corresponding to a certain attribute of a certain evaluation indicator", the query result can be obtained by connecting the evaluation indicator table on the blockchain with the enterprise transaction data table off the chain.
步骤4:设计索引机制:针对混合存储区块链主要的查询操作设计三种写入高效的索引结构:区块索引、表级位图索引和层次索引;Step 4: Design index mechanism: Design three index structures with high write efficiency for the main query operations of hybrid storage blockchain: block index, table-level bitmap index and hierarchical index;
具体为:同一类型的交易通过同一关系表模式来描述,因此链上复合链可以支持关系查询。但相比于传统数据库,区块链系统在数据存储方式上还有很大不同。不同类型的交易根据打包规则被打包在同一区块中进行共识,并物理上存储在一起,属于同一张表的交易在物理上分布在多个区块中。查询一张表的数据需要逐个扫描区块获取查询结果,查询效率低下。为了提升面向区块存储的查询性能,本发明设计了索引结构来加速数据访问,主要面向三种基本操作:(1)给定区块号、交易号或者时间戳获取区块;(2)获取属于某张表的所有交易数据;(3)给定查询条件下获取满足条件的交易。在区块链中,数据更新以区块为单位,单个区块可能会引起大量的索引更新,影响系统的写入性能;同时,由于区块链存储了所有的历史交易,而用户可能查询特定时间段内的交易,所以索引结构设计还需支持基于时间窗口的查询。因此,本发明提出三种写入高效的索引结构:区块索引、表级位图索引和层次索引。Specifically, transactions of the same type are described by the same relational table model, so the on-chain composite chain can support relational queries. However, compared with traditional databases, blockchain systems are very different in data storage methods. Different types of transactions are packaged in the same block according to the packaging rules for consensus and physically stored together. Transactions belonging to the same table are physically distributed in multiple blocks. To query the data of a table, it is necessary to scan the blocks one by one to obtain the query results, which is inefficient. In order to improve the query performance of block storage, the present invention designs an index structure to accelerate data access, mainly for three basic operations: (1) obtaining a block given a block number, transaction number or timestamp; (2) obtaining all transaction data belonging to a table; (3) obtaining transactions that meet the conditions under given query conditions. In the blockchain, data updates are based on blocks, and a single block may cause a large number of index updates, affecting the write performance of the system; at the same time, since the blockchain stores all historical transactions, and users may query transactions within a specific time period, the index structure design also needs to support queries based on time windows. Therefore, the present invention proposes three index structures with efficient writing: block index, table-level bitmap index and hierarchical index.
区块索引适用于处理第一种操作类型,其记录了区块链上的所有区块信息,支持通过区块号、交易号、时间戳查询区块信息。区块索引是一棵B+树,其搜索码为一个三元组(bid,tid,Ts),其中bid为区块号,tid为区块中的第一个交易号,交易号用于唯一地标识一笔交易,此处使用递增的整数标识,Ts表示区块的时间戳,叶子节点存储了指向区块存储位置的指针。对于任意两个区块bi和bj,如果区块bi的打包时间比bj早,那么(bi.bid<bj.bid)∧(bi.tid<bj.tid)∧(bi.Ts<bj.Ts)总是成立的。通过这种方式,在执行查询时给定区块号、交易号、时间戳中任意一维,即可得到其它两维的数据和区块的存储位置。The block index is suitable for processing the first type of operation. It records all block information on the blockchain and supports querying block information by block number, transaction number, and timestamp. The block index is a B+ tree, and its search code is a triple (bid, tid, Ts), where bid is the block number, tid is the first transaction number in the block, and the transaction number is used to uniquely identify a transaction. Here, an increasing integer is used to identify it. Ts represents the timestamp of the block, and the leaf node stores a pointer to the storage location of the block. For any two blocks b i and b j , if the packaging time of block b i is earlier than that of b j , then (b i .bid < b j .bid) ∧ (b i .tid < b j .tid) ∧ (b i .Ts < b j .Ts) is always true. In this way, when executing a query, if any one of the block number, transaction number, and timestamp is given, the data of the other two dimensions and the storage location of the block can be obtained.
表级位图索引适用于处理第二种操作类型,表级位图索引记录了关系表的数据分布,可以用于过滤不需要读取的区块,提升查询性能。区块链上的每张表都对应一个位图,该位图中的每一位对应一个区块,位图中的第i位代表第i个区块,如果为1,那么该区块包含相应表的交易数据。反之,则不包含相应表的交易。因此,对于一个表查询请求,查找位图索引可以避免扫描所有区块。当生成一个新表时,将添加一个新的位图。当一个新区块到达时,通过设置相应的位图来更新位图索引。Table-level bitmap indexes are suitable for processing the second type of operation. Table-level bitmap indexes record the data distribution of relational tables and can be used to filter blocks that do not need to be read, thereby improving query performance. Each table on the blockchain corresponds to a bitmap, and each bit in the bitmap corresponds to a block. The i-th bit in the bitmap represents the i-th block. If it is 1, then the block contains the transaction data of the corresponding table. Otherwise, it does not contain transactions for the corresponding table. Therefore, for a table query request, looking up the bitmap index can avoid scanning all blocks. When a new table is generated, a new bitmap is added. When a new block arrives, the bitmap index is updated by setting the corresponding bitmap.
层次索引适用于处理第三种操作类型,层次索引建立在指定的属性上,以加快特定属性上范围查询的速度。层次索引的第一层由一个记录属性值分布的等深直方图和一系列的索引项组成,对于离散属性,直方图中的每一个桶表示一个属性值,对于连续属性等深直方图根据交易属性值分布情况生成,桶表示连续的属性值范围,每个区块对应一个索引项,索引项记录了区块中的数据范围。第二层由每个区块索引属性上的B+树组成。区块链上存储所有的历史交易数据,最近的数据更有可能被查询,因此,当索引占用内存过大时,早期的索引结构可以存储在磁盘上,将近期的索引结构缓存在内存中。Hierarchical indexes are suitable for processing the third type of operation. Hierarchical indexes are built on specified attributes to speed up range queries on specific attributes. The first layer of the hierarchical index consists of an equal-depth histogram that records the distribution of attribute values and a series of index items. For discrete attributes, each bucket in the histogram represents an attribute value. For continuous attributes, the equal-depth histogram is generated based on the distribution of transaction attribute values. The bucket represents a continuous range of attribute values. Each block corresponds to an index item, which records the data range in the block. The second layer consists of a B+ tree on the index attribute of each block. All historical transaction data is stored on the blockchain, and the most recent data is more likely to be queried. Therefore, when the index occupies too much memory, the early index structure can be stored on the disk and the recent index structure can be cached in memory.
步骤5:基于索引机制的查询优化:针对追溯查询、链上连接查询和联合查询,设计相应的查询优化方法;Step 5: Query optimization based on index mechanism: Design corresponding query optimization methods for traceability query, on-chain connection query and joint query;
具体为:每个交易类型在逻辑上对应于一个表,基本的关系运算如project,select,cartesian product等操作也可以被复合链查询支持。然而,与MySQL不同的是,同一表中的数据在物理上不是连续存储的,而可能在物理上分布到多个不相邻的区块中。因此,基于区块链的存储模式,基本操作的执行效率非常低,本发明提出基于上述三个索引结构优化了一些基本查询算子的实现,包括追溯操作、链上连接操作以及联合操作以提升不同查询类型的查询性能。Specifically, each transaction type logically corresponds to a table, and basic relational operations such as project, select, cartesian product, etc. can also be supported by composite chain queries. However, unlike MySQL, the data in the same table is not physically stored continuously, but may be physically distributed to multiple non-adjacent blocks. Therefore, based on the storage mode of blockchain, the execution efficiency of basic operations is very low. The present invention proposes to optimize the implementation of some basic query operators based on the above three index structures, including tracing operations, on-chain connection operations, and joint operations to improve the query performance of different query types.
(1)追溯查询:(1) Traceability query:
追溯操作是一元操作,旨在从两个维度进行交易追溯,即交易发送者维度与交易类型维度,意味着谁发送了交易以及哪个交易完成了。追溯查询可以通过扫描所有区块并检查区块中的所有交易实现,但这种方式查询效率低下。通过位图索引可以优化查询性能,例如追溯某一发送者发出的所有交易,通过该发送者对应的位图可以获取包含发送者的交易的区块,然后扫描这些区块获取查询结果,从而避免扫描所有区块。The traceback operation is a unary operation that aims to trace transactions from two dimensions, namely the transaction sender dimension and the transaction type dimension, which means who sent the transaction and which transaction was completed. The traceback query can be implemented by scanning all blocks and checking all transactions in the blocks, but this query efficiency is low. The query performance can be optimized through the bitmap index. For example, all transactions sent by a sender can be traced back. The block containing the sender's transaction can be obtained through the bitmap corresponding to the sender, and then these blocks can be scanned to obtain the query results, thereby avoiding scanning all blocks.
(2)链上连接查询:(2) On-chain connection query:
链上连接操作是二元操作,其可以用于支持交易之间的可追溯性。链上连接查询表示为Q=<On,r,s,θ,[c,e]>,On表示链上连接查询,r,s表示连接表,θ表示等值连接条件,[c,e]表示时间窗口。传统的连接算法,如区块嵌套循环连接等算法由于数据分散存储导致查询开销巨大无法直接应用在区块链中。本发明采用扫描哈希连接算法实现连接,对于表r与表s上的连接查询,首先,扫描所有的区块,并使用哈希函数h构造r和s的交易分区,对于s的每个分区si,在si上建立一个哈希索引。对于分区中的每一笔交易,通过探查该哈希索引来获取满足连接条件的交易,从而获得连接结果。通过使用表级位图索引,可以提升连接查询的性能,因为只有包含r或s的交易的区块需要被读取,从而提高查询速度。The on-chain connection operation is a binary operation that can be used to support traceability between transactions. The on-chain connection query is expressed as Q = <On, r, s, θ, [c, e]>, where On represents the on-chain connection query, r, s represent the connection table, θ represents the equivalent connection condition, and [c, e] represents the time window. Traditional connection algorithms, such as block nested loop connection algorithms, cannot be directly applied in blockchains due to the huge query overhead caused by decentralized data storage. The present invention uses a scanning hash connection algorithm to achieve connection. For connection queries on tables r and s, first, all blocks are scanned, and the transaction partitions of r and s are constructed using the hash function h. For each partition s i of s, a hash index is established on s i . For each transaction in the partition, the hash index is explored to obtain transactions that meet the connection conditions, thereby obtaining the connection result. By using a table-level bitmap index, the performance of the connection query can be improved, because only the blocks containing transactions of r or s need to be read, thereby improving the query speed.
(3)联合查询:(3)Joint query:
联合操作也是二元操作,用于链上和链下的数据集成,其本质上是在链上、链下表上进行的连接操作。对于联合查询Q=<Onoff,r,s,r.attr=s.attr,[c,e]>,也可以通过扫描哈希连接算法实现。首先,通过ODBC、JDBC接口从链下MySQL数据库获取关系表s的数据,然后使用位图索引读取包含属于r的交易的区块。最后,对连接结果执行哈希连接算法获取查询结果。The union operation is also a binary operation used for data integration on and off the chain. It is essentially a join operation on the on-chain and off-chain tables. For the union query Q = <Onoff, r, s, r.attr = s.attr, [c, e]>, it can also be implemented by scanning the hash join algorithm. First, the data of the relational table s is obtained from the off-chain MySQL database through the ODBC and JDBC interfaces, and then the block containing the transaction belonging to r is read using the bitmap index. Finally, the hash join algorithm is executed on the connection result to obtain the query result.
步骤6:轻客户端查询验证:设计基于层次索引的验证索引结构和验证查询处理方法,保证轻客户端查询结果的健全性和完整性。Step 6: Light client query verification: Design a verification index structure and verification query processing method based on hierarchical indexing to ensure the soundness and completeness of the light client query results.
具体为:轻客户端只存储区块头,以验证来自不可信节点的数据的正确性。传统方法通过扫描所有区块来查询数据,重建已访问区块的Merkle哈希树的根,就可以验证数据的正确性。然而,这种扫描方式效率过低,例如,对于范围查询,为了保证查询结果的健壮性和完整性,需要将所有区块返回给客户端。因此,为满足资源有限的查询用户的需求,本发明将在层次索引的基础上设计一种验证索引结构,并提出基于该索引的查询验证方法。Specifically, the light client only stores the block header to verify the correctness of the data from the untrusted node. The traditional method queries data by scanning all blocks and rebuilding the root of the Merkle hash tree of the accessed block to verify the correctness of the data. However, this scanning method is too inefficient. For example, for range queries, in order to ensure the robustness and integrity of the query results, all blocks need to be returned to the client. Therefore, in order to meet the needs of query users with limited resources, the present invention will design a verification index structure based on the hierarchical index and propose a query verification method based on the index.
Merkle B-tree(MB-tree)是B+tree和Merkle Hash Tree(MHT)的结合体,可以保证索引访问的查询结果的健壮性和完整性。其中,每个叶节点包含一个数据记录的哈希摘要,每个内部节点存储其子节点派生的哈希摘要。在查询过程中,轻节点需要验证其他全节点发送的查询结果。但由于交易执行速度不同,不同节点的数据可能不一致。因此,不能直接采用MB树,因为它无法支持多版本Merkle根的快照验证。为了支持轻客户端的验证查询,本发明修改了层次索引,用MB树取代第二层的B+树,称这种索引为验证层次索引(ALI)。由于每个区块都维护第二层索引,因此每个区块的高度都对应一个快照。Merkle B-tree (MB-tree) is a combination of B+tree and Merkle Hash Tree (MHT), which can ensure the robustness and integrity of the query results of index access. Among them, each leaf node contains a hash summary of a data record, and each internal node stores the hash summary derived from its child node. During the query process, the light node needs to verify the query results sent by other full nodes. However, due to different transaction execution speeds, the data of different nodes may be inconsistent. Therefore, the MB tree cannot be used directly because it cannot support snapshot verification of multiple versions of Merkle roots. In order to support verification queries of light clients, the present invention modifies the hierarchical index and replaces the second-level B+ tree with the MB tree. This index is called the verification hierarchical index (ALI). Since each block maintains the second-level index, the height of each block corresponds to a snapshot.
轻客户端查询验证流程如下:The light client query verification process is as follows:
(1)轻客户端向随机选择的全节点发送查询请求;(1) The light client sends a query request to a randomly selected full node;
(2)全节点根据ALI执行查询,并在VO中添加验证信息和区块高度h;(2) The full node executes the query based on the ALI and adds the verification information and block height h in the VO;
(3)全节点向轻客户端返回VO和R;(3) The full node returns VO and R to the light client;
(4)客户端将查询和从第一阶段收到的h一起发送到另一个随机选择的节点(辅助全节点);(4) The client sends the query together with h received from the first phase to another randomly selected node (auxiliary full node);
(5)辅助全节点根据查询和h获取区块,并根据查询访问的MB树的根生成摘要,然后将摘要返回给轻客户端;(5) The auxiliary full node obtains the block based on the query and h, generates a summary based on the root of the MB tree accessed by the query, and then returns the summary to the light client;
(6)轻客户端使用接收到的VO重新构造摘要,并将其与正确的摘要进行比较,以验证查询结果R的健全性和完整性。(6) The light client reconstructs the digest using the received VO and compares it with the correct digest to verify the soundness and integrity of the query result R.
在某些情况下,辅助节点也可能是不可信的,为了处理这种情况,轻客户端可以通过从多个节点采样来降低风险。假设拜占庭节点与总节点的数量之比为p,客户端向n个辅助节点发出n个请求,接收m个相同的摘要。考虑最多有max个拜占庭节点。摘要错误的概率θ如下描述,用户可以通过调整n和m来实现不同的可信度。然后,客户端可以使用接收到的VO重新构造摘要,并将其与正确的摘要进行比较,以验证查询结果。In some cases, auxiliary nodes may also be untrustworthy. To handle this situation, light clients can reduce the risk by sampling from multiple nodes. Assuming that the ratio of the number of Byzantine nodes to the total number of nodes is p, the client sends n requests to n auxiliary nodes and receives m identical summaries. Consider that there are at most max Byzantine nodes. The probability θ of a summary error is described as follows, and users can achieve different levels of credibility by adjusting n and m. The client can then reconstruct the summary using the received VO and compare it with the correct summary to verify the query result.
由于本发明提出的面向营商环境评估的混合存储区块链查询优化方法考虑了链上和链下混合存储以及为区块数据添加关系语义,故面向营商环境评估的混合存储区块链查询优化方法具有较短的查询延迟,较好的检索性能和验证效率。Since the hybrid storage blockchain query optimization method for business environment assessment proposed in the present invention takes into account on-chain and off-chain hybrid storage and adds relational semantics to block data, the hybrid storage blockchain query optimization method for business environment assessment has shorter query latency, better retrieval performance and verification efficiency.
Claims (7)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410419897.5A CN118312532A (en) | 2024-04-09 | 2024-04-09 | Hybrid storage blockchain query optimization method for business environment evaluation |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410419897.5A CN118312532A (en) | 2024-04-09 | 2024-04-09 | Hybrid storage blockchain query optimization method for business environment evaluation |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN118312532A true CN118312532A (en) | 2024-07-09 |
Family
ID=91723338
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410419897.5A Pending CN118312532A (en) | 2024-04-09 | 2024-04-09 | Hybrid storage blockchain query optimization method for business environment evaluation |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN118312532A (en) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119760014A (en) * | 2024-11-28 | 2025-04-04 | 辽宁大学 | A fast retrieval and storage method for blockchain data based on online learning machine |
| CN120179650A (en) * | 2025-03-17 | 2025-06-20 | 晟安信息技术有限公司 | A trusted query configuration method and system for blockchain PB-level multimodal data |
-
2024
- 2024-04-09 CN CN202410419897.5A patent/CN118312532A/en active Pending
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119760014A (en) * | 2024-11-28 | 2025-04-04 | 辽宁大学 | A fast retrieval and storage method for blockchain data based on online learning machine |
| CN120179650A (en) * | 2025-03-17 | 2025-06-20 | 晟安信息技术有限公司 | A trusted query configuration method and system for blockchain PB-level multimodal data |
| CN120179650B (en) * | 2025-03-17 | 2025-11-28 | 晟安信息技术有限公司 | A trusted query configuration method and system for blockchain petabyte-scale multimodal data |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN106528775B (en) | Private block chain operation support system supporting logic multi-chain and working method thereof | |
| US8762395B2 (en) | Evaluating event-generated data using append-only tables | |
| US6502088B1 (en) | Method and system for improved access to non-relational databases | |
| US6085189A (en) | Database system and method for supporting current of cursor updates and deletes from a select query from one or more updatable tables in single node and MPP environments | |
| US20100114935A1 (en) | Populating a multi-relational enterprise social network with disparate source data | |
| EP1446737B1 (en) | An efficient index structure to access hierarchical data in a relational database system | |
| CN113704248B (en) | Block chain query optimization method based on external index | |
| US7693845B2 (en) | Database systems, methods and computer program products using type based selective foreign key association to represent multiple but exclusive relationships in relational databases | |
| CN101710336A (en) | Method for accelerating data processing by using relational middleware | |
| Jin et al. | Making RDBMSs efficient on graph workloads through predefined joins | |
| Ma et al. | G-SQL: Fast query processing via graph exploration | |
| CN121092532A (en) | Cross-system full-link metadata processing method and device | |
| US12373436B2 (en) | Data query method and apparatus based on Doris, storage medium and device | |
| Li et al. | A hybrid storage blockchain-based query efficiency enhancement method for business environment evaluation | |
| CN120179650A (en) | A trusted query configuration method and system for blockchain PB-level multimodal data | |
| CN114168620B (en) | Execution plan processing method and device | |
| CN115221558B (en) | Digital object efficient evidence-storing method and system for multi-subject scientific and technological resources | |
| Lim et al. | Query optimization and processing in federated database systems | |
| Yao et al. | VGQ: Enabling verifiable graph queries on blockchain systems | |
| CN117851413B (en) | Data operation method, device, electronic equipment, storage medium and program product | |
| Marinho et al. | Using a hybrid approach to data management in relational database and blockchain: A case study on the e-health domain | |
| Liu et al. | EntityManager: Managing dirty data based on entity resolution | |
| Yao et al. | Efficient blockchain data trusty provenance based on the w3c prov model | |
| CN112364189A (en) | Electronic certificate application method based on ES service | |
| Hu et al. | BCTree: A Fast and Verifiable Tracing Approach for Blockchain-Enabled Reputation Management in Industrial IoT Networks |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |