Query statement detection method, device, equipment and medium for distributed database
By obtaining node addresses and execution policies in a distributed database, generating and executing query statements, and dynamically comparing the execution results, the problem of low data verification efficiency of distributed database nodes is solved, and more efficient query statement detection is achieved.
Patent Information
- Application Number
- CN202410307771.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-18
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2044-03-18
AI Technical Summary
In the process of data inspection of distributed database nodes, the inspection efficiency of the existing technology is low and requires maintenance of query cycles.
By obtaining the node address and execution policy in the distributed database, generating query statements, and executing query statements according to the policy, the execution results of each node are obtained. Then, for each node, a dynamic reference node is selected for comparison and the detection results are obtained. Adopt parallel execution strategies to improve efficiency.
There is no need to expect execution results, which reduces the difficulty of maintaining test cases. Choosing a parallel execution strategy can improve execution and comparison efficiency, thereby improving the detection efficiency of query statements.
Smart Images

Figure CN117992357B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and in particular, to a method, device, equipment and medium for detecting query statements of a distributed database. Background Art
[0002] With the rise of the mobile Internet, the data scale has exploded. Distributed databases with data sharding capabilities have become increasingly mature and are favored by more and more enterprises. Distributed databases have developed rapidly in China, and more and more enterprises have joined the trend of distributed database product research and development. However, distributed databases have many nodes, complex processing processes, and diverse objects. It is crucial to verify whether the node data is consistent. In the prior art, when verifying the node data in a distributed database, generally, the execution results of query statements are detected. Usually, fixed query expectations are uploaded, and the execution results of each node are compared with the expected results one by one. However, the query cycle needs to be maintained, resulting in low verification efficiency. Therefore, in the process of verifying the node data of a distributed database, how to improve the verification efficiency has become an urgent problem to be solved. Summary of the Invention
[0003] In view of this, the embodiments of the present application provide a method, device, equipment and medium for detecting query statements of a distributed database to solve the problem of low verification efficiency in the process of verifying the node data of a distributed database.
[0004] In a first aspect, the embodiments of the present application provide a method for detecting query statements of a distributed database. The distributed database includes N nodes, where N is an integer greater than zero. The query statement detection method includes:
[0005] Obtain the objects to be tested of the N nodes in the distributed database, the node addresses of the N nodes in the distributed database, and the execution strategy of the distributed database;
[0006] Generate query statements for the N nodes according to the objects to be tested of the N nodes;
[0007] Execute the query statements according to the execution strategy to obtain the execution results of the N nodes;
[0008] For any current node, determine the reference node of the current node among the N nodes, and compare the execution result of the current node with the execution result of the reference node to obtain a comparison result;
[0009] Obtain the detection result of the query statement according to the comparison result.
[0010] Second aspect, an embodiment of the present application provides a query statement detection device for a distributed database. The distributed database includes N nodes, where N is an integer greater than zero. The query statement detection device includes:
[0011] An acquisition module, configured to acquire the objects to be tested of the N nodes in the distributed database, the node addresses of the N nodes in the distributed database, and the execution strategy of the distributed database;
[0012] A generation module, configured to generate query statements for the N nodes according to the objects to be tested of the N nodes;
[0013] An execution module, configured to execute the query statements according to the execution strategy to obtain execution results of the N nodes;
[0014] A comparison module, configured to determine a reference node of a current node among the N nodes for any current node, and compare the execution result of the current node with the execution result of the reference node to obtain a comparison result;
[0015] A result obtaining module, configured to obtain a detection result of the query statement according to the comparison result.
[0016] Third aspect, an embodiment of the present application provides a network device. The network device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the query statement detection method described in the first aspect is implemented.
[0017] Fourth aspect, an embodiment of the present application provides a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the query statement detection method described in the first aspect is implemented.
[0018] The beneficial effects of the present invention compared with the prior art are:
[0019] Obtain the objects to be tested of N nodes in the distributed database, the node addresses of the N nodes in the distributed database, and the execution strategy of the distributed database. Generate query statements for the N nodes according to the objects to be tested of the N nodes. Execute the query statements according to the execution strategy to obtain the execution results of the N nodes. For any current node, determine the reference node of the current node among the N nodes. Compare the execution result of the current node with the execution result of the reference node to obtain a comparison result. Obtain the detection result of the query statement according to the comparison result. In this application, a corresponding reference node is selected for each current node, where the reference node is not unique and is a dynamic reference node. When comparing the execution results among the N nodes, the expected execution result is not required, which reduces the difficulty of maintaining test cases. Moreover, when the selected execution strategy is parallel, the execution and comparison efficiency can be improved, thereby improving the detection efficiency of the query statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0021] Figure 1 FIG. is a schematic diagram of an application environment of a method for detecting query statements of a distributed database provided in Embodiment 1 of this application;
[0022] Figure 2 FIG. is a schematic flowchart of a method for detecting query statements of a distributed database provided in Embodiment 2 of this application;
[0023] Figure 3 FIG. is a schematic flowchart of a method for detecting query statements of a distributed database provided in Embodiment 3 of this application;
[0024] Figure 4 FIG. is a schematic flowchart of a method for detecting query statements of a distributed database provided in Embodiment 4 of this application;
[0025] Figure 5 FIG. is a schematic flowchart of a method for detecting query statements of a distributed database provided in Embodiment 5 of this application;
[0026] Figure 6 FIG. is a schematic flowchart of a method for detecting query statements of a distributed database provided in Embodiment 6 of this application;
[0027] Figure 7 FIG. is a schematic structural diagram of a device for detecting query statements of a distributed database provided in Embodiment 7 of this application;
[0028] Figure 8 It is a schematic structural diagram of a network device provided in Embodiment 8 of the present application. Detailed implementation manners
[0029] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0030] It should be understood that when used in the specification of the present application and the appended claims, the term "comprising" indicates the presence of the described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their combinations.
[0031] It should also be understood that the term "and / or" used in the specification of the present application and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0032] As used in the specification of the present application and the appended claims, the term "if" can be interpreted as "when", "once", "in response to determining" or "in response to detecting" according to the context. Similarly, the phrase "if determined" or "if detecting [the described condition or event]" can be interpreted as meaning "once determined", "in response to determining", "once detecting [the described condition or event]" or "in response to detecting [the described condition or event]" according to the context.
[0033] In addition, in the description of the specification of the present application and the appended claims, the terms "first", "second", "third", etc. are only used for distinguishing descriptions, and cannot be understood as indicating or implying relative importance.
[0034] The reference to "one embodiment" or "some embodiments" etc. described in the specification of the present application means that a specific feature, structure or characteristic described in combination with the embodiment is included in one or more embodiments of the present application. Thus, the statements "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "comprising", "including", "having" and their variants all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0035] It should be understood that the sequence numbers of the steps in the following embodiments do not indicate the order of execution, and the order of execution of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0036] In order to illustrate the technical solution of the present application, it will be described below through specific embodiments.
[0037] A query statement detection method for a distributed database provided in Embodiment 1 of the present application can be applied to an application environment such as Figure 1 , where the central server is connected to each node server, and the network device corresponding to the server can be implemented by an independent server or a server cluster composed of multiple servers.
[0038] See Figure 2 , which is a schematic flowchart of a query statement detection method for a distributed database provided in Embodiment 2 of the present application. As Figure 2 shown, the query statement detection method for the distributed database may include the following steps:
[0039] S201: Obtain the objects to be tested of N nodes in the distributed database, the node addresses of N nodes in the distributed database, and the execution strategy of the distributed database.
[0040] In step S201, the distributed database includes N nodes, where N is an integer greater than zero. Obtain the objects to be tested of N nodes in the distributed database, the node addresses of N nodes in the distributed database, and the execution strategy of the distributed database. Among them, the object to be tested is a set of data to be tested, and the node addresses of N nodes are the IP (Internet Protocol Address) addresses of the corresponding nodes, so as to execute the query statement in the corresponding node. The execution strategy may include parallel execution and serial execution. Parallel execution means that each node simultaneously executes the query statement of the corresponding node, and serial execution means that the query statements corresponding to each node are executed in sequence.
[0041] In this embodiment, the distributed database may be a homogeneous database, that is, the data in each node should be the same data. The objects to be tested of N nodes in the distributed database, the node addresses of N nodes in the distributed database, and the execution strategy of the distributed database can be determined in the central server.
[0042] It should be noted that the object to be tested may be the data of a certain data table, or the data in a certain column of the data table, where the data in a certain column is the common column of the data tables in each node.
[0043] S202: Generate query statements for N nodes according to the objects to be tested of N nodes.
[0044] In step S202, query statements for N nodes are generated according to the objects to be tested of the N nodes. The query statements for the N nodes can be statements in any syntax in the database. For example, they can be SQL (Structured Query Language) statements.
[0045] In this embodiment, corresponding query statements are respectively generated for each of the N nodes. For example, if the query statement is an SQL statement, the corresponding query statement can be "sql": "select * from obj$", "node_info": "192.168.6.151:1601", where the query statement is an SQL statement, the object to be queried is the obj$ object, and the address of the corresponding node is 192.168.6.151:1601, so as to execute the corresponding query statement in the corresponding node. The corresponding query statement can also be "sql": "select * from obj$", "node_info": "192.168.6.151:1602", where the query statement is an SQL statement, the object to be queried is the obj$ object, and the address of the corresponding node is 192.168.6.151:1602.
[0046] It should be noted that the query statement can be a query command written in the structured query language or other languages, mainly used to query the data stored in the data table. Each query statement can include a table name, fields, and keywords. Generally, the "columns" in each data table are called "fields", each field contains information on a certain topic, the "rows" in the data table are called "records", each record contains all the information in this row, and the data at the intersection of the rows and columns of the data table is called a "value", which can include letters, Chinese characters, and characters, etc. The keyword mentioned here is a value, and the data to be queried is a record.
[0047] It should be noted that since the query statement generally has a default fixed format, and the program cannot read a query statement that does not conform to the format, before performing relevant query operations according to the query statement, it is necessary to pre-detect whether the format of the query statement meets the requirements.
[0048] It should be noted that the query statement can also include columns to be queried. If the object being queried is an object name, it is judged whether there is a projection column mapping relationship for obtaining the object. If there is a projection column mapping relationship, the respective projection columns are concatenated into column_list separated by ",", and if the passed-in object is one, it means that the reference object and the object under test are the same, and * is directly used as column_list. If they are isomorphic and the query objects of each node have the same column_list, then there is no need to pass in the projection column mapping, and the object name can be directly used as a condition to obtain the common columns from the system table dba_tab_columns and concatenate them into column_list separated by ",". For example, when the single-node view v$lsc_slice_stat is used as the query object and the distributed view dv$lsc_slice_stat is used as the query object, the obtained common column_list is: bo,obj,dataobj,slice_id,status,scn,space_id,slice_file_id,file_size,row_count,row_group_num. The select_list is generated by connecting column_list and the object name. The select_list for the single-node view v$lsc_slice_stat is: select bo,obj,dataobj,slice_id,status,scn,space_id,slice_file_id,file_size,row_count,row_group_num from v$lsc_slice_stat, and the select_list for the distributed view dv$lsc_slice_stat is: bo,obj,dataobj,slice_id,status,scn,space_id,slice_file_id,file_size,row_count,row_group_num from dv$lsc_slice_stat.
[0049] It should be noted that if there are filtering conditions in the query statement, the filtering conditions are concatenated and ended with ";". For example, if the filtering condition is where group_id = 1 and group_node_id = 1, the query statement obtained by concatenating the filtering conditions in the select_list is: select bo, obj, dataobj, slice_id, status, scn, space_id, slice_file_id, file_size, row_count, row_group_num from v$lsc_slice_stat.
[0050] It should be noted that N nodes generate N query statements according to the corresponding node addresses. Among them, the N query statements can be generated in the form of a list. For example, if the node addresses of the N nodes are "192.168.6.151:1601" and "192.168.6.151:1602", the generated list can be {"sql": "select * from obj$", "node_info":
[0051] "192.168.6.151:1601"}, {"sql": "select * from obj$", "node_info": "192.168.6.151:1602"}.
[0052] S203: Execute the query statement according to the execution policy to obtain the execution results of N nodes.
[0053] In step S203, execute the query statement according to the execution policy to obtain the execution results of N nodes. Among them, the execution policy can be serial execution or parallel execution, and the execution result is the query result of the object to be queried in the query statement.
[0054] In this embodiment, execute the query statement according to the execution policy to obtain the execution results of N nodes. Among them, when executing the query statement, send the corresponding query statement to the corresponding target node according to the node address in each query statement, and execute the corresponding query statement in the corresponding target node. For example, if the corresponding query statement is {"sql": "select * from obj$", "node_info": "192.168.6.151:1601"}, the node address of the corresponding target node is "192.168.6.151:1601", then send the query statement to the node with the node address "192.168.6.151:1601" to execute the corresponding query statement, that is, query the object of obj$ in the target node.
[0055] SeeFigure 3 , which is a schematic flowchart of a method for detecting query statements of a distributed database provided in Embodiment 3 of this application. As Figure 3 shown, in step S203, according to the execution policy, the query statement is executed to obtain the execution results of N nodes, which may include the following steps:
[0056] S301: If the execution policy is serial execution, the N nodes sequentially execute the query statements in the corresponding nodes according to the preset execution order, and sequentially obtain the execution results of the corresponding statements of each node;
[0057] S302: If the execution policy is parallel execution, the N nodes execute the query statements in the corresponding nodes in parallel, and obtain the execution results of the corresponding statements of each node in parallel.
[0058] In this embodiment, the execution policy includes serial execution and parallel execution. In serial execution, each node is sequentially executed according to the preset execution order. In parallel execution, each node simultaneously executes the corresponding query statement, and obtains the execution results of the corresponding statements of each node in parallel.
[0059] It should be noted that when performing parallel execution, the time of the obtained execution results may be different according to the execution speed of each node.
[0060] It should be noted that each node may include multiple threads, and each thread executes the task of the query statement. Therefore, multiple tasks corresponding to the query statements can be executed in each node.
[0061] S204: For any current node, determine the reference node of the current node among the N nodes, and compare the execution result of the current node with the execution result of the reference node to obtain a comparison result.
[0062] In step S204, after each node obtains the corresponding execution result, dynamic comparison is performed. During dynamic comparison, a reference node and a current node are selected, and the execution result of the current node is compared with the execution result of the reference node to obtain a comparison result, where the current node is the node whose execution result is to be detected, and the reference node is the node whose execution result is used as the reference execution result.
[0063] In this embodiment, for any current node, a reference node of the current node is determined among the N nodes, and the execution result of the current node is compared with the execution result of the reference node to obtain a comparison result. When selecting the reference node, any node among the N nodes can be selected. For example, if each node only includes one thread, that is, each node only executes the task of one query statement, the reference node can be other nodes except the current node. If one of the nodes includes two or more threads, that is, each node can execute multiple query statements, the reference node can be the same node as the current node.
[0064] It should be noted that when comparing the execution result of the current node with the execution result of the reference node, the execution results can be directly compared, or the files of the execution results can be compared, that is, the execution results are stored in the corresponding files, and the files containing the execution results are compared.
[0065] See Figure 4 , which is a schematic flowchart of a method for detecting query statements in a distributed database provided in Embodiment 4 of this application. As Figure 4 shown, in step S204, for any current node, a reference node of the current node is determined among the N nodes, and the execution result of the current node is compared with the execution result of the reference node to obtain a comparison result, which may include the following steps:
[0066] S401: If the execution policy is serial execution, for any current node, the previous node corresponding to the current node in the execution order is used as the reference node;
[0067] S402: If the execution policy is parallel execution, for any current node, the previous node or the next node where the current node is located is used as the reference node.
[0068] In this embodiment, for different execution policies, the methods of selecting corresponding reference nodes are different. If the execution policy is serial execution, for any current node, the previous node corresponding to the current node in the execution order is used as the reference node. That is, each node performs the execution of the query statement detection according to the corresponding execution order. When selecting the reference node, the corresponding reference node can be selected according to the execution order, and the previous node of the current node is used as the reference node. For example, if the execution policy is serial execution and the execution order is the first node, the second node, the third node, etc., then the first node in the execution order starts to execute the task of the corresponding query statement to obtain the execution result of the first node. The second node in the execution order starts to execute the task of the corresponding query statement to obtain the execution result of the second node. Then, if the second node is the current node, the first node is the previous node of the second node, and the first node is used as the reference node, and the execution result of the first node is compared with the execution result of the second node. The third node in the execution order starts to execute the task of the corresponding query statement to obtain the execution result of the third node. Then, if the third node is the current node, the second node is the previous node of the third node, and the third node is used as the reference node, and the execution result of the third node is compared with the execution result of the second node.
[0069] If the execution policy is parallel execution, for any current node, the previous node or the next node where the current node is located is used as the reference node. In parallel execution, N nodes execute simultaneously. One of the adjacent two nodes is used as the current node, and the other node is used as the reference node, that is, the execution results of the adjacent two nodes are compared. Among them, the adjacent two nodes can be determined according to the node address. For example, if the node addresses are "192.168.6.151:1601", "192.168.6.151:1602" and "192.168.6.152:1601", the nodes with the node addresses "192.168.6.151:1601" and "192.168.6.151:1602" can be used as adjacent nodes. For any current node, the previous node or the next node where the current node is located is used as the reference node. For example, if the node address of the current node is the node with "192.168.6.151:1602", the reference node can be the node with the node address "192.168.6.151:1601", or can also be the node with the node address "192.168.6.152:1601".
[0070] S205: Obtain the detection result of the query statement according to the comparison result.
[0071] In step S205, obtain the detection result of the query statement according to the comparison result. The detection result can be detection passed or detection failed.
[0072] In this embodiment, according to the comparison result, the detection result of the query statement is obtained. Among them, the comparison result includes the comparison results of all reference nodes and the current node pairs. For example, when there are three nodes, the reference node and the current node pair include 2 pairs. According to the comparison results of the execution results of the reference nodes and the current nodes in the 2 pairs, the detection result of the query statement is obtained. When there are 6 nodes, the reference node and the current node pair include 5 pairs. According to the comparison results of the execution results of the reference nodes and the current nodes in the 5 pairs, the detection result of the query statement is obtained. According to the corresponding number of nodes, the reference node and the current node pair are determined, and according to the comparison results of the reference node and the current node in each pair, the detection result of the query statement is obtained.
[0073] See Figure 5 , which is a schematic flowchart of a method for detecting a query statement of a distributed database provided in Embodiment 5 of this application. As Figure 5 shown, according to the comparison result in step S205, obtaining the detection result of the query statement may include the following steps:
[0074] S501: If the comparison results of the execution results of each current node among the N nodes and the execution results of the corresponding reference nodes are all equal, then determine that the detection result of the query statement is passed;
[0075] S502: If there is a comparison result that is not equal between the execution result of a current node among the N nodes and the execution result of the corresponding reference node, then determine that the detection result of the query statement is not passed.
[0076] In this embodiment, if the comparison results of the execution results of each current node among the N nodes and the execution results of the corresponding reference nodes are all equal, then determine that the detection result of the query statement is passed. For example, the reference node and the current node pair include 2 pairs. If the execution strategy is serial execution, and the execution order is the first node, the second node, the third node, etc. The second node and the first node are a pair of current node and reference node. According to the execution result of the second node and the execution result of the first node, the first comparison result is obtained. The third node and the second node are a pair of current node and reference node. According to the execution result of the third node and the execution result of the second node, the second comparison result is obtained. If the first comparison result and the second comparison result are both equal, then determine that the detection result of the query statement is passed.
[0077] If the comparison result between the execution result of a current node among N nodes and the execution result of the corresponding reference node is not equal, the detection result of the query statement is determined to be a failed detection. For example, there are 2 pairs of reference nodes and current nodes. If the execution policy is serial execution, and the execution order is the first node, the second node, the third node, etc. The second node and the first node form a pair of current node and reference node. According to the execution result of the second node and the execution result of the first node, the first comparison result is obtained. The third node and the second node form a pair of current node and reference node. According to the execution result of the third node and the execution result of the second node, the second comparison result is obtained. If one of the first comparison result and the second comparison result is not equal, it is considered that the detection result of the query statement is determined to be a failed detection.
[0078] See Figure 6 , which is a schematic flowchart of a method for detecting query statements in a distributed database provided in Embodiment 6 of the present application. As Figure 6 shown, before obtaining the detection result of the query statement according to the comparison result, the following steps may further be included:
[0079] S601: Obtain the expected execution result;
[0080] S602: If the execution policy is serial execution, compare the expected execution result with the execution result of each node to obtain a comparison result;
[0081] S603: If the execution policy is parallel execution, rank the expected execution result first, rank the execution results of the N nodes behind the expected execution result, sort according to the obtained order of the execution results to obtain the sorting result of N + 1 execution results, and compare the current execution result in the sorting result of N + 1 execution results with the next execution result of the current execution result to obtain a comparison result.
[0082] In this embodiment, if the corresponding expected execution result is obtained in advance, that is, the standard query result that the query statement should query, if the execution policy is serial execution, the expected execution result is compared with the execution result of each node to obtain a comparison result. That is, the node corresponding to the expected execution result is used as the reference node, the N nodes for executing the query statement are used as the current nodes, and the execution result obtained by the current node is compared with the execution result of the reference node to obtain a comparison result.
[0083] It should be noted that the node for obtaining the expected execution result can be one of the N nodes, or it can be the expected execution result pre-obtained by the distributed database, that is, the execution result not obtained from the N nodes. For example, if the node for obtaining the expected execution result is one of the N nodes, the execution result obtained by the node with the first execution order can be used as the expected execution result, and the expected execution result is compared with the execution results of the remaining N - 1 nodes. If the node for obtaining the expected execution result is the execution result not obtained from the N nodes, the expected execution result is compared with the execution result of each of the N nodes.
[0084] If the execution strategy is parallel execution, the expected execution result is ranked first, the execution results of the N nodes are ranked behind the expected execution result, and sorted according to the order of the obtained execution results to obtain the sorting result of N + 1 execution results. The current execution result in the sorting result of the N + 1 execution results is compared with the next execution result of the current execution result to obtain the comparison result. For example, if there are 3 nodes, namely the first node, the second node, and the third node, the 3 nodes simultaneously execute the task of the query statement, and the order of the obtained execution results is the third node, the first node, and the second node in sequence, obtaining 3 execution results. Adding the obtained expected execution result, 4 execution results are obtained. When sorting the 4 execution results, they are sorted according to the order in which the execution results are obtained, which are, in sequence, the expected execution result, the execution result of the third node, the execution result of the first node, and the second execution result. The current execution result in the sorting result of the N + 1 execution results is compared with the next execution result of the current execution result to obtain the comparison result, that is, the expected execution result is compared with the execution result of the third node, the execution result of the third node is compared with the execution result of the first node, and the execution result of the first node is compared with the second execution result.
[0085] In another embodiment, an execution result can be selected from the execution results of N nodes as the expected execution result, that is, the dynamic expected execution result. When the execution policy is parallel execution, the execution results obtained are sorted according to the order, and the sorting result of the N execution results is obtained. The execution result ranked first in the sorting result is used as the expected execution result. The current execution result in the sorting result of the N execution results is compared with the next execution result of the current execution result to obtain a comparison result. For example, if there are 3 nodes, namely the first node, the second node, and the third node, and the order of obtaining the execution results is the third node, the first node, and the second node in sequence, and 3 execution results are obtained. When sorting, they are sorted according to the order in which the execution results are obtained, that is, the execution result of the third node, the execution result of the first node, and the second execution result. The execution result of the third node is used as the expected execution result, and the current execution result in the sorting result of the 3 execution results is compared with the next execution result of the current execution result to obtain a comparison result, that is, the execution result of the third node (expected execution result) is compared with the execution result of the first node, and the execution result of the first node is compared with the execution result of the second node.
[0086] Obtain the objects to be tested of N nodes in the distributed database, the node addresses of N nodes in the distributed database, and the execution policy of the distributed database. Generate query statements for N nodes according to the objects to be tested of N nodes. Execute the query statements according to the execution policy to obtain the execution results of N nodes. For any current node, determine the reference node of the current node among N nodes, compare the execution result of the current node with the execution result of the reference node to obtain a comparison result, and obtain the detection result of the query statement according to the comparison result. In this application, a corresponding reference node is selected for each current node, where the reference node is not unique and is a dynamic reference node. When comparing the execution results between N nodes, no expected execution result is required, which reduces the difficulty of maintaining test cases. And when the selected execution policy is parallel, the execution and comparison efficiency can be improved, thereby improving the detection efficiency of the query statement.
[0087] Please refer to Figure 7 , Figure 7 which is a schematic structural diagram of a query statement detection device for a distributed database provided in Embodiment 7 of the present invention. Specifically, please refer to Figures 2 - 6 and Figures 2 - 6 the relevant descriptions in the corresponding embodiments. For the sake of convenience of description, only the parts related to this embodiment are shown. As Figure 7 shown, the query statement detection device 70 includes: an acquisition module 71, a generation module 72, an execution module 73, a comparison module 74, and a obtaining module 75.
[0088] An acquisition module 71, configured to acquire objects to be tested of N nodes in a distributed database, node addresses of the N nodes in the distributed database, and an execution policy of the distributed database.
[0089] A generation module 72, configured to generate query statements for the N nodes according to the objects to be tested of the N nodes.
[0090] An execution module 73, configured to execute the query statements according to the execution policy to obtain execution results of the N nodes.
[0091] A comparison module 74, configured to determine a reference node of a current node among the N nodes for any current node, and compare the execution result of the current node with the execution result of the reference node to obtain a comparison result.
[0092] A result obtaining module 75, configured to obtain a detection result of the query statement according to the comparison result.
[0093] Optionally, the execution module 73 includes:
[0094] A first execution unit, configured to, if the execution policy is serial execution, the N nodes sequentially execute the query statements in the corresponding nodes according to a preset execution order, and sequentially obtain the execution results of the corresponding statements of each node.
[0095] A second execution unit, configured to, if the execution policy is parallel execution, the N nodes parallelly execute the query statements in the corresponding nodes, and parallelly obtain the execution results of the corresponding statements of each node.
[0096] Optionally, the comparison module 74 includes:
[0097] A first judgment unit, configured to, if the execution policy is serial execution, for any current node, use the previous node corresponding to the current node in the execution order as the reference node.
[0098] A second judgment unit, configured to, if the execution policy is parallel execution, for any current node, use the previous node or the next node where the current node is located as the reference node.
[0099] Optionally, the result obtaining module 75 includes:
[0100] A third judgment unit, configured to, if the comparison results of the execution results of each current node among the N nodes and the execution results of the corresponding reference nodes are all equal, determine that the detection result of the query statement is passed.
[0101] A fourth judgment unit, configured to, if there is a comparison result of the execution result of a current node among the N nodes and the execution result of the corresponding reference node that is not equal, determine that the detection result of the query statement is not passed.
[0102] Optionally, the query statement detection device 70 further includes:
[0103] An expected execution result acquisition module, configured to acquire an expected execution result.
[0104] A first comparison module, configured to, if the execution policy is serial execution, compare the expected execution result with the execution results of each node to obtain a comparison result.
[0105] A second comparison module, configured to, if the execution policy is parallel execution, rank the expected execution result first, rank the execution results of N nodes behind the expected execution result, sort according to the obtained order of the execution results to obtain a sorting result of N + 1 execution results, and compare the current execution result in the sorting result of N + 1 execution results with the next execution result of the current execution result to obtain a comparison result.
[0106] It should be noted that, for the information interaction, execution process, etc. between the above modules, since they are based on the same concept as the method embodiments of the present application, their specific functions and the technical effects brought thereby can be specifically referred to in the method embodiment part, and will not be elaborated herein.
[0107] Figure 8 This is a schematic structural diagram of a network device provided in Embodiment 8 of the present application. As Figure 8 shown, the network device of this embodiment includes: at least one processor ( Figure 8 only one is shown in the figure), a memory, and a computer program stored in the memory and executable on at least one processor. When the processor executes the computer program, the steps in any of the above method embodiments for detecting query statements of a distributed database are implemented.
[0108] The network device may include, but is not limited to, a processor and a memory. Those skilled in the art can understand that Figure 8 this is only an example of a network device and does not constitute a limitation on the network device. The network device may include more or fewer components than shown in the figure, or combine some components, or different components. For example, it may further include a network interface, etc.
[0109] The so-called processor may be a CPU, and the processor may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0110] The memory includes a readable storage medium, internal memory, etc. Among them, the internal memory may be the memory of the network device, and the internal memory provides an environment for the operation of the operating system and computer-readable instructions in the readable storage medium. The readable storage medium may be the hard disk of the network device, and in some other embodiments, it may also be an external storage device of the network device. For example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the network device. Further, the memory may also include both the internal storage unit of the network device and the external storage device. The memory is used to store the operating system, application programs, boot loaders, data, and other programs, such as the program code of computer programs. The memory may also be used to temporarily store the data that has been output or will be output.
[0111] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiments can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of this application. The specific working processes of the units and modules in the above device can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated here. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above method embodiments of this application, a computer program can be used to instruct the relevant hardware to complete. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can at least include: any entity or device that can carry the computer program code, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk, or an optical disc, etc. In some jurisdictions, according to legislation and patent practice, the computer-readable medium cannot be an electrical carrier signal and a telecommunication signal.
[0112] To implement all or part of the processes in the above method embodiments of this application, it can also be completed by a computer program product. When the computer program product runs on a network device, the network device can be made to execute the steps in the above method embodiments when executed.
[0113] In the above embodiments, the descriptions of each embodiment have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0114] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of this application.
[0115] In the embodiments provided in this application, it should be understood that the disclosed devices / network devices and methods can be implemented in other ways. For example, the device / network device embodiments described above are merely illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of devices or units can be in an electrical, mechanical or other form.
[0116] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place, or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0117] The above embodiments are only used to illustrate the technical solutions of this application, rather than to limit it; although this application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; 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 of the embodiments of this application, and should all be included in the protection scope of this application.
Claims
1. A query statement detection method for a distributed database, characterized in that: The distributed database includes N nodes, where N is an integer greater than zero. The query statement detection method includes: Obtaining the objects to be tested of the N nodes in the distributed database, the node addresses of the N nodes in the distributed database, and the execution strategy of the distributed database; Generate query statements for the N nodes according to the objects to be tested of the N nodes, where the query statements for the N nodes are the same query statements or different query statements; If the execution strategy is serial execution, the N nodes execute the query statements in the corresponding nodes in sequence according to the preset execution order, and obtain the execution results of the corresponding statements of each node in sequence; if the execution strategy is parallel execution, the N nodes execute the query statements in the corresponding nodes in parallel, and obtain the execution results of the corresponding statements of each node in parallel; Select the corresponding reference node according to the execution order. If the execution strategy is serial execution, for any current node, use the previous node corresponding to the current node in the execution order as the reference node. If the execution strategy is parallel execution, for any current node, use the previous node or the next node where the current node is located as the reference node, compare the execution result of the current node with the execution result of the reference node, and obtain the comparison result; If the comparison result of the execution result of each current node among the N nodes is equal to the execution result of the corresponding reference node, the detection result of the query statement is determined as passed; If the comparison result of the execution result of a current node among the N nodes is not equal to the execution result of the corresponding reference node, the detection result of the query statement is determined as failure to pass the detection; Also includes: If the execution strategy is parallel execution, the execution results are sorted according to the order of the obtained execution results to obtain a sorted result of N execution results, the execution result ranked first in the sorted result is used as the expected execution result, and the current execution result in the sorted result of the N execution results is compared with the execution result after the current execution result to obtain a comparison result; According to the comparison result, a detection result of the query statement is obtained.
2. The query statement detection method according to claim 1, characterized in that: Before obtaining the detection result of the query statement according to the comparison result, the method further includes: Get the expected execution results; If the execution strategy is serial execution, the expected execution result is compared with the execution result of each node to obtain a comparison result; If the execution strategy is parallel execution, the expected execution result is ranked first, and the execution results of the N nodes are ranked behind the expected execution result. The execution results are sorted according to the order of the obtained execution results to obtain the sorted results of N+1 execution results. The current execution result in the sorted results of the N+1 execution results is compared with the execution result after the current execution result to obtain the comparison result.
3. A query statement detection device for a distributed database, characterized in that: The distributed database includes N nodes, where N is an integer greater than zero. The query statement detection device includes: An acquisition module, used to acquire the objects to be tested of the N nodes in the distributed database, the node addresses of the N nodes in the distributed database and the execution strategy of the distributed database; A generating module, used for generating query statements of the N nodes according to the objects to be tested of the N nodes, wherein the query statements of the N nodes are the same query statements or different query statements; An execution module, for, if the execution strategy is serial execution, the N nodes sequentially execute the query statements in the corresponding nodes according to a preset execution order, and sequentially obtain the execution results of the corresponding statements of each node; if the execution strategy is parallel execution, the N nodes parallelly execute the query statements in the corresponding nodes, and parallelly obtain the execution results of the corresponding statements of each node; A comparison module is used to select a corresponding reference node according to the execution order. If the execution strategy is serial execution, for any current node, the previous node corresponding to the current node in the execution order is used as the reference node. If the execution strategy is parallel execution, for any current node, the previous node or the next node where the current node is located is used as the reference node, and the execution result of the current node is compared with the execution result of the reference node to obtain a comparison result. An obtaining module is used to determine the detection result of the query statement as passed if the comparison result of the execution result of each current node in the N nodes is equal to the execution result of the corresponding reference node; If the comparison result of the execution result of a current node among the N nodes is not equal to the execution result of the corresponding reference node, the detection result of the query statement is determined as failure to pass the detection; Also includes: If the execution strategy is parallel execution, the execution results are sorted according to the order of the obtained execution results to obtain a sorted result of N execution results, the execution result ranked first in the sorted result is used as the expected execution result, and the current execution result in the sorted result of the N execution results is compared with the execution result after the current execution result to obtain a comparison result; According to the comparison result, a detection result of the query statement is obtained.
4. A network device, characterized in that: The network device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the query statement detection method according to any one of claims 1 to 2 is implemented.
5. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the query statement detection method according to any one of claims 1 to 2 is implemented.
Citation Information
Patent Citations
Distributed space data enquiring and optimizing method under gridding calculation environment
CN101408900A
Nested query method oriented to mass distributed-type database
CN104090962A