WO2022140936A1 - Metering method and device for data query workload in blockchain, and terminal - Google Patents

Metering method and device for data query workload in blockchain, and terminal Download PDF

Info

Publication number
WO2022140936A1
WO2022140936A1 PCT/CN2020/140246 CN2020140246W WO2022140936A1 WO 2022140936 A1 WO2022140936 A1 WO 2022140936A1 CN 2020140246 W CN2020140246 W CN 2020140246W WO 2022140936 A1 WO2022140936 A1 WO 2022140936A1
Authority
WO
WIPO (PCT)
Prior art keywords
sql query
workload
data
query statement
execution
Prior art date
Application number
PCT/CN2020/140246
Other languages
French (fr)
Chinese (zh)
Inventor
李伟
邱炜伟
张珂杰
黄方蕾
胡麦芳
Original Assignee
杭州趣链科技有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 杭州趣链科技有限公司 filed Critical 杭州趣链科技有限公司
Priority to PCT/CN2020/140246 priority Critical patent/WO2022140936A1/en
Publication of WO2022140936A1 publication Critical patent/WO2022140936A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying

Definitions

  • the present application belongs to the technical field of blockchain, and in particular relates to a method, device and terminal for measuring the workload of data query in the blockchain.
  • the blockchain network adopts the Proof-of-Work (PoW) mechanism, which requires all nodes in the blockchain network to perform calculations according to the preset Proof-of-Work method, and the node that first obtains the result has the The right to package blockchain transaction information and receive rewards.
  • PoW Proof-of-Work
  • the smart contract execution engine needs to execute the smart contract to read data from the blockchain ledger.
  • the smart contract When executing the smart contract, it needs to execute several different instructions according to the logical bottom layer of the smart contract, such as data operations, data read.
  • the execution of the existing SQL query is a complex logic, and the workload cannot be measured from the dimension of the instruction.
  • the execution engine of smart contracts cannot adapt to the workload measurement mechanism of the blockchain when applying SQL queries, and cannot integrate SQL queries with the blockchain platform.
  • the embodiments of the present application provide a method, device and terminal for measuring the workload of data query in the blockchain, so as to solve the problem that the execution engine of the smart contract in the prior art cannot adapt to the blockchain when applying SQL query.
  • the workload measurement mechanism cannot integrate SQL queries with the blockchain platform.
  • a first aspect of the embodiments of the present application provides a method for measuring data query workload in a blockchain, including:
  • the SQL query statement is input into the built-in SQL query engine, and the SQL query statement is executed by the SQL query engine;
  • the workload in the process of executing the SQL query statement by the SQL query engine is accumulated.
  • a second aspect of the embodiments of the present application provides a device for measuring data query workload in a blockchain, including:
  • a generation module used for executing the smart contract according to the blockchain transaction generated by the user, and generating the SQL query statement corresponding to the smart contract;
  • a query module for inputting the SQL query statement into a built-in SQL query engine, and executing the SQL query statement through the SQL query engine;
  • an acquisition module for acquiring the execution operation of the SQL query engine from the execution process of the SQL query statement
  • a matching module configured to match the workload corresponding to the execution operation from a preset workload table based on the execution operation
  • a workload calculation module configured to accumulate the workload in the process of executing the SQL query statement by the SQL query engine based on the workload.
  • a third aspect of the embodiments of the present application provides a terminal, including a memory, a processor, and a computer program stored in the memory and running on the processor, which is implemented when the processor executes the computer program The steps of the method according to the first aspect.
  • a fourth aspect of the embodiments of the present application provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.
  • a fifth aspect of the present application provides a computer program product, which, when the computer program product runs on a terminal, causes the terminal to execute the steps of the method in the above-mentioned first aspect.
  • the smart contract is executed according to the blockchain transaction generated by the user, the SQL query statement corresponding to the smart contract is generated, the SQL query statement is input into the built-in SQL query engine, and the SQL query statement is executed.
  • the engine executes the SQL query statement, obtains the execution operation of the SQL query engine from the execution process of the SQL query statement, and based on the execution operation, matches the workload corresponding to the execution operation from the preset workload table, and based on the workload, Accumulate the workload in the process of executing the SQL query statement by the SQL query engine.
  • the SQL query statement corresponding to the smart contract is generated when the smart contract is executed, the SQL query statement is executed through the built-in SQL query engine, and the execution process is monitored, and the SQL query engine is obtained when the SQL query statement is executed.
  • Corresponding execution operations and match these execution operations in the preset workload table to obtain the workload corresponding to these execution operations based on the record content in the workload table, and accumulate them. From the query process
  • the dimension of the execution operation itself involved measures the workload, adapts to the workload measurement mechanism of the blockchain, and realizes the integration between the SQL query and the blockchain platform.
  • FIG. 1 is a flow chart 1 of a method for measuring data query workload in a blockchain provided by an embodiment of the present application;
  • FIG. 2 is a second flowchart of a method for measuring data query workload in a blockchain provided by an embodiment of the present application
  • FIG. 3 is a structural example diagram of a layered executor provided by an embodiment of the present application.
  • FIG. 4 is a structural diagram of a device for measuring data query workload in a blockchain provided by an embodiment of the present application.
  • FIG. 5 is a structural diagram of a terminal provided by an embodiment of the present application.
  • FIG. 1 is a flowchart 1 of a method for measuring data query workload in a blockchain provided by an embodiment of the present application. As shown in Figure 1, a method for measuring the workload of data query in blockchain, the method includes the following steps:
  • Step 101 Execute the smart contract according to the blockchain transaction generated by the user, and generate a SQL query statement corresponding to the smart contract.
  • the code of the corresponding smart contract needs to be obtained and executed, and the corresponding SQL query statement is generated based on the contract logic during the execution process.
  • the SQL query statement is used to read the target data from the blockchain ledger, and the target data is used to implement the execution of the smart contract.
  • the implementation process of this step 101 is specifically:
  • the input parameters are, for example, data content to be modified, transaction information to be added, and the like.
  • the smart contract code to be executed is the smart contract code corresponding to the input parameters parsed in the blockchain transaction.
  • the blockchain system receives the blockchain transaction generated by the user, parses the blockchain transaction, verifies the legality of the format, and obtains the input parameters after several preprocessing.
  • Preprocessing includes but is not limited to parameter parsing and consensus packaging.
  • the smart contract execution engine reads the smart contract code to be executed from the blockchain ledger according to the input parameters, and uses the above code and parameters to initialize the smart contract virtual machine. Start executing the smart contract through the smart contract virtual machine, first run some contract logic, accumulate some workload, generate SQL query statement according to the contract logic, and input it into the SQL query engine built in the smart contract execution engine.
  • Step 102 Input the SQL query statement into the built-in SQL query engine, and execute the SQL query statement through the SQL query engine.
  • the SQL query engine executes an SQL query statement, it can preprocess the SQL query statement, for example, disassemble it to obtain query conditions, and then generate a corresponding executor based on the disassembled query conditions, and execute the block execution through the executor. Data query action in the chain ledger.
  • the method of matching data from the blockchain ledger can be to construct a specific primary key according to the contract logic and data structure in the smart contract, and match the target data with the target primary key and meet the set matching conditions from the blockchain ledger.
  • Step 103 Acquire the execution operation of the SQL query engine from the execution process of the SQL query statement.
  • the execution operation is multiple.
  • the execution operation of the SQL query engine is, for example: the aforementioned operation of preprocessing the SQL query statement, and the data execution operation executed by the matching executor, and the data execution operation may be a string comparison operation, an integer comparison operation, a data execution operation read operations, etc.
  • Step 104 based on the execution operation, match the workload corresponding to the execution operation from a preset workload table.
  • the workload table is table structure data used to measure the workload consumed by the SQL query engine in the process of executing the SQL query statement. Specifically, the table structure data is used to measure the workload consumed by the preprocessing and executor of the SQL query engine in the process of executing the SQL query statement.
  • the workload table the workload of processing input data of a certain size is recorded for each preprocessor, and the workload of processing input data of a certain size is recorded for each executor.
  • the total workload is accumulated by looking up the table according to the actual processing process of processing the current SQL query statement.
  • the workload table needs to be stored on the blockchain ledger and loaded when the SQL query engine is initialized.
  • the SQL query engine is initialized.
  • unified changes need to be made in the form of blockchain transactions. If the work sheet is not recorded on the blockchain ledger, the same default configuration is required between blockchain nodes.
  • Step 105 Based on the workload, the workload in the process of executing the SQL query statement by the SQL query engine is accumulated.
  • a workload measurement mechanism based on the processing process is constructed in the SQL query engine, so that the smart contract virtual machine with the workload mechanism can build this SQL query engine, and then provide the SQL query function for the smart contract.
  • the workload is set for the processing processes such as scanning, conditional filtering, and connection involved in the execution of the SQL query statement, and is recorded in the workload table in advance.
  • the total workload is accumulated, so that the execution engine of the smart contract can be embedded with an efficient native SQL query engine while maintaining the original workload mechanism, thereby improving the reading of smart contract data.
  • the friendliness of the interface improves the efficiency of blockchain contract development.
  • the method further includes:
  • the SQL query engine executes the SQL query statement, if the total amount of work corresponding to the execution operation exceeds the threshold, the SQL query engine is controlled to output the data query result.
  • the setting of the workload mechanism is mainly to solve the problem of downtime, avoid the situation that the contract call cannot be terminated, and also avoid excessive system resources consumed by a single execution.
  • the upper limit of the workload of the SQL query engine needs to be set.
  • the upper limit of the workload that can be used to query data using the built-in SQL query engine is specified by the parameter.
  • the workload cap can be an input or a unified configuration made in a user blockchain transaction.
  • the data is returned in a readable data structure in the smart contract for the contract logic.
  • the smart contract is executed according to the blockchain transaction generated by the user, the SQL query statement corresponding to the smart contract is generated, the SQL query statement is input into the built-in SQL query engine, and the SQL query engine is used to execute the SQL Query statement, obtain the execution operation of the SQL query engine from the execution process of the SQL query statement, based on the execution operation, match the workload corresponding to the execution operation from the preset workload table, and based on the workload, the SQL query engine The workload in the process of executing the SQL query statement is accumulated.
  • the SQL query statement corresponding to the smart contract is generated when the smart contract is executed, the SQL query statement is executed through the built-in SQL query engine, and the execution process is monitored, and the SQL query engine is obtained when the SQL query statement is executed.
  • Corresponding execution operations and match these execution operations in the preset workload table to obtain the workload corresponding to these execution operations based on the record content in the workload table, and accumulate them. From the query process
  • the dimension of the execution operation itself involved measures the workload, adapts to the workload measurement mechanism of the blockchain, and realizes the integration between the SQL query and the blockchain platform.
  • the embodiments of the present application also provide different implementations of the method for measuring the workload of data query in the blockchain.
  • FIG. 2 is a second flowchart of a method for measuring data query workload in a blockchain provided by an embodiment of the present application. As shown in Figure 2, a method for measuring the workload of data query in blockchain, the method includes the following steps:
  • Step 201 Execute the smart contract according to the blockchain transaction generated by the user, and generate a SQL query statement corresponding to the smart contract.
  • Step 202 Input the SQL query statement into the built-in SQL query engine, and execute the SQL query statement through the SQL query engine.
  • step 102 The implementation process of this step is the same as the implementation process of step 102 in the foregoing embodiment, and details are not repeated here.
  • Step 203 from the process of executing the SQL query statement, obtain the preprocessing operation of the SQL query statement by the SQL query engine, and obtain the SQL query engine to preprocess the SQL query statement to generate a hierarchical executor, and pass the hierarchical executor During the hierarchical execution of the preprocessed SQL query statement, the data of each executor performs operations.
  • the acquired execution operations of the SQL query engine specifically include: preprocessing operations on the SQL query statement and data execution operations of each executor in the hierarchical executors.
  • the SQL query engine first uses the preprocessor to preprocess the SQL query statement, and then generates a hierarchical executor based on the preprocessing result.
  • Preprocessing includes, but is not limited to, parsing of SQL query statements, index selection, and execution optimization.
  • Executor is a general term for the logical unit of sub-processes in the SQL query execution process, including but not limited to data operations, comparisons, and connections.
  • Hierarchical refers to the relationship between the executor and the executor.
  • the output of the lower executor is used as the input of the upper executor.
  • the browser is connected to the SQL query interface provided by the SQL query engine to the smart contract, and returns data query results through this interface.
  • the data acquisition in the smart contract can be regarded as a recursive call from the top-level executor to the bottom-level executor, and the data in the execution result of the lower-level executor is returned to the upper-level executor for further matching processing. Called and returns a certain amount of data.
  • the SQL query engine After the SQL query engine receives the SQL query statement from the SQL query interface, it starts to call down to acquire and process data.
  • the lowermost executor reads the data of the set number of rows from the blockchain ledger, and the lowermost executor takes the data as the input of the adjacent upper executor, and the adjacent
  • the upper-layer executor performs the data comparison operation that has been assigned to the executor of this layer, and obtains the data that meets the corresponding query conditions based on the comparison result, and continues to input the data to the adjacent upper-layer executor for the corresponding query.
  • the data is subjected to another data comparison and judgment until the execution of the top-level executor is completed, and the final qualified data is output as the result of the SQL query.
  • Step 204 based on the execution operation, match the workload corresponding to the execution operation from a preset workload table.
  • the recorded content includes: the workload consumed by each preprocessor for processing a unit amount of input data, the amount of work consumed by each preprocessor processing a unit amount of input data workload.
  • the unit amount is, for example, one byte.
  • different preprocessors correspond to different preprocessing methods, and different executors perform different data processing operations.
  • the execution operations include: preprocessing operations on SQL query statements and data execution operations on each executor in the hierarchical executors.
  • the steps include: acquiring the first operation data amount when the preprocessing operation is performed; acquiring the first processing work corresponding to the unit operation data amount of the preprocessing operation from the preset workload table The first workload of the preprocessing operation is obtained according to the first operation data volume and the first processing workload.
  • this step 204 also includes: according to the execution sequence of the data execution operations of the executors, every time an executor is detected to execute the data execution operation, acquiring the second data execution operation of the current executor when the data execution operation is performed. operation data volume; from the preset workload table, obtain the second processing workload of the unit operation data volume corresponding to the data execution operation of the current executor; according to the second operation data volume and the second processing workload, Get the second workload of the current executor.
  • Step 205 Based on the workload, the workload in the process of executing the SQL query statement by the SQL query engine is accumulated.
  • this step is specifically: accumulating the first workload in the preceding steps and the second workload obtained in sequence.
  • the workload of each pair of executors is obtained once according to the method in the preceding steps, and a corresponding second workload is obtained.
  • a corresponding second workload is obtained.
  • different executors are sequentially obtained.
  • the second workload corresponding to the executor is accumulated with the first workload, and the total workload in the process of executing the SQL query statement by the SQL query engine is obtained.
  • table T The relational data in the following table 2 is pre-stored on the blockchain ledger through blockchain transactions, which is called table T, where A is the primary key, columns A and C are 8-byte integers, and column B is each A 1-byte string of characters. Only the primary key index.
  • the encoding results of the above table are stored in the form of key-value pairs in the blockchain ledger.
  • the data in the above table is stored in the blockchain ledger with a length of 14 bytes.
  • the SQL query engine uses the SQL parsing preprocessor to parse the SQL query statement.
  • the input of the query statement is 38 bytes.
  • Table 1 the preset workload table (Table 1), a total of 380 units of workload are generated, and the required amount of work to execute the query statement is generated.
  • Hierarchical executors each executor returns 5 pieces of data at a time and makes recursive calls. A hierarchical structure is shown in Figure 3.
  • the structure of the layered executor includes: the uppermost string comparison executor, which is connected with the SQL engine interface to realize the acquisition of SQL query statements; the lowermost blockchain ledger reading executor, which is connected with the blockchain ledger , which implements data reading from the blockchain; an integer comparison executor located in the middle layer.
  • the bottom-level blockchain ledger reading executor constructs the primary key row by row according to the primary key range, reads the data in Table 2, a total of 5 rows of data and 90 bytes, and parses it into an integer returned to the upper layer in the corresponding format Comparing the actuators and combining the data in Table 1, it can be concluded that 180 units of workload will be consumed, and the cumulative consumption of 560 units of workload at this time.
  • the integer comparison executor compares the processing data in column C in Table 2. It needs to process the 5 rows of data returned by the blockchain ledger reading executor, and perform 5 comparisons of 8-byte integers. Combined with the data in Table 1, we get The output will consume 40 units of workload, and the cumulative consumption of 600 units of workload at this time. Filter out the rows that satisfy the condition C>100, and get 3 rows of data whose primary keys are 3, 4, and 5. At this time, less than 5 pieces of data need to be returned, continue to call the lower-level executor (that is, the blockchain ledger reading executor). If the data provided by the lower-level is not received, the 3 pieces of data are directly returned to the upper-level string comparison. Actuator.
  • the process in this embodiment allows the blockchain smart contract execution engine to embed a SQL query engine compatible with the workload mechanism, and allows the blockchain contract to read relational data in a more flexible, efficient and standard manner.
  • FIG. 4 is a structural diagram of a device for measuring data query workload in a blockchain provided by an embodiment of the present application. For convenience of description, only parts related to the embodiment of the present application are shown.
  • the measuring device 400 of the data query workload in the blockchain includes:
  • the generating module 401 is used for executing the smart contract according to the blockchain transaction generated by the user, and generating the SQL query statement corresponding to the smart contract;
  • a query module 402 configured to input the SQL query statement into a built-in SQL query engine, and execute the SQL query statement through the SQL query engine;
  • An obtaining module 403, configured to obtain the execution operation of the SQL query engine from the execution process of the SQL query statement;
  • a matching module 404 configured to match the workload corresponding to the execution operation from a preset workload table based on the execution operation;
  • the workload calculation module 405 is configured to accumulate the workload in the process of executing the SQL query statement by the SQL query engine based on the workload.
  • the acquisition module 403 is specifically used for:
  • the matching module 404 is specifically used for:
  • the first workload of the preprocessing operation is obtained.
  • the matching module 404 is also specifically used for:
  • each time an executor is detected to execute the data execution operation obtain the second operation data amount of the current executor when the data execution operation is performed;
  • the second workload of the current executor is obtained.
  • the workload calculation module 405 is specifically used for:
  • the first workload and the sequentially acquired second workload are accumulated.
  • the generation module 401 is specifically used for:
  • the smart contract virtual machine is controlled to generate an SQL query statement according to the contract logic of the smart contract in the smart contract code.
  • the device also includes: an output module for:
  • the SQL query engine During the process of executing the SQL query statement by the SQL query engine, if the total amount of work corresponding to the execution operation exceeds a threshold, the SQL query engine is controlled to output a data query result.
  • the device for measuring the workload of data query in the blockchain provided by the embodiment of the present application can realize the various processes of the above-mentioned embodiments of the method for measuring the workload of data query in the blockchain, and can achieve the same technical effect. In order to avoid repetition, I won't go into details here.
  • FIG. 5 is a structural diagram of a terminal provided by an embodiment of the present application.
  • the terminal 5 of this embodiment includes: at least one processor 50 (only one is shown in FIG. 5 ), a memory 51 , and a memory 51 stored in the memory 51 and available on the at least one processor 50
  • the running computer program 52 when the processor 50 executes the computer program 52, implements the steps in any of the foregoing method embodiments.
  • the terminal 5 may be a computing device such as a desktop computer, a notebook, a palmtop computer and a cloud server.
  • the terminal 5 may include, but is not limited to, a processor 50 and a memory 51 .
  • FIG. 5 is only an example of the terminal 5, and does not constitute a limitation on the terminal 5. It may include more or less components than the one shown in the figure, or combine some components, or different components, such as
  • the terminal may also include input and output devices, network access devices, buses, and the like.
  • the processor 50 may be a central processing unit (Central Processing Unit, CPU), or other general-purpose processors, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
  • a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
  • the memory 51 may be an internal storage unit of the terminal 5 , such as a hard disk or a memory of the terminal 5 .
  • the memory 51 may also be an external storage device of the terminal 5, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card equipped on the terminal 5, Flash card (Flash Card) and so on.
  • the memory 51 may also include both an internal storage unit of the terminal 5 and an external storage device.
  • the memory 51 is used to store the computer program and other programs and data required by the terminal.
  • the memory 51 can also be used to temporarily store data that has been output or will be output.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units may be implemented in the form of hardware, or may be implemented in the form of software functional units.
  • the integrated modules/units if implemented in the form of software functional units and sold or used as independent products, may be stored in a computer-readable storage medium.
  • the present application can implement all or part of the processes in the methods of the above embodiments, and can also be completed by instructing the relevant hardware through a computer program.
  • the computer program can be stored in a computer-readable storage medium, and the computer When the program is executed by the processor, the steps of the foregoing method embodiments can be implemented.
  • the computer program includes computer program code, and the computer program code may be in the form of source code, object code, executable file or some intermediate form, and the like.
  • the computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, removable hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory) , Random Access Memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable media may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, the computer-readable media Electric carrier signals and telecommunication signals are not included.

Abstract

The present application is applicable to the technical field of blockchains and provides a metering method and device for data query workload in a blockchain, and a terminal. The method comprises: executing an intelligent contract according to a blockchain transaction generated by a user, and generating an SQL query statement corresponding to the intelligent contract; inputting the SQL query statement into a built-in SQL query engine, and executing the SQL query statement by means of the SQL query engine; obtaining an execution operation of the SQL query engine from an SQL query statement execution process; matching, on the basis of the execution operation, workload corresponding to the execution operation from a preset workload table; and accumulating, on the basis of the workload, the workload in the process of executing the SQL query statement by the SQL query engine. The scheme can adapt to a workload metering mechanism of a blockchain, and fusion between SQL query and a blockchain platform is realized.

Description

区块链中数据查询工作量的计量方法、装置及终端Method, device and terminal for measuring data query workload in blockchain 技术领域technical field
本申请属于区块链技术领域,尤其涉及一种区块链中数据查询工作量的计量方法、装置及终端。The present application belongs to the technical field of blockchain, and in particular relates to a method, device and terminal for measuring the workload of data query in the blockchain.
背景技术Background technique
区块链网络采用了工作量证明机制(Proof-of-Work,PoW),它要求区块链网络中的所有节点按照预设的工作量证明方法进行计算,率先得出结果的节点则拥有了对区块链交易信息进行打包以及获得奖励的权利。The blockchain network adopts the Proof-of-Work (PoW) mechanism, which requires all nodes in the blockchain network to perform calculations according to the preset Proof-of-Work method, and the node that first obtains the result has the The right to package blockchain transaction information and receive rewards.
现有的区块链网络中,智能合约执行引擎需要执行智能合约从区块链账本上读取数据,在执行智能合约时需要根据智能合约的逻辑底层执行若干不同的指令,例如数据运算、数据读取。每执行一个指令,就产生了一定的工作量,该些工作量与指令相结合容易进行量化统计。In the existing blockchain network, the smart contract execution engine needs to execute the smart contract to read data from the blockchain ledger. When executing the smart contract, it needs to execute several different instructions according to the logical bottom layer of the smart contract, such as data operations, data read. Each time an instruction is executed, a certain workload is generated, and the combination of the workload and the instruction is easy to perform quantitative statistics.
受限于工作量证明机制的应用,在现有的区块链网络中,基于智能合约从区块链账本中读取数据的方式相比于其他数据库应用来说,能够直接使用的数据结构相对有限,缺乏对关系型数据读取的支持,数据查询效率低下,因此提出将现有的SQL(Structured Query Language,结构化查询语言)查询引入至区块链平台中进行应用。Limited by the application of the workload proof mechanism, in the existing blockchain network, the way of reading data from the blockchain ledger based on smart contracts, compared with other database applications, the data structure that can be directly used is relatively Limited, lack of support for relational data reading, and low data query efficiency, so it is proposed to introduce existing SQL (Structured Query Language, Structured Query Language) queries into the blockchain platform for application.
而现有的SQL查询的执行是一个复杂逻辑,无法从指令的维度度量工作量。智能合约的执行引擎在应用SQL查询时不能适应区块链的工作量计量机制,无法将SQL查询与区块链平台进行融合。The execution of the existing SQL query is a complex logic, and the workload cannot be measured from the dimension of the instruction. The execution engine of smart contracts cannot adapt to the workload measurement mechanism of the blockchain when applying SQL queries, and cannot integrate SQL queries with the blockchain platform.
技术问题technical problem
有鉴于此,本申请实施例提供了一种区块链中数据查询工作量的计量方法、装置及终端,以解决现有技术中智能合约的执行引擎在应用SQL查询时不能适应区块链的工作量计量机制,无法将SQL查询与区块链平台进行融合的问题。In view of this, the embodiments of the present application provide a method, device and terminal for measuring the workload of data query in the blockchain, so as to solve the problem that the execution engine of the smart contract in the prior art cannot adapt to the blockchain when applying SQL query. The workload measurement mechanism cannot integrate SQL queries with the blockchain platform.
技术解决方案technical solutions
本申请实施例的第一方面提供了一种区块链中数据查询工作量的计量方法,包括:A first aspect of the embodiments of the present application provides a method for measuring data query workload in a blockchain, including:
根据用户产生的区块链交易,执行智能合约,生成与所述智能合约对应的SQL查询语句;According to the blockchain transaction generated by the user, execute the smart contract, and generate the SQL query statement corresponding to the smart contract;
将所述SQL查询语句输入至内置的SQL查询引擎,通过所述SQL查询引擎执行所述SQL查询语句;The SQL query statement is input into the built-in SQL query engine, and the SQL query statement is executed by the SQL query engine;
从所述SQL查询语句执行过程中,获取所述SQL查询引擎的执行操作;From the execution process of the SQL query statement, obtain the execution operation of the SQL query engine;
基于所述执行操作,从预设的工作量表中匹配与所述执行操作对应的工作量;Based on the execution operation, matching the workload corresponding to the execution operation from a preset workload table;
基于所述工作量,对所述SQL查询引擎执行所述SQL查询语句过程中的工作量进行累计。Based on the workload, the workload in the process of executing the SQL query statement by the SQL query engine is accumulated.
本申请实施例的第二方面提供了一种区块链中数据查询工作量的计量装置,包括:A second aspect of the embodiments of the present application provides a device for measuring data query workload in a blockchain, including:
生成模块,用于根据用户产生的区块链交易,执行智能合约,生成与所述智能合约对应的SQL查询语句;A generation module, used for executing the smart contract according to the blockchain transaction generated by the user, and generating the SQL query statement corresponding to the smart contract;
查询模块,用于将所述SQL查询语句输入至内置的SQL查询引擎,通过所述SQL查询引擎执行所述SQL查询语句;A query module, for inputting the SQL query statement into a built-in SQL query engine, and executing the SQL query statement through the SQL query engine;
获取模块,用于从所述SQL查询语句执行过程中,获取所述SQL查询引擎的执行操作;an acquisition module, for acquiring the execution operation of the SQL query engine from the execution process of the SQL query statement;
匹配模块,用于基于所述执行操作,从预设的工作量表中匹配与所述执行操作对应的工作量;a matching module, configured to match the workload corresponding to the execution operation from a preset workload table based on the execution operation;
工作量计算模块,用于基于所述工作量,对所述SQL查询引擎执行所述SQL查询语句过程中的工作量进行累计。A workload calculation module, configured to accumulate the workload in the process of executing the SQL query statement by the SQL query engine based on the workload.
本申请实施例的第三方面提供了一种终端,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如第一方面所述方法的步骤。A third aspect of the embodiments of the present application provides a terminal, including a memory, a processor, and a computer program stored in the memory and running on the processor, which is implemented when the processor executes the computer program The steps of the method according to the first aspect.
本申请实施例的第四方面提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现如第一方面所述方法的步骤。A fourth aspect of the embodiments of the present application provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.
本申请的第五方面提供了一种计算机程序产品,当所述计算机程序产品在终端上运行时,使得所述终端执行上述第一方面所述方法的步骤。A fifth aspect of the present application provides a computer program product, which, when the computer program product runs on a terminal, causes the terminal to execute the steps of the method in the above-mentioned first aspect.
有益效果beneficial effect
由上可见,本申请实施例中,通过根据用户产生的区块链交易,执行智能合约,生成与该智能合约对应的SQL查询语句,将SQL查询语句输入至内置的SQL查询引擎,通过SQL查询引擎执行该SQL查询语句,从SQL查询语句执行过程中,获取SQL查询引擎的执行操作,基于该执行操作,从预设的工作量表中匹配与执行操作对应的工作量,基于该工作量,对SQL查询引擎执行SQL查询语句过程中的工作量进行累计。该过程通过在执行智能合约时生成与智能合约对应的SQL查询语句,通过内置的SQL查询引擎对该SQL查询语句进行执行,并对该执行过程进行监控,获取SQL查询引擎在执行SQL查询语句时对应的执行操作,并将该些执行操作在预设置的工作量表中进行匹配,以基于工作量表中的记录内容得到与该些执行操作对应的工作量,并进行累计,从查询过程中涉及的执行操作本身这一维度去度量工作量,适应区块链的工作量计量机制,实现SQL查询与区块链平台之间的融合。As can be seen from the above, in the embodiment of the present application, the smart contract is executed according to the blockchain transaction generated by the user, the SQL query statement corresponding to the smart contract is generated, the SQL query statement is input into the built-in SQL query engine, and the SQL query statement is executed. The engine executes the SQL query statement, obtains the execution operation of the SQL query engine from the execution process of the SQL query statement, and based on the execution operation, matches the workload corresponding to the execution operation from the preset workload table, and based on the workload, Accumulate the workload in the process of executing the SQL query statement by the SQL query engine. In this process, the SQL query statement corresponding to the smart contract is generated when the smart contract is executed, the SQL query statement is executed through the built-in SQL query engine, and the execution process is monitored, and the SQL query engine is obtained when the SQL query statement is executed. Corresponding execution operations, and match these execution operations in the preset workload table to obtain the workload corresponding to these execution operations based on the record content in the workload table, and accumulate them. From the query process The dimension of the execution operation itself involved measures the workload, adapts to the workload measurement mechanism of the blockchain, and realizes the integration between the SQL query and the blockchain platform.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the accompanying drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only for the present application. In some embodiments, for those of ordinary skill in the art, other drawings can also be obtained according to these drawings without any creative effort.
图1是本申请实施例提供的一种区块链中数据查询工作量的计量方法的流程图一;1 is a flow chart 1 of a method for measuring data query workload in a blockchain provided by an embodiment of the present application;
图2是本申请实施例提供的一种区块链中数据查询工作量的计量方法的流程图二;2 is a second flowchart of a method for measuring data query workload in a blockchain provided by an embodiment of the present application;
图3是本申请实施例提供的一种分层执行器的结构实例图;3 is a structural example diagram of a layered executor provided by an embodiment of the present application;
图4是本申请实施例提供的一种区块链中数据查询工作量的计量装置的结构图;4 is a structural diagram of a device for measuring data query workload in a blockchain provided by an embodiment of the present application;
图5是本申请实施例提供的一种终端的结构图。FIG. 5 is a structural diagram of a terminal provided by an embodiment of the present application.
本发明的实施方式Embodiments of the present invention
以为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the objectives, technical solutions and advantages of the present application more clearly understood, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application.
应当理解,当在本说明书和所附权利要求书中使用时,术语“包括”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。It is to be understood that, when used in this specification and the appended claims, the term "comprising" indicates the presence of the described feature, integer, step, operation, element and/or component, but does not exclude one or more other features , whole, step, operation, element, component and/or the presence or addition of a collection thereof.
为了说明本申请所述的技术方案,下面通过具体实施例来进行说明。In order to illustrate the technical solutions described in the present application, the following specific embodiments are used for description.
参见图1,图1是本申请实施例提供的一种区块链中数据查询工作量的计量方法的流程图一。如图1所示,一种区块链中数据查询工作量的计量方法,该方法包括以下步骤:Referring to FIG. 1 , FIG. 1 is a flowchart 1 of a method for measuring data query workload in a blockchain provided by an embodiment of the present application. As shown in Figure 1, a method for measuring the workload of data query in blockchain, the method includes the following steps:
步骤101,根据用户产生的区块链交易,执行智能合约,生成与该智能合约对应的SQL查询语句。Step 101: Execute the smart contract according to the blockchain transaction generated by the user, and generate a SQL query statement corresponding to the smart contract.
其中,在获取到用户产生的区块链交易后,需要对其对应的智能合约的代码进行获取并执行,在执行过程中基于合约逻辑生成对应的SQL查询语句。该SQL查询语句用于从区块链账本中读取目标数据,该目标数据用于实现智能合约的执行。Among them, after obtaining the blockchain transaction generated by the user, the code of the corresponding smart contract needs to be obtained and executed, and the corresponding SQL query statement is generated based on the contract logic during the execution process. The SQL query statement is used to read the target data from the blockchain ledger, and the target data is used to implement the execution of the smart contract.
在具体实现时,该步骤101的实现过程具体是:In the specific implementation, the implementation process of this step 101 is specifically:
对用户产生的区块链交易进行解析,得到输入参数;根据该输入参数,从区块链账本中读取待执行的智能合约代码;基于该输入参数及智能合约代码,初始化智能合约虚拟机;控制智能合约虚拟机根据智能合约代码中智能合约的合约逻辑生成SQL查询语句。Analyze the blockchain transaction generated by the user to obtain input parameters; read the smart contract code to be executed from the blockchain ledger according to the input parameters; initialize the smart contract virtual machine based on the input parameters and the smart contract code; The control smart contract virtual machine generates SQL query statements according to the contract logic of the smart contract in the smart contract code.
输入参数例如是待修改的数据内容、待增加的交易信息等等。The input parameters are, for example, data content to be modified, transaction information to be added, and the like.
该待执行的智能合约代码为与区块链交易中解析出的输入参数相对应的智能合约代码。The smart contract code to be executed is the smart contract code corresponding to the input parameters parsed in the blockchain transaction.
在生成SQL查询语句时,可以是将输入参数带入至查询语句框架中,得到查询语句。例如为:select * from T where B=”aa” and C>100。When generating the SQL query statement, input parameters may be brought into the query statement frame to obtain the query statement. For example: select * from T where B=”aa” and C>100.
具体地,对用户产生的区块链交易进行解析,得到输入参数过程中,需要对区块链交易的合法性进行判断,在判断其具备合法性时,获取其中的输入参数执行后续操作。Specifically, in the process of parsing the blockchain transaction generated by the user and obtaining the input parameters, it is necessary to judge the legality of the blockchain transaction, and when judging that it is legal, obtain the input parameters and perform subsequent operations.
在具体实施过程中,区块链系统接收到用户产生的区块链交易,解析区块链交易,验证格式合法后,经过若干预处理之后,得到输入参数。预处理包括但不限于参数解析、共识打包。In the specific implementation process, the blockchain system receives the blockchain transaction generated by the user, parses the blockchain transaction, verifies the legality of the format, and obtains the input parameters after several preprocessing. Preprocessing includes but is not limited to parameter parsing and consensus packaging.
智能合约执行引擎根据输入参数,从区块链账本中读取需要执行的智能合约代码,使用上述代码和参数,初始化智能合约虚拟机。通过智能合约虚拟机开始执行智能合约,首先运行若干合约逻辑,累计若干工作量,根据合约逻辑生成SQL查询语句,并输入到了内置在智能合约执行引擎中的SQL查询引擎中。The smart contract execution engine reads the smart contract code to be executed from the blockchain ledger according to the input parameters, and uses the above code and parameters to initialize the smart contract virtual machine. Start executing the smart contract through the smart contract virtual machine, first run some contract logic, accumulate some workload, generate SQL query statement according to the contract logic, and input it into the SQL query engine built in the smart contract execution engine.
步骤102,将SQL查询语句输入至内置的SQL查询引擎,通过SQL查询引擎执行该SQL查询语句。Step 102: Input the SQL query statement into the built-in SQL query engine, and execute the SQL query statement through the SQL query engine.
SQL查询引擎执行SQL查询语句时,可以是将SQL查询语句进行预处理例如将其进行拆解得出查询条件,随后基于拆解出的查询条件生成对应的执行器,通过执行器执行对区块链账本中的数据查询动作。When the SQL query engine executes an SQL query statement, it can preprocess the SQL query statement, for example, disassemble it to obtain query conditions, and then generate a corresponding executor based on the disassembled query conditions, and execute the block execution through the executor. Data query action in the chain ledger.
具体地,从区块链账本上匹配数据的方式可以是根据智能合约中合约逻辑和数据结构,构造特定的主键,从区块链账本中匹配具有目标主键且符合设定匹配条件的目标数据。Specifically, the method of matching data from the blockchain ledger can be to construct a specific primary key according to the contract logic and data structure in the smart contract, and match the target data with the target primary key and meet the set matching conditions from the blockchain ledger.
步骤103,从SQL查询语句执行过程中,获取SQL查询引擎的执行操作。Step 103: Acquire the execution operation of the SQL query engine from the execution process of the SQL query statement.
该执行操作为多个。The execution operation is multiple.
其中,SQL查询引擎的执行操作例如为:前述的将SQL查询语句进行预处理的操作,及通过匹配执行器执行的数据执行操作,该数据执行操作可以是字符串比较操作、整数比较操作、数据读取操作等等。Wherein, the execution operation of the SQL query engine is, for example: the aforementioned operation of preprocessing the SQL query statement, and the data execution operation executed by the matching executor, and the data execution operation may be a string comparison operation, an integer comparison operation, a data execution operation read operations, etc.
步骤104,基于该执行操作,从预设的工作量表中匹配与该执行操作对应的工作量。Step 104 , based on the execution operation, match the workload corresponding to the execution operation from a preset workload table.
该工作量表是用来度量SQL查询引擎在执行SQL查询语句过程中所消耗工作量的表结构数据。具体为用来度量SQL查询引擎在执行SQL查询语句过程中预处理和执行器的所消耗工作量的表结构数据。在该工作量表中,对每一种预处理器都会记录其处理一定大小的输入数据所消耗的工作量,对每一种执行器都会记录其处理一定大小的输入数据所消耗的工作量。The workload table is table structure data used to measure the workload consumed by the SQL query engine in the process of executing the SQL query statement. Specifically, the table structure data is used to measure the workload consumed by the preprocessing and executor of the SQL query engine in the process of executing the SQL query statement. In the workload table, the workload of processing input data of a certain size is recorded for each preprocessor, and the workload of processing input data of a certain size is recorded for each executor.
在SQL查询引擎工作每执行一次SQL查询语句时,则根据此次处理当前SQL查询语句的实际处理过程,通过查表累计总的工作量。Each time the SQL query engine executes an SQL query statement, the total workload is accumulated by looking up the table according to the actual processing process of processing the current SQL query statement.
为了保证区块链各个节点的一致性,该工作量表需要存储在区块链账本上,在SQL查询引擎初始化时加载出来。在需要对工作量表中设定的某些工作量变更时,需要通过区块链交易的形式进行统一的变更。如果工作量表不记录在区块链账本上,则需要区块链节点之间使用相同的缺省配置。In order to ensure the consistency of each node of the blockchain, the workload table needs to be stored on the blockchain ledger and loaded when the SQL query engine is initialized. When some workloads set in the workload table need to be changed, unified changes need to be made in the form of blockchain transactions. If the work sheet is not recorded on the blockchain ledger, the same default configuration is required between blockchain nodes.
步骤105,基于该工作量,对SQL查询引擎执行SQL查询语句过程中的工作量进行累计。Step 105: Based on the workload, the workload in the process of executing the SQL query statement by the SQL query engine is accumulated.
上述过程中,在SQL查询引擎中构造基于处理过程的工作量度量机制,使得具备工作量机制的智能合约虚拟机可以内置这种SQL查询引擎,进而为智能合约提供SQL查询功能。In the above process, a workload measurement mechanism based on the processing process is constructed in the SQL query engine, so that the smart contract virtual machine with the workload mechanism can build this SQL query engine, and then provide the SQL query function for the smart contract.
具体地,通过对SQL查询语句执行过程中的所涉及到的扫描、条件过滤、连接等处理过程设定工作量,并预先记载于工作量表中,在执行智能合约过程中执行SQL查询语句时,根据具体调用到的执行操作以及调用次数,累计计算总工作量,从而能够允许智能合约的执行引擎在保持原有工作量机制的同时嵌入高效的原生SQL查询引擎,进而提高智能合约数据读取接口的友好度,提高区块链合约开发效率。Specifically, the workload is set for the processing processes such as scanning, conditional filtering, and connection involved in the execution of the SQL query statement, and is recorded in the workload table in advance. When executing the SQL query statement during the execution of the smart contract , according to the specific execution operations and the number of calls, the total workload is accumulated, so that the execution engine of the smart contract can be embedded with an efficient native SQL query engine while maintaining the original workload mechanism, thereby improving the reading of smart contract data. The friendliness of the interface improves the efficiency of blockchain contract development.
进一步地,在基于该工作量,对SQL查询引擎执行SQL查询语句过程中的工作量进行累计之后,还包括:Further, after accumulating the workload in the process of executing the SQL query statement by the SQL query engine based on the workload, the method further includes:
在SQL查询引擎执行SQL查询语句过程中,若执行操作对应的工作总量超出阈值,则控制SQL查询引擎输出数据查询结果。When the SQL query engine executes the SQL query statement, if the total amount of work corresponding to the execution operation exceeds the threshold, the SQL query engine is controlled to output the data query result.
工作量机制的设置主要是解决停机问题,避免合约调用无法终止的情况,另外还避免单次执行消耗的系统资源过大。The setting of the workload mechanism is mainly to solve the problem of downtime, avoid the situation that the contract call cannot be terminated, and also avoid excessive system resources consumed by a single execution.
需要对SQL查询引擎的工作量上限进行设定,每次使用内置SQL查询引擎查询数据能够使用的工作量上限由参数指定。工作量上限可以是用户区块链交易中进行的输入或统一配置。The upper limit of the workload of the SQL query engine needs to be set. The upper limit of the workload that can be used to query data using the built-in SQL query engine is specified by the parameter. The workload cap can be an input or a unified configuration made in a user blockchain transaction.
当SQL查询任务处理完成,或者SQL查询引擎累计的工作量达到上限,以智能合约中可读取的数据结构返回数据供合约逻辑使用。When the SQL query task is processed, or the accumulated workload of the SQL query engine reaches the upper limit, the data is returned in a readable data structure in the smart contract for the contract logic.
本申请实施例中,通过根据用户产生的区块链交易,执行智能合约,生成与该智能合约对应的SQL查询语句,将SQL查询语句输入至内置的SQL查询引擎,通过SQL查询引擎执行该SQL查询语句,从SQL查询语句执行过程中,获取SQL查询引擎的执行操作,基于该执行操作,从预设的工作量表中匹配与执行操作对应的工作量,基于该工作量,对SQL查询引擎执行SQL查询语句过程中的工作量进行累计。该过程通过在执行智能合约时生成与智能合约对应的SQL查询语句,通过内置的SQL查询引擎对该SQL查询语句进行执行,并对该执行过程进行监控,获取SQL查询引擎在执行SQL查询语句时对应的执行操作,并将该些执行操作在预设置的工作量表中进行匹配,以基于工作量表中的记录内容得到与该些执行操作对应的工作量,并进行累计,从查询过程中涉及的执行操作本身这一维度去度量工作量,适应区块链的工作量计量机制,实现SQL查询与区块链平台之间的融合。In the embodiment of the present application, the smart contract is executed according to the blockchain transaction generated by the user, the SQL query statement corresponding to the smart contract is generated, the SQL query statement is input into the built-in SQL query engine, and the SQL query engine is used to execute the SQL Query statement, obtain the execution operation of the SQL query engine from the execution process of the SQL query statement, based on the execution operation, match the workload corresponding to the execution operation from the preset workload table, and based on the workload, the SQL query engine The workload in the process of executing the SQL query statement is accumulated. In this process, the SQL query statement corresponding to the smart contract is generated when the smart contract is executed, the SQL query statement is executed through the built-in SQL query engine, and the execution process is monitored, and the SQL query engine is obtained when the SQL query statement is executed. Corresponding execution operations, and match these execution operations in the preset workload table to obtain the workload corresponding to these execution operations based on the record content in the workload table, and accumulate them. From the query process The dimension of the execution operation itself involved measures the workload, adapts to the workload measurement mechanism of the blockchain, and realizes the integration between the SQL query and the blockchain platform.
本申请实施例中还提供了区块链中数据查询工作量的计量方法的不同实施方式。The embodiments of the present application also provide different implementations of the method for measuring the workload of data query in the blockchain.
参见图2,图2是本申请实施例提供的一种区块链中数据查询工作量的计量方法的流程图二。如图2所示,一种区块链中数据查询工作量的计量方法,该方法包括以下步骤:Referring to FIG. 2 , FIG. 2 is a second flowchart of a method for measuring data query workload in a blockchain provided by an embodiment of the present application. As shown in Figure 2, a method for measuring the workload of data query in blockchain, the method includes the following steps:
步骤201,根据用户产生的区块链交易,执行智能合约,生成与该智能合约对应的SQL查询语句。Step 201: Execute the smart contract according to the blockchain transaction generated by the user, and generate a SQL query statement corresponding to the smart contract.
该步骤的实现过程与前述实施方式中的步骤101的实现过程相同,此处不再赘述。The implementation process of this step is the same as the implementation process of step 101 in the foregoing embodiment, and details are not repeated here.
步骤202,将SQL查询语句输入至内置的SQL查询引擎,通过该SQL查询引擎执行SQL查询语句。Step 202: Input the SQL query statement into the built-in SQL query engine, and execute the SQL query statement through the SQL query engine.
该步骤的实现过程与前述实施方式中的步骤102的实现过程相同,此处不再赘述。The implementation process of this step is the same as the implementation process of step 102 in the foregoing embodiment, and details are not repeated here.
步骤203,从SQL查询语句执行过程中,获取SQL查询引擎对SQL查询语句的预处理操作,及,获取SQL查询引擎对SQL查询语句进行预处理后生成分层执行器,并通过分层执行器对预处理后的SQL查询语句进行分层执行过程中,每一执行器的数据执行操作。Step 203, from the process of executing the SQL query statement, obtain the preprocessing operation of the SQL query statement by the SQL query engine, and obtain the SQL query engine to preprocess the SQL query statement to generate a hierarchical executor, and pass the hierarchical executor During the hierarchical execution of the preprocessed SQL query statement, the data of each executor performs operations.
即在SQL查询语句执行过程中,获取的SQL查询引擎的执行操作具体包括:对SQL查询语句的预处理操作及分层执行器中每一执行器的数据执行操作。That is, during the execution of the SQL query statement, the acquired execution operations of the SQL query engine specifically include: preprocessing operations on the SQL query statement and data execution operations of each executor in the hierarchical executors.
在具体应用过程中,SQL查询引擎先对SQL查询语句使用预处理器进行预处理,再基于预处理结果生成分层执行器。预处理包括但不限于SQL查询语句的解析、索引选择、执行优化。执行器是SQL查询执行过程中子过程的逻辑单元总称,包括但不限于数据运算、比较、连接。分层指的是执行器与执行器之间存在上下层级关系,下层执行器的输出作为上层执行器的输入,最下层的执行器是对区块链账本的读取执行器,最上层的执行器连接的是SQL查询引擎对智能合约提供的SQL查询接口,并通过该接口返回数据查询结果。智能合约中的数据获取可以看作是最上层执行器到最下层执行器的递归调用,下层执行器的执行结果中的数据返回给上层执行器进一步匹配处理,每个执行器根据各自配置每次调用并返回一定数量的数据。In the specific application process, the SQL query engine first uses the preprocessor to preprocess the SQL query statement, and then generates a hierarchical executor based on the preprocessing result. Preprocessing includes, but is not limited to, parsing of SQL query statements, index selection, and execution optimization. Executor is a general term for the logical unit of sub-processes in the SQL query execution process, including but not limited to data operations, comparisons, and connections. Hierarchical refers to the relationship between the executor and the executor. The output of the lower executor is used as the input of the upper executor. The browser is connected to the SQL query interface provided by the SQL query engine to the smart contract, and returns data query results through this interface. The data acquisition in the smart contract can be regarded as a recursive call from the top-level executor to the bottom-level executor, and the data in the execution result of the lower-level executor is returned to the upper-level executor for further matching processing. Called and returns a certain amount of data.
该SQL查询引擎由SQL查询接口接收到SQL查询语句后,开始向下调用获取和处理数据。After the SQL query engine receives the SQL query statement from the SQL query interface, it starts to call down to acquire and process data.
通过上层执行器向下进行调用,由最下层执行器从区块链账本中读取设定行数的数据,最下层执行器将该数据作为相邻的上层执行器的输入,由该相邻的上层执行器对该数据执行已经赋予给该层执行器的数据比对操作,基于比对结果得出符合对应查询条件的数据,并将该数据继续输入至相邻的上层执行器以对该数据进行又一次的数据比对判断,直至最上一层执行器执行完毕,将最终符合条件的数据作为SQL查询的结果进行输出。Call down through the upper executor, the lowermost executor reads the data of the set number of rows from the blockchain ledger, and the lowermost executor takes the data as the input of the adjacent upper executor, and the adjacent The upper-layer executor performs the data comparison operation that has been assigned to the executor of this layer, and obtains the data that meets the corresponding query conditions based on the comparison result, and continues to input the data to the adjacent upper-layer executor for the corresponding query. The data is subjected to another data comparison and judgment until the execution of the top-level executor is completed, and the final qualified data is output as the result of the SQL query.
步骤204,基于该执行操作,从预设的工作量表中匹配与该执行操作对应的工作量。Step 204 , based on the execution operation, match the workload corresponding to the execution operation from a preset workload table.
具体地,该预设的工作量表中,记录的内容包括:每一种预处理器处理单位量的输入数据所消耗的工作量,每一种预处理器处理单位量的输入数据所消耗的工作量。该单位量例如为一字节。Specifically, in the preset workload table, the recorded content includes: the workload consumed by each preprocessor for processing a unit amount of input data, the amount of work consumed by each preprocessor processing a unit amount of input data workload. The unit amount is, for example, one byte.
其中,不同的预处理器对应于不同的预处理方式,不同的执行器执行不同的数据处理操作。Among them, different preprocessors correspond to different preprocessing methods, and different executors perform different data processing operations.
该执行操作包括:对SQL查询语句的预处理操作及分层执行器中每一执行器的数据执行操作。The execution operations include: preprocessing operations on SQL query statements and data execution operations on each executor in the hierarchical executors.
本步骤204在实施过程中,包括:获取预处理操作在执行时的第一操作数据量;从与预设的工作量表中,获取与预处理操作对应的单位操作数据量的第一处理工作量;根据该第一操作数据量及第一处理工作量,得到预处理操作的第一工作量。During the implementation process of step 204, the steps include: acquiring the first operation data amount when the preprocessing operation is performed; acquiring the first processing work corresponding to the unit operation data amount of the preprocessing operation from the preset workload table The first workload of the preprocessing operation is obtained according to the first operation data volume and the first processing workload.
进一步地,本步骤204在实施过程中,还包括:按照执行器的数据执行操作的执行顺序,每检测到一个执行器执行数据执行操作,则获取当前执行器在执行数据执行操作时的第二操作数据量;从与预设的工作量表中,获取与当前执行器的数据执行操作所对应的单位操作数据量的第二处理工作量;根据第二操作数据量及第二处理工作量,得到当前执行器的第二工作量。Further, in the implementation process of this step 204, it also includes: according to the execution sequence of the data execution operations of the executors, every time an executor is detected to execute the data execution operation, acquiring the second data execution operation of the current executor when the data execution operation is performed. operation data volume; from the preset workload table, obtain the second processing workload of the unit operation data volume corresponding to the data execution operation of the current executor; according to the second operation data volume and the second processing workload, Get the second workload of the current executor.
实现对SQL查询引擎执行SQL查询语句过程中不同执行操作的工作量的获取。Realize the acquisition of the workload of different execution operations in the process of executing the SQL query statement by the SQL query engine.
步骤205,基于该工作量,对SQL查询引擎执行SQL查询语句过程中的工作量进行累计。Step 205: Based on the workload, the workload in the process of executing the SQL query statement by the SQL query engine is accumulated.
对应地,该步骤的实现具体是:将前述步骤中的第一工作量及依次获取到的第二工作量进行累计。Correspondingly, the implementation of this step is specifically: accumulating the first workload in the preceding steps and the second workload obtained in sequence.
其中,每对一个执行器的工作量按照前述步骤中的方式获取一次则会得到对应的一个第二工作量,依照多层执行器中各执行器对数据执行操作的执行顺序,依次获取不同的执行器对应的第二工作量,并实现与第一工作量的累计,实现对SQL查询引擎执行SQL查询语句过程中的总工作量的获取。Among them, the workload of each pair of executors is obtained once according to the method in the preceding steps, and a corresponding second workload is obtained. According to the execution order of the data operations performed by the executors in the multi-layer executors, different executors are sequentially obtained. The second workload corresponding to the executor is accumulated with the first workload, and the total workload in the process of executing the SQL query statement by the SQL query engine is obtained.
这里,对上述实施过程进行实例说明:Here, the above implementation process is illustrated with an example:
1)通过区块链交易在工作量表中设置不同的执行操作所对应的单位操作数据量的处理工作量。具体内容如下表1:1) Set the processing workload of the unit operation data volume corresponding to different execution operations in the workload table through blockchain transactions. The details are shown in Table 1:
预处理器/执行器名称 preprocessor/executor name 处理输入数据所消耗的单位工作量/字节 Unit effort/byte consumed by processing input data
SQL解析预处理器 SQL parsing preprocessor 10 10
... ... ... ...
字符串比较执行器 String comparison executor 1 1
整数比较执行器 Integer comparison executor 1 1
区块链账本读取执行器 Blockchain Ledger Reader 2 2
... ... ... ...
2)通过区块链交易在区块链账本上预先存储了如下表2的关系型数据, 称为表T,其中A是主键,A列和C列是8字节整数,B列是每个字符1字节的字符串。仅有主键索引。2) The relational data in the following table 2 is pre-stored on the blockchain ledger through blockchain transactions, which is called table T, where A is the primary key, columns A and C are 8-byte integers, and column B is each A 1-byte string of characters. Only the primary key index.
A A B B C C
1 1 “aa” "aa" 100 100
2 2 “aa” "aa" 100 100
3 3 “aa” "aa" 200 200
4 4 “ba” "ba" 200 200
5 5 “ba” "ba" 300 300
在区块链账本中以键值对的形式存储上述表的编码结果,上表中的数据在区块链账本上存储的值长度均为14字节。The encoding results of the above table are stored in the form of key-value pairs in the blockchain ledger. The data in the above table is stored in the blockchain ledger with a length of 14 bytes.
3)通过区块链交易调用智能合约。3) Invoke smart contracts through blockchain transactions.
4)智能合约执行时生成了SQL查询语句select * from T where B=”aa” and C>100,将该SQL查询语句输入到SQL查询引擎,并且限定工作量上限为1000。4) When the smart contract is executed, the SQL query statement select * from T where B=”aa” and C>100, input the SQL query statement to the SQL query engine, and limit the workload to 1000.
SQL查询引擎使用SQL解析预处理器解析SQL查询语句,该查询语句的输入为38字节,根据预设的工作量表(表1)累计产生380单位工作量,并且生成执行查询语句所需的分层执行器,每个执行器一次返回5条数据,进行递归调用,一种分层结构如图3所示。The SQL query engine uses the SQL parsing preprocessor to parse the SQL query statement. The input of the query statement is 38 bytes. According to the preset workload table (Table 1), a total of 380 units of workload are generated, and the required amount of work to execute the query statement is generated. Hierarchical executors, each executor returns 5 pieces of data at a time and makes recursive calls. A hierarchical structure is shown in Figure 3.
该分层执行器的结构包括:最上层的字符串比较执行器,与SQL引擎接口连接,实现对SQL查询语句的获取;最下层的区块链账本读取执行器,与区块链账本连接,实现从区块链中进行数据读取;位于中间层的整数比较执行器。The structure of the layered executor includes: the uppermost string comparison executor, which is connected with the SQL engine interface to realize the acquisition of SQL query statements; the lowermost blockchain ledger reading executor, which is connected with the blockchain ledger , which implements data reading from the blockchain; an integer comparison executor located in the middle layer.
5)最底层的区块链账本读取执行器根据主键范围逐行构造主键,对表2中的数据进行读取,总计5行数据90个字节,并解析成对应格式返回给上层的整数比较执行器,结合表1中的数据得出会消耗180单位工作量,此时累计消耗560单位工作量。5) The bottom-level blockchain ledger reading executor constructs the primary key row by row according to the primary key range, reads the data in Table 2, a total of 5 rows of data and 90 bytes, and parses it into an integer returned to the upper layer in the corresponding format Comparing the actuators and combining the data in Table 1, it can be concluded that 180 units of workload will be consumed, and the cumulative consumption of 560 units of workload at this time.
6)整数比较执行器比较表2中的C列执行处理数据,需要处理区块链账本读取执行器返回的5行数据,进行5次8字节整数的比较,结合表1中的数据得出会消耗40单位工作量,此时累计消耗600单位工作量。过滤出满足C>100条件的行,得到主键为3、4、5的3行数据。此时需要返回的数据不足5条,继续调用下层执行器(即区块链账本读取执行器),若没有收到下层提供的数据,则直接将该3条数据返回给上层的字符串比较执行器。6) The integer comparison executor compares the processing data in column C in Table 2. It needs to process the 5 rows of data returned by the blockchain ledger reading executor, and perform 5 comparisons of 8-byte integers. Combined with the data in Table 1, we get The output will consume 40 units of workload, and the cumulative consumption of 600 units of workload at this time. Filter out the rows that satisfy the condition C>100, and get 3 rows of data whose primary keys are 3, 4, and 5. At this time, less than 5 pieces of data need to be returned, continue to call the lower-level executor (that is, the blockchain ledger reading executor). If the data provided by the lower-level is not received, the 3 pieces of data are directly returned to the upper-level string comparison. Actuator.
7)字符串比较执行器比较表2中的B列执行处理数据,需要处理整数比较器返回的3行数据,进行3次2字节字符串的比较,结合表1中的数据得出会消耗6单位工作量,此时累计消耗606单位工作量。过滤出满足条件B=”aa”的行,得到主键为3、4的2行数据。需要返回数据不足5条,继续调用下层执行器(即整数比较执行器),若没有收到下层提供的数据,则将已处理好的2行数据返回给上层,即从SQL引擎接口返回给智能合约逻辑。智能合约中按行读取数据,执行后续逻辑,并生成智能合约的执行结果。7) The string comparison executor compares the processing data in column B in Table 2. It needs to process the 3 rows of data returned by the integer comparator, and perform 3 comparisons of 2-byte strings. Combined with the data in Table 1, it will consume 6 units of workload, and the cumulative consumption of 606 units of workload at this time. Filter out the rows that satisfy the condition B=”aa”, and get 2 rows of data whose primary keys are 3 and 4. If there are less than 5 pieces of returned data, continue to call the lower-level executor (that is, the integer comparison executor). If the data provided by the lower-level is not received, the processed 2 rows of data are returned to the upper-level, that is, from the SQL engine interface to the intelligent contract logic. In the smart contract, the data is read line by line, the subsequent logic is executed, and the execution result of the smart contract is generated.
本实施例中的该过程,允许区块链智能合约执行引擎内嵌兼容工作量机制的SQL查询引擎,可以允许区块链合约以更加灵活、高效、标准的方式进行关系型数据读取。The process in this embodiment allows the blockchain smart contract execution engine to embed a SQL query engine compatible with the workload mechanism, and allows the blockchain contract to read relational data in a more flexible, efficient and standard manner.
参见图4,图4是本申请实施例提供的一种区块链中数据查询工作量的计量装置的结构图,为了便于说明,仅示出了与本申请实施例相关的部分。Referring to FIG. 4 , FIG. 4 is a structural diagram of a device for measuring data query workload in a blockchain provided by an embodiment of the present application. For convenience of description, only parts related to the embodiment of the present application are shown.
该区块链中数据查询工作量的计量装置400包括:The measuring device 400 of the data query workload in the blockchain includes:
生成模块401,用于根据用户产生的区块链交易,执行智能合约,生成与所述智能合约对应的SQL查询语句;The generating module 401 is used for executing the smart contract according to the blockchain transaction generated by the user, and generating the SQL query statement corresponding to the smart contract;
查询模块402,用于将所述SQL查询语句输入至内置的SQL查询引擎,通过所述SQL查询引擎执行所述SQL查询语句;A query module 402, configured to input the SQL query statement into a built-in SQL query engine, and execute the SQL query statement through the SQL query engine;
获取模块403,用于从所述SQL查询语句执行过程中,获取所述SQL查询引擎的执行操作;An obtaining module 403, configured to obtain the execution operation of the SQL query engine from the execution process of the SQL query statement;
匹配模块404,用于基于所述执行操作,从预设的工作量表中匹配与所述执行操作对应的工作量;a matching module 404, configured to match the workload corresponding to the execution operation from a preset workload table based on the execution operation;
工作量计算模块405,用于基于所述工作量,对所述SQL查询引擎执行所述SQL查询语句过程中的工作量进行累计。The workload calculation module 405 is configured to accumulate the workload in the process of executing the SQL query statement by the SQL query engine based on the workload.
其中,获取模块403,具体用于:Wherein, the acquisition module 403 is specifically used for:
从所述SQL查询语句执行过程中,获取所述SQL查询引擎对所述SQL查询语句的预处理操作,及,获取所述SQL查询引擎对所述SQL查询语句进行预处理后生成分层执行器,并通过所述分层执行器对预处理后的所述SQL查询语句进行分层执行过程中,每一执行器的数据执行操作。From the process of executing the SQL query statement, obtain the preprocessing operation of the SQL query statement by the SQL query engine, and obtain the SQL query engine after preprocessing the SQL query statement to generate a layered executor , and during the hierarchical execution process of the preprocessed SQL query statement by the hierarchical executor, the data of each executor performs operations.
其中,匹配模块404,具体用于:Wherein, the matching module 404 is specifically used for:
获取所述预处理操作在执行时的第一操作数据量;obtaining the first operation data amount when the preprocessing operation is performed;
从与所述预设的工作量表中,获取与所述预处理操作对应的单位操作数据量的第一处理工作量;obtaining, from the preset workload table, a first processing workload corresponding to the preprocessing operation per unit of operation data;
根据所述第一操作数据量及所述第一处理工作量,得到所述预处理操作的第一工作量。According to the first operation data amount and the first processing workload, the first workload of the preprocessing operation is obtained.
其中,匹配模块404,还具体用于:Wherein, the matching module 404 is also specifically used for:
按照所述执行器的数据执行操作的执行顺序,每检测到一个执行器执行所述数据执行操作,则获取当前执行器在执行数据执行操作时的第二操作数据量;According to the execution sequence of the data execution operations of the executors, each time an executor is detected to execute the data execution operation, obtain the second operation data amount of the current executor when the data execution operation is performed;
从与所述预设的工作量表中,获取与当前执行器的数据执行操作所对应的单位操作数据量的第二处理工作量;From the preset workload table, obtain the second processing workload of the unit operation data volume corresponding to the data execution operation of the current executor;
根据所述第二操作数据量及所述第二处理工作量,得到所述当前执行器的第二工作量。According to the second operation data amount and the second processing workload, the second workload of the current executor is obtained.
其中,工作量计算模块405,具体用于:Among them, the workload calculation module 405 is specifically used for:
将所述第一工作量及依次获取到的所述第二工作量进行累计。The first workload and the sequentially acquired second workload are accumulated.
其中,生成模块401,具体用于:Wherein, the generation module 401 is specifically used for:
对用户产生的区块链交易进行解析,得到输入参数;Analyze the blockchain transaction generated by the user to obtain the input parameters;
根据所述输入参数,从区块链账本中读取待执行的智能合约代码;According to the input parameters, read the smart contract code to be executed from the blockchain ledger;
基于所述输入参数及所述智能合约代码,初始化智能合约虚拟机;Based on the input parameters and the smart contract code, initialize a smart contract virtual machine;
控制所述智能合约虚拟机根据所述智能合约代码中智能合约的合约逻辑生成SQL查询语句。The smart contract virtual machine is controlled to generate an SQL query statement according to the contract logic of the smart contract in the smart contract code.
该装置还包括:输出模块,用于:The device also includes: an output module for:
在所述SQL查询引擎执行所述SQL查询语句过程中,若所述执行操作对应的工作总量超出阈值,则控制所述SQL查询引擎输出数据查询结果。During the process of executing the SQL query statement by the SQL query engine, if the total amount of work corresponding to the execution operation exceeds a threshold, the SQL query engine is controlled to output a data query result.
本申请实施例提供的区块链中数据查询工作量的计量装置能够实现上述区块链中数据查询工作量的计量方法的实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。The device for measuring the workload of data query in the blockchain provided by the embodiment of the present application can realize the various processes of the above-mentioned embodiments of the method for measuring the workload of data query in the blockchain, and can achieve the same technical effect. In order to avoid repetition, I won't go into details here.
图5是本申请实施例提供的一种终端的结构图。如该图所示,该实施例的终端5包括:至少一个处理器50(图5中仅示出一个)、存储器51以及存储在所述存储器51中并可在所述至少一个处理器50上运行的计算机程序52,所述处理器50执行所述计算机程序52时实现上述任意各个方法实施例中的步骤。FIG. 5 is a structural diagram of a terminal provided by an embodiment of the present application. As shown in this figure, the terminal 5 of this embodiment includes: at least one processor 50 (only one is shown in FIG. 5 ), a memory 51 , and a memory 51 stored in the memory 51 and available on the at least one processor 50 The running computer program 52, when the processor 50 executes the computer program 52, implements the steps in any of the foregoing method embodiments.
所述终端5可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。所述终端5可包括,但不仅限于,处理器50、存储器51。本领域技术人员可以理解,图5仅仅是终端5的示例,并不构成对终端5的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如所述终端还可以包括输入输出设备、网络接入设备、总线等。The terminal 5 may be a computing device such as a desktop computer, a notebook, a palmtop computer and a cloud server. The terminal 5 may include, but is not limited to, a processor 50 and a memory 51 . Those skilled in the art can understand that FIG. 5 is only an example of the terminal 5, and does not constitute a limitation on the terminal 5. It may include more or less components than the one shown in the figure, or combine some components, or different components, such as The terminal may also include input and output devices, network access devices, buses, and the like.
所述处理器50可以是中央处理单元(Central Processing Unit,CPU),还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA) 或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。The processor 50 may be a central processing unit (Central Processing Unit, CPU), or other general-purpose processors, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
所述存储器51可以是所述终端5的内部存储单元,例如终端5的硬盘或内存。所述存储器51也可以是所述终端5的外部存储设备,例如所述终端5上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,所述存储器51还可以既包括所述终端5的内部存储单元也包括外部存储设备。所述存储器51用于存储所述计算机程序以及所述终端所需的其他程序和数据。所述存储器51还可以用于暂时地存储已经输出或者将要输出的数据。The memory 51 may be an internal storage unit of the terminal 5 , such as a hard disk or a memory of the terminal 5 . The memory 51 may also be an external storage device of the terminal 5, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card equipped on the terminal 5, Flash card (Flash Card) and so on. Further, the memory 51 may also include both an internal storage unit of the terminal 5 and an external storage device. The memory 51 is used to store the computer program and other programs and data required by the terminal. The memory 51 can also be used to temporarily store data that has been output or will be output.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。实施例中的各功能单元、模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元、模块的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。上述系统中单元、模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. Module completion, that is, dividing the internal structure of the device into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment may be integrated in one processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit, and the above-mentioned integrated units may adopt hardware. It can also be realized in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing from each other, and are not used to limit the protection scope of the present application. For the specific working processes of the units and modules in the above-mentioned system, reference may be made to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。In the foregoing embodiments, the description of each embodiment has its own emphasis. For parts that are not described or described in detail in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware, or may be implemented in the form of software functional units.
所述集成的模块/单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,也可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机程序包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质可以包括:能够携带所述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号、电信信号以及软件分发介质等。需要说明的是,所述计算机可读介质包含的内容可以根据司法管辖区内立法和专利实践的要求进行适当的增减,例如在某些司法管辖区,根据立法和专利实践,计算机可读介质不包括电载波信号和电信信号。The integrated modules/units, if implemented in the form of software functional units and sold or used as independent products, may be stored in a computer-readable storage medium. Based on this understanding, the present application can implement all or part of the processes in the methods of the above embodiments, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer When the program is executed by the processor, the steps of the foregoing method embodiments can be implemented. Wherein, the computer program includes computer program code, and the computer program code may be in the form of source code, object code, executable file or some intermediate form, and the like. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, removable hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory) , Random Access Memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable media may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, the computer-readable media Electric carrier signals and telecommunication signals are not included.
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the above-mentioned embodiments, those of ordinary skill in the art should understand that: it can still be used for the above-mentioned implementations. The technical solutions described in the examples are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions in the embodiments of the application, and should be included in the within the scope of protection of this application.

Claims (16)

  1. 一种区块链中数据查询工作量的计量方法,其特征在于,包括:A method for measuring data query workload in a blockchain, characterized by comprising:
    根据用户产生的区块链交易,执行智能合约,生成与所述智能合约对应的SQL查询语句;According to the blockchain transaction generated by the user, execute the smart contract, and generate the SQL query statement corresponding to the smart contract;
    将所述SQL查询语句输入至内置的SQL查询引擎,通过所述SQL查询引擎执行所述SQL查询语句;The SQL query statement is input into the built-in SQL query engine, and the SQL query statement is executed by the SQL query engine;
    从所述SQL查询语句执行过程中,获取所述SQL查询引擎的执行操作;From the execution process of the SQL query statement, obtain the execution operation of the SQL query engine;
    基于所述执行操作,从预设的工作量表中匹配与所述执行操作对应的工作量;Based on the execution operation, matching the workload corresponding to the execution operation from a preset workload table;
    基于所述工作量,对所述SQL查询引擎执行所述SQL查询语句过程中的工作量进行累计。Based on the workload, the workload in the process of executing the SQL query statement by the SQL query engine is accumulated.
  2. 根据权利要求1所述的计量方法,其特征在于,所述从所述SQL查询语句执行过程中,获取所述SQL查询引擎的执行操作,包括:The measurement method according to claim 1, wherein the obtaining the execution operation of the SQL query engine from the execution process of the SQL query statement comprises:
    从所述SQL查询语句执行过程中,获取所述SQL查询引擎对所述SQL查询语句的预处理操作,及,获取所述SQL查询引擎对所述SQL查询语句进行预处理后生成分层执行器,并通过所述分层执行器对预处理后的所述SQL查询语句进行分层执行过程中,每一执行器的数据执行操作。From the process of executing the SQL query statement, obtain the preprocessing operation of the SQL query statement by the SQL query engine, and obtain the SQL query engine after preprocessing the SQL query statement to generate a layered executor , and during the hierarchical execution process of the preprocessed SQL query statement by the hierarchical executor, the data of each executor performs operations.
  3. 根据权利要求2所述的计量方法,其特征在于,所述基于所述执行操作,从预设的工作量表中匹配与所述执行操作对应的工作量,包括:The metering method according to claim 2, wherein, based on the execution operation, matching the workload corresponding to the execution operation from a preset workload table, comprising:
    获取所述预处理操作在执行时的第一操作数据量;obtaining the first operation data amount when the preprocessing operation is performed;
    从与所述预设的工作量表中,获取与所述预处理操作对应的单位操作数据量的第一处理工作量;obtaining, from the preset workload table, a first processing workload corresponding to the preprocessing operation per unit of operation data;
    根据所述第一操作数据量及所述第一处理工作量,得到所述预处理操作的第一工作量。According to the first operation data amount and the first processing workload, the first workload of the preprocessing operation is obtained.
  4. 根据权利要求3所述的计量方法,其特征在于,所述根据所述第一操作数据量及所述第一处理工作量,得到所述预处理操作的第一工作量之后,还包括:The measurement method according to claim 3, wherein after obtaining the first workload of the preprocessing operation according to the first operation data volume and the first processing workload, the method further comprises:
    按照所述执行器的数据执行操作的执行顺序,每检测到一个执行器执行所述数据执行操作,则获取当前执行器在执行数据执行操作时的第二操作数据量;According to the execution sequence of the data execution operations of the executors, each time an executor is detected to execute the data execution operation, obtain the second operation data amount of the current executor when the data execution operation is performed;
    从与所述预设的工作量表中,获取与当前执行器的数据执行操作所对应的单位操作数据量的第二处理工作量;From the preset workload table, obtain the second processing workload of the unit operation data volume corresponding to the data execution operation of the current executor;
    根据所述第二操作数据量及所述第二处理工作量,得到所述当前执行器的第二工作量。According to the second operation data amount and the second processing workload, the second workload of the current executor is obtained.
  5. 根据权利要求4所述的计量方法,其特征在于,所述基于所述工作量,对所述SQL查询引擎执行所述SQL查询语句过程中的工作量进行累计,包括:The measurement method according to claim 4, wherein, based on the workload, accumulating the workload in the process of executing the SQL query statement by the SQL query engine, comprising:
    将所述第一工作量及依次获取到的所述第二工作量进行累计。The first workload and the sequentially acquired second workload are accumulated.
  6. 根据权利要求1所述的计量方法,其特征在于,所述根据用户产生的区块链交易,执行智能合约,生成与所述智能合约对应的SQL查询语句,包括:The measurement method according to claim 1, wherein, executing a smart contract according to a blockchain transaction generated by a user, and generating an SQL query statement corresponding to the smart contract, comprising:
    对用户产生的区块链交易进行解析,得到输入参数;Analyze the blockchain transaction generated by the user to obtain the input parameters;
    根据所述输入参数,从区块链账本中读取待执行的智能合约代码;According to the input parameters, read the smart contract code to be executed from the blockchain ledger;
    基于所述输入参数及所述智能合约代码,初始化智能合约虚拟机;Based on the input parameters and the smart contract code, initialize a smart contract virtual machine;
    控制所述智能合约虚拟机根据所述智能合约代码中智能合约的合约逻辑生成SQL查询语句。The smart contract virtual machine is controlled to generate an SQL query statement according to the contract logic of the smart contract in the smart contract code.
  7. 根据权利要求1所述的计量方法,其特征在于,所述基于所述工作量,对所述SQL查询引擎执行所述SQL查询语句过程中的工作量进行累计之后,还包括:The measurement method according to claim 1, wherein, after accumulating the workload in the process of executing the SQL query statement by the SQL query engine based on the workload, the method further comprises:
    在所述SQL查询引擎执行所述SQL查询语句过程中,若所述执行操作对应的工作总量超出阈值,则控制所述SQL查询引擎输出数据查询结果。During the process of executing the SQL query statement by the SQL query engine, if the total amount of work corresponding to the execution operation exceeds a threshold, the SQL query engine is controlled to output a data query result.
  8. 一种区块链中数据查询工作量的计量装置,其特征在于,包括:A measuring device for data query workload in a blockchain, characterized in that it includes:
    生成模块,用于根据用户产生的区块链交易,执行智能合约,生成与所述智能合约对应的SQL查询语句;A generation module, used for executing the smart contract according to the blockchain transaction generated by the user, and generating the SQL query statement corresponding to the smart contract;
    查询模块,用于将所述SQL查询语句输入至内置的SQL查询引擎,通过所述SQL查询引擎执行所述SQL查询语句;A query module, for inputting the SQL query statement into a built-in SQL query engine, and executing the SQL query statement through the SQL query engine;
    获取模块,用于从所述SQL查询语句执行过程中,获取所述SQL查询引擎的执行操作;an acquisition module, for acquiring the execution operation of the SQL query engine from the execution process of the SQL query statement;
    匹配模块,用于基于所述执行操作,从预设的工作量表中匹配与所述执行操作对应的工作量;a matching module, configured to match the workload corresponding to the execution operation from a preset workload table based on the execution operation;
    工作量计算模块,用于基于所述工作量,对所述SQL查询引擎执行所述SQL查询语句过程中的工作量进行累计。A workload calculation module, configured to accumulate the workload in the process of executing the SQL query statement by the SQL query engine based on the workload.
  9. 根据权利要求8所述的计量装置,其特征在于,所述获取模块具体用于:The metering device according to claim 8, wherein the acquisition module is specifically used for:
    从所述SQL查询语句执行过程中,获取所述SQL查询引擎对所述SQL查询语句的预处理操作,及,获取所述SQL查询引擎对所述SQL查询语句进行预处理后生成分层执行器,并通过所述分层执行器对预处理后的所述SQL查询语句进行分层执行过程中,每一执行器的数据执行操作。From the process of executing the SQL query statement, obtain the preprocessing operation of the SQL query statement by the SQL query engine, and obtain the SQL query engine after preprocessing the SQL query statement to generate a layered executor , and during the hierarchical execution process of the preprocessed SQL query statement by the hierarchical executor, the data of each executor performs operations.
  10. 根据权利要求9所述的计量装置,其特征在于,所述匹配模块,具体用于:The metering device according to claim 9, wherein the matching module is specifically used for:
    获取所述预处理操作在执行时的第一操作数据量;obtaining the first operation data amount when the preprocessing operation is performed;
    从与所述预设的工作量表中,获取与所述预处理操作对应的单位操作数据量的第一处理工作量;obtaining, from the preset workload table, a first processing workload corresponding to the preprocessing operation per unit of operation data;
    根据所述第一操作数据量及所述第一处理工作量,得到所述预处理操作的第一工作量。According to the first operation data amount and the first processing workload, the first workload of the preprocessing operation is obtained.
  11. 根据权利要求10所述的计量装置,其特征在于,所述匹配模块,还具体用于:The metering device according to claim 10, wherein the matching module is further specifically used for:
    按照所述执行器的数据执行操作的执行顺序,每检测到一个执行器执行所述数据执行操作,则获取当前执行器在执行数据执行操作时的第二操作数据量;According to the execution sequence of the data execution operations of the executors, each time an executor is detected to execute the data execution operation, obtain the second operation data amount of the current executor when the data execution operation is performed;
    从与所述预设的工作量表中,获取与当前执行器的数据执行操作所对应的单位操作数据量的第二处理工作量;From the preset workload table, obtain the second processing workload of the unit operation data volume corresponding to the data execution operation of the current executor;
    根据所述第二操作数据量及所述第二处理工作量,得到所述当前执行器的第二工作量。According to the second operation data amount and the second processing workload, the second workload of the current executor is obtained.
  12. 根据权利要求11所述的计量装置,其特征在于,所述工作量计算模块,具体用于:The metering device according to claim 11, wherein the workload calculation module is specifically used for:
    将所述第一工作量及依次获取到的所述第二工作量进行累计。The first workload and the sequentially acquired second workload are accumulated.
  13. 根据权利要求8所述的计量装置,其特征在于,所述生成模块,具体用于:The metering device according to claim 8, wherein the generating module is specifically used for:
    对用户产生的区块链交易进行解析,得到输入参数;Analyze the blockchain transaction generated by the user to obtain the input parameters;
    根据所述输入参数,从区块链账本中读取待执行的智能合约代码;According to the input parameters, read the smart contract code to be executed from the blockchain ledger;
    基于所述输入参数及所述智能合约代码,初始化智能合约虚拟机;Based on the input parameters and the smart contract code, initialize a smart contract virtual machine;
    控制所述智能合约虚拟机根据所述智能合约代码中智能合约的合约逻辑生成SQL查询语句。The smart contract virtual machine is controlled to generate an SQL query statement according to the contract logic of the smart contract in the smart contract code.
  14. 根据权利要求8所述的计量装置,其特征在于,该装置还包括:The metering device according to claim 8, characterized in that, the device further comprises:
    输出模块,用于在所述SQL查询引擎执行所述SQL查询语句过程中,若所述执行操作对应的工作总量超出阈值,则控制所述SQL查询引擎输出数据查询结果。An output module, configured to control the SQL query engine to output a data query result if the total amount of work corresponding to the execution operation exceeds a threshold during the process of executing the SQL query statement by the SQL query engine.
  15. 一种终端,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现如权利要求1至7任一项所述方法的步骤。A terminal, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, when the processor executes the computer program, the implementation of claims 1 to 7 The steps of any one of the methods.
  16. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1至7任一项所述方法的步骤。A computer-readable storage medium storing a computer program, characterized in that, when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
PCT/CN2020/140246 2020-12-28 2020-12-28 Metering method and device for data query workload in blockchain, and terminal WO2022140936A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/140246 WO2022140936A1 (en) 2020-12-28 2020-12-28 Metering method and device for data query workload in blockchain, and terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/140246 WO2022140936A1 (en) 2020-12-28 2020-12-28 Metering method and device for data query workload in blockchain, and terminal

Publications (1)

Publication Number Publication Date
WO2022140936A1 true WO2022140936A1 (en) 2022-07-07

Family

ID=82259015

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/140246 WO2022140936A1 (en) 2020-12-28 2020-12-28 Metering method and device for data query workload in blockchain, and terminal

Country Status (1)

Country Link
WO (1) WO2022140936A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115421698A (en) * 2022-08-30 2022-12-02 敏于行(北京)科技有限公司 Data processing method and device based on declarative and distributed accounts book and electronic device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109408513A (en) * 2018-10-23 2019-03-01 杭州能链科技有限公司 Data processing method, system and storage medium
CN110309196A (en) * 2019-05-22 2019-10-08 深圳壹账通智能科技有限公司 Block chain data storage and query method, apparatus, equipment and storage medium
US20200250177A1 (en) * 2019-01-31 2020-08-06 Salesforce.Com, Inc. Systems, methods, and apparatuses for implementing an sql query and filter mechanism for blockchain stored data using distributed ledger technology (dlt)
CN111680067A (en) * 2020-05-28 2020-09-18 中国工商银行股份有限公司 Data processing method, device and system based on block chain

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109408513A (en) * 2018-10-23 2019-03-01 杭州能链科技有限公司 Data processing method, system and storage medium
US20200250177A1 (en) * 2019-01-31 2020-08-06 Salesforce.Com, Inc. Systems, methods, and apparatuses for implementing an sql query and filter mechanism for blockchain stored data using distributed ledger technology (dlt)
CN110309196A (en) * 2019-05-22 2019-10-08 深圳壹账通智能科技有限公司 Block chain data storage and query method, apparatus, equipment and storage medium
CN111680067A (en) * 2020-05-28 2020-09-18 中国工商银行股份有限公司 Data processing method, device and system based on block chain

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115421698A (en) * 2022-08-30 2022-12-02 敏于行(北京)科技有限公司 Data processing method and device based on declarative and distributed accounts book and electronic device

Similar Documents

Publication Publication Date Title
JP5255000B2 (en) Query pattern to enable type flow of element types
US11106437B2 (en) Lookup table optimization for programming languages that target synchronous digital circuits
US8417690B2 (en) Automatically avoiding unconstrained cartesian product joins
CN111949650A (en) Multi-language fusion query method and multi-mode database system
CN110795455A (en) Dependency relationship analysis method, electronic device, computer device and readable storage medium
US20120150913A1 (en) Multidimensional data-centric service protocol
WO2019196239A1 (en) Method for managing thread interfaces, and terminal device and computer-readable storage medium
CN111443901B (en) Java reflection-based service expansion method and device
WO2022057357A1 (en) Data query method and apparatus, and database system
CN110351325A (en) A kind of data processing method and relevant device
WO2022140936A1 (en) Metering method and device for data query workload in blockchain, and terminal
CN113504900A (en) Programming language conversion method and device
WO2020151209A1 (en) Multi-dimensional data variable-based data interaction method and platform
CN107222363B (en) Storage protocol consistency test method and system
US20230004548A1 (en) Registering additional type systems using a hub data model for data processing
WO2018053889A1 (en) Distributed computing framework and distributed computing method
US20140122158A1 (en) License Meta-Model for Automatic License Reasoning
Viotti et al. A Benchmark of JSON-compatible Binary Serialization Specifications
US9342581B2 (en) System to disclose the internal structure of persistent database objects
CN111460021A (en) Data export method and device
CN114328486A (en) Data quality checking method and device based on model
CN107506299B (en) Code analysis method and terminal equipment
CN112667489B (en) Method and device for measuring data query workload in block chain and terminal
CN113703739A (en) Cross-language fusion computing method, system and terminal based on omiga engine
CN111158994A (en) Pressure testing performance testing method and device

Legal Events

Date Code Title Description
NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20967288

Country of ref document: EP

Kind code of ref document: A1