Data query method, device, equipment and computer readable storage medium

By establishing a statistical tree model library, matching the target statistical tree model to determine the data statistical values ​​that meet the conditions in the database, the problem of low database query efficiency is solved and fast and accurate data query is achieved.

CN114385708BActive Publication Date: 2025-03-28CHONGQING COMM CONSTR CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111598825.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2025-03-28
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

In the prior art, when a database querys the total number of data that meets the conditions, it is necessary to conduct a comprehensive scan of the data in the database, resulting in low query efficiency.

Method used

By establishing a preset statistical tree model library, matching the target statistical tree model according to the query field conditions, directly determining the data statistics in the database that meets the conditions, avoiding full table scanning.

Benefits of technology

It improves the efficiency of data query, can quickly process complex query conditions, and ensures the accuracy of query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114385708B_ABST
    Figure CN114385708B_ABST
Patent Text Reader

Abstract

The present application provides a data query method, apparatus, device and computer-readable storage medium, which can match a target statistical tree model according to the query field conditions to be queried. Since each node in the target statistical tree model records the statistical value of the query field under the corresponding limited data, the statistical value of the data in the database that meets the query field conditions to be queried can be directly determined according to the information recorded in the corresponding node in the target statistical tree model, without the need to fully scan the data in the database, and the query efficiency is higher.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data query method, device, equipment and computer-readable storage medium. Background Art

[0002] A large amount of data is stored in the database. In many business scenarios, it is usually necessary to query the data in the database according to actual business needs. For example, when querying the total number of data that meets the conditions, the current common practice is to perform a comprehensive scan of the data in the database, accumulate the total number of data that meet the query conditions, and then return the results. As the amount of data increases, the scanning time becomes longer and longer, and the performance becomes lower and lower, which cannot meet the usage needs in actual scenarios. Summary of the invention

[0003] The purpose of the embodiments of the present application is to provide a data query method, device, equipment and computer-readable storage medium to solve the problem in the prior art that when querying the total number of data that meets the conditions in a database, it is necessary to fully scan the data in the database and accumulate the total number that meets the query conditions, resulting in low query efficiency.

[0004] The present application provides a data query method, the method comprising:

[0005] Obtaining a query field condition to be queried, wherein the query field condition includes information of the query field in a database and limiting data corresponding to the query field;

[0006] According to the query field condition, a target statistical tree model is matched from a preset statistical tree model library, each statistical tree model in the statistical tree model library includes a node layer generated according to the database and the preset query field condition, each node in the node layer respectively records the query field information, the limited data corresponding to the node and the statistical value, the statistical value recorded in each node in the node layer is the total number of data statistics corresponding to the query field recorded in the node when the limited data recorded in the node is met, and the query field information recorded in each node in the node layer is the same;

[0007] According to the query field condition to be queried and the statistical value recorded in the corresponding node in the target statistical tree model, the data statistical value of the database that meets the query field condition to be queried is determined.

[0008] In the above implementation process, the target statistical tree model can be matched according to the query field conditions to be queried. Since each node in the target statistical tree model records the statistical value of the query field under the corresponding limited data, the statistical value of the data in the database that meets the query field conditions to be queried can be directly determined according to the information recorded in the corresponding node in the target statistical tree model. There is no need to fully scan the data in the database, and the query efficiency is higher.

[0009] Furthermore, there is at least one statistical tree model in the statistical tree model library, which includes at least two node layers. The statistical value recorded in each node in the first node layer of the statistical tree model is the total number of data statistics in the database when the query field recorded in the node meets the restricted data of the node record, and the statistical value recorded in each node in the i-th node layer is the total number of data statistics in the database when the query field corresponding to the i-th node layer meets the restricted data corresponding to the node and meets the corresponding node of the i-1th layer. i is an integer greater than 1, and the information of the query field recorded in each node in the same node layer is the same.

[0010] In the above implementation process, since a statistical tree model including multiple node layers is provided, diversified queries can be implemented based on the specific conditions of the node layers.

[0011] Further, the query field condition to be queried includes information of at least two query fields and a logical operation relationship between the query fields; the step of determining the data statistical value of the database that meets the query field condition to be queried according to the query field condition to be queried and the statistical value recorded in the corresponding node in the target statistical tree model includes:

[0012] Analyze the logical operation relationship between the query fields to determine a search strategy for searching the target statistical tree model;

[0013] Search the target statistical tree model according to the search strategy to obtain a node path in the target statistical tree model that meets the query field condition to be queried;

[0014] According to the statistical values ​​recorded on the corresponding nodes in the node path, the statistical values ​​of the data in the database that meet the requirements of the query field condition to be queried are determined.

[0015] In the above implementation process, fast query can also be achieved for some complex query field conditions.

[0016] Furthermore, on each node of the statistical tree model, for the statistical value, a corresponding source data identity is associated and recorded, and the source data identity is used to represent the data identity of the data that meets the statistical requirements of the node;

[0017] When at least two node paths are determined, determining the data statistics of the database that meet the query field condition requirements to be queried according to the statistics recorded on the corresponding nodes in the node paths includes:

[0018] The statistical values ​​recorded in the last layer of nodes in each of the node paths are added together, and the number of repeated statistical data is subtracted according to the corresponding source data identity identifier to obtain the data statistical value of the database that meets the query field condition requirements to be queried.

[0019] In the above implementation process, duplicate statistical data is removed based on the source data identity, thereby ensuring the accuracy of the statistical results.

[0020] Furthermore, the limiting data is at least one of value interval range limiting data and value limiting data.

[0021] In the above implementation process, the value range-limited data and / or the value-limited data to be queried may be queried.

[0022] Furthermore, there is at least one statistical tree model in the statistical tree model library that satisfies the following conditions:

[0023] The query fields corresponding to at least one group of adjacent node layers are the same, and the limiting data corresponding to each node in the upper node layer in the adjacent node layer is value range limiting data, and the limiting data corresponding to each node in the lower node layer in the adjacent node layer is value limiting data.

[0024] In the above implementation process, since the corresponding statistical values ​​are recorded for the value range limiting data and the value limiting data of the query field in the statistical tree model, the setting of various query conditions can be met in the actual query process.

[0025] Furthermore, the method further comprises:

[0026] When data update in the database is detected, the information recorded on the corresponding node of the corresponding statistical tree model is updated.

[0027] In the above implementation process, the information recorded on the corresponding nodes in the statistical tree model is updated according to the update status of the data in the database to ensure the accuracy of subsequent query results.

[0028] The present application also provides a data query device, including:

[0029] An acquisition module, used to acquire a query field condition to be queried, wherein the query field condition includes information of the query field in the database and limiting data corresponding to the query field;

[0030] A model matching module, used for matching a target statistical tree model from a preset statistical tree model library according to the query field condition, wherein each statistical tree model in the statistical tree model library includes a node layer generated according to the database and the preset query field condition, each node in the node layer records the query field information, the limited data corresponding to the node and the statistical value, the statistical value recorded in each node in the node layer is the total number of data statistics corresponding to the query field recorded in the node when the limited data recorded in the node is met, and the query field information recorded in each node in the node layer is the same;

[0031] The determination module determines the data statistics of the database that meet the requirements of the query field condition to be queried according to the query field condition to be queried and the statistical values ​​recorded in the corresponding nodes in the target statistical tree model.

[0032] An embodiment of the present application further provides a device, including a processor and a memory, wherein the memory stores a computer program, and the processor executes the computer program to implement any one of the above-mentioned data query methods.

[0033] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, any one of the above-mentioned data query methods is implemented. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0035] Figure 1 A flowchart of a data query method provided in Example 1 of the present application;

[0036] Figure 2 A schematic diagram of a process for determining data statistical values ​​according to a target statistical tree model provided in Example 1 of the present application;

[0037] Figure 3 A schematic diagram of a first statistical tree model provided in Example 1 of the present application;

[0038] Figure 4 A schematic diagram of a second statistical tree model provided in Example 1 of the present application;

[0039] Figure 5 A schematic diagram of a third statistical tree model provided in Example 1 of the present application;

[0040] Figure 6 A schematic diagram of the fourth statistical tree model provided in Example 1 of the present application;

[0041] Figure 7 A first schematic diagram of searching for a node path based on a target statistical tree model provided in the first embodiment of the present application;

[0042] Figure 8 A second schematic diagram of searching for node paths based on a target statistical tree model provided in the first embodiment of the present application;

[0043] Fig. 9 A third schematic diagram of searching for a node path based on a target statistical tree model provided in the first embodiment of the present application;

[0044] Fig.10 A fourth schematic diagram of searching for a node path based on a target statistical tree model provided in the first embodiment of the present application;

[0045] Fig.11 A fifth schematic diagram of searching for a node path based on a target statistical tree model provided in the first embodiment of the present application;

[0046] Fig.12 A schematic diagram of the structure of a data query device provided in Embodiment 2 of the present application;

[0047] Fig.13 This is a schematic diagram of the structure of the device provided in Example 3 of the present application. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0049] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present invention are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0050] In the description of the present invention, it should be understood that the numerical labels before the steps do not identify the order of executing the steps, but are only used to facilitate the description of the present invention and distinguish each step, and therefore cannot be understood as a limitation of the present invention.

[0051] A number of embodiments will be provided below to specifically introduce a data query method, apparatus, device, and computer-readable storage medium.

[0052] Embodiment 1:

[0053] In order to solve the problem in the prior art that when querying the total number of data that meets the conditions in a database, it is necessary to fully scan the data in the database and accumulate the total number of data that meet the query conditions, resulting in low query efficiency, the embodiment of the present application provides a data query method. The method provided in this embodiment can be applied to any device, which can be a PC (Personal Computer), a mobile phone, a tablet computer, a laptop computer, a virtual host, etc.; it can also be a server, for example, a rack server, a blade server, a tower server or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc.

[0054] Please refer to the flowchart of the method provided in the embodiment of this application Figure 1 ,include:

[0055] S11: Obtain a query field condition to be queried, wherein the query field condition includes information of the query field in the database and limiting data corresponding to the query field.

[0056] The user may input the query field conditions to be queried on the device as needed; or the device may pre-store query field conditions that can be selected by the user.

[0057] Assuming that the query field condition to be queried obtained in step S11 is "A=5", the corresponding query field information is A, and the limiting data corresponding to the query field is "5".

[0058] Of course, in some other embodiments, the query field condition to be queried may include information of at least two query fields, limiting data corresponding to each query field, and a logical operation relationship between the query fields. For example, the query field condition to be queried obtained in step S11 may be "A=5AND B=5", or may be "A=5OR B=5".

[0059] S12: matching a target statistical tree model from a preset statistical tree model library according to the query field condition.

[0060] Each statistical tree model in the statistical tree model library in step S12 includes a node layer generated according to the database and preset query field conditions, and each node in the node layer records the query field information, the limited data corresponding to the node and the statistical value. The statistical value recorded in each node in the node layer is the total number of data statistics corresponding to the query field recorded in the node when the limited data recorded in the node is met. The query field information recorded in each node in the same node layer is the same.

[0061] Optionally, the target statistical tree model can be matched from the statistical tree model library according to the query arrangement order of the query fields in the query field conditions to be queried. Preferably, the statistical tree model whose field order in the preset query field conditions is consistent with the query arrangement order is selected as the target statistical tree model. For example, if the query field conditions to be queried are "A=5AND B=5AND C=true", the statistical tree model generated according to the preset query field conditions "ABC" can be selected as the target statistical tree model. In some other embodiments, the priority of the query field can be specified by the user, for example, the priority of field A can be specified to be higher than the priority of field B.

[0062] Here we first explain the statistical values ​​recorded by each node in the node layer.

[0063] When the number of node layers generated by a statistical tree model according to the database and the preset query field conditions is 1, then at this time, the statistical value of each node record in the node layer can be the total number of data statistics in the database when the query field of the node record meets the limited data of the node record.

[0064] When the number of node layers generated by a statistical tree model according to the database and the preset query field conditions is greater than 1, then at this time, the statistical value recorded in each node in the first node layer can be the total number of data statistics in the database for the query field recorded in the node when the restricted data of the node record is met, and the statistical value recorded in each node in the i-th node layer is the total number of data statistics in the database for the query field corresponding to the i-th node layer when the restricted data corresponding to the node is met and the corresponding node of the i-1th layer is met, and i is an integer greater than 1.

[0065] It should be noted that the limiting data in this embodiment includes but is not limited to at least one of value interval range limiting data and value limiting data.

[0066] For example, for a certain statistical tree model, the restricted data recorded in each node can be value interval range restricted data, value restricted data, or both value interval range restricted data and value restricted data. Alternatively, the restricted data recorded in each node in a certain node layer can be value interval range restricted data, and the restricted data recorded in each node in another node layer can be value restricted data. Recording value interval range restricted data in the node can speed up the range search process.

[0067] Optionally, there is at least one statistical tree model in the statistical tree model library that satisfies the following conditions:

[0068] The query fields corresponding to at least one group of adjacent node layers are the same, and the limiting data corresponding to each node in the upper node layer in the adjacent node layer is value range limiting data, and the limiting data corresponding to each node in the lower node layer in the adjacent node layer is value limiting data.

[0069] S13: According to the query field condition to be queried and the statistical values ​​recorded in the corresponding nodes in the target statistical tree model, determine the data statistical values ​​of the database that meet the query field condition requirements to be queried.

[0070] See also Figure 2 As shown, in this embodiment, when the query field condition to be queried includes information of at least two query fields and a logical operation relationship between the query fields, step S13 may include the following sub-steps:

[0071] S131: Analyze the logical operation relationship between the query fields and determine the search strategy for searching the target statistical tree model.

[0072] S132: Search the target statistical tree model according to the search strategy to obtain a node path in the target statistical tree model that meets the query field condition to be queried.

[0073] S133: Determine the data statistics of the database that meet the query field condition requirements to be queried according to the statistics recorded on the corresponding node in the node path.

[0074] When the logical operation relationship between the query fields to be queried includes "OR operation", multiple node paths may be obtained in step S202, and the fields corresponding to different node paths may come from the same source data. Therefore, in order to improve the accuracy of the query results, on each node of the statistical tree model, the statistical value of the record is also associated with the corresponding source data identity. The source data identity is used to characterize the data identity of the data that meets the statistical requirements of the node. For example, when the statistical value of a node record is 3, it means that the number of data in the database that meets the statistical requirements of the node is 3. For the statistical value 3, the node is also associated with the source data identity of these 3 data.

[0075] When at least two node paths are determined, step S203 includes:

[0076] The statistical values ​​recorded in the last layer of nodes in each node path are added together, and the number of repeated statistical data is subtracted according to the corresponding source data identity identifier to obtain the data statistical value of the database that meets the query field condition requirements to be queried.

[0077] To facilitate understanding, the process of generating the above statistical tree model and the data query process are specifically described below with reference to specific examples.

[0078] Assume that a data table stored in the database is as shown in Table 1 below:

[0079] Table 1 Data sheet

[0080]

[0081] It is understandable that the data types corresponding to different fields may be different. For example, the data corresponding to field A and field B in the above table are integer data, the data corresponding to field C is Boolean data, and the data corresponding to field D is time data. The difference from other databases is that the database in the embodiment of the present application can redundantly have a field to identify each piece of data uniquely. Therefore, the source data identity identification field in the above Table 1 represents the identity of the data.

[0082] The statistical tree model is initialized according to the database and the preset query field conditions. The preset query field conditions may include multiple ones, and the preset query field conditions include the information of the preset query fields. For example, for the above data table, the preset query field conditions may be: ABCD, BACD, CBAD, DAB, etc. The query field conditions may be specified according to user needs. Although the above preset query field conditions ABCD and BACD have the same fields, they are in different orders and will also be identified as different query field conditions. A statistical tree model can be generated according to the database and the preset query field conditions.

[0083] Assume that the query field conditions preset in step S12 include information of two groups of query fields, ABC and BA.

[0084] For the query field conditions corresponding to the query field group ABC, if the limited data includes value-limited data and value range-limited data, the corresponding preset statistical tree model can be as follows: Figure 3 shown.

[0085] Figure 3 The root node 300 records the total amount of database data.

[0086] Each node in the first node layer 301 records the information of the query field, the value interval range limiting data corresponding to the node, and the total number of data statistics in the database when the query field recorded by the node meets the value interval range limiting data recorded by the node. Among them, NRA1 represents the first value interval range statistical node of the query field A, and the value interval range statistical node represents the node whose limited data recorded is the value interval range limiting data, and the value interval range is 1 to 100, wherein [5] is the number of records under the interval, that is, the corresponding statistical value. The statistical principles of the remaining value interval range nodes of the query field A are the same and will not be repeated.

[0087] Each node in the second node layer 302 records the information of the query field, the value restriction data corresponding to the node, and the total number of data statistics in the database when the query field recorded by the node meets the value restriction data recorded by the node and meets the corresponding node of the upper layer. Among them, NVA1 represents a value statistics node for query field A=5, the value statistics node is a node whose restricted data is the value restriction data, [2] represents the number of records, that is, the corresponding statistical value, and id stores the source data identity identifier (hereinafter referred to as ID) set of all records that meet the query field A=5. Similarly, the statistical principles of the remaining value interval statistical nodes of query field A are the same and will not be repeated.

[0088] Each node in the third node layer 303 represents a value interval range statistics node for query field B under the value statistics node NVA1, where NRB1 is the first value interval range statistics node, the interval range is 1 to 200, and the total number of records is 2. The statistical principles of the remaining value interval range statistics nodes for query field B under NVA1 are the same and will not be repeated. Similarly, the statistical principles of the value interval range statistics nodes corresponding to query field B under the NVA(X) value statistics node are the same and will not be repeated.

[0089] Each node in the fourth node layer 304 represents a value statistics node under the value interval range statistics node NRB1, where NVB1 represents a value statistics node for query field B equal to 5, [1] represents the number of records, and id stores the IDs of all records that meet the query field A=5and B=5. Similarly, the statistical principles of the value statistics nodes under the other value interval range statistics nodes of the query field B are the same and will not be repeated.

[0090] Each node in the fifth node layer 305 represents a value interval range statistics node corresponding to the query field C under the value statistics node NVB1, wherein NRC1 is the first value interval range statistics node, the interval range is true, and the total number of records is 1. The statistical principles of the remaining value interval range statistics nodes for querying field C under NVB1 are the same and will not be repeated. Similarly, the statistical principles of the value interval range statistics nodes for querying field C under the NVB(X) value statistics node are the same and will not be repeated.

[0091] Each node in the sixth node layer 306 represents a value statistics node corresponding to the query field C under the value interval range statistics node NRC1, wherein NVC1 represents a value statistics node for the query field C=true, [1] represents the number of records, and id stores the ID set of all records that meet the query fields A=5and B=5and C=true. Similarly, the statistical principles of the value statistics nodes under the remaining value interval range statistics nodes corresponding to the query field C are the same and will not be repeated.

[0092] For the query field conditions corresponding to the query field group ABC, if the restricted data includes value restricted data, the corresponding preset statistical tree model can be as follows: Figure 4 shown.

[0093] Figure 4 The root node 400 records the total amount of database data.

[0094] Each node in the first node layer 401 represents a value statistics node corresponding to the query field A, where NVA1 represents a value statistics node for the query field A=5, [2] represents the number of records, and id stores the ID set of all records that match the query field A=5. Similarly, the statistical principles of the remaining value statistics nodes for the query field A are the same and will not be repeated here.

[0095] Each node in the second node layer 402 represents a value statistics node corresponding to the query field B, wherein NVB1 represents a value statistics node under NVA1 and query field B=5, [1] represents the number of records, and id stores the IDs of all records that meet the query fields A=5ANDB=5.

[0096] Each node in the third node layer 403 represents a value statistics node corresponding to the query field C, where NVC1 represents a value statistics node under NVB1 where the query field C is equal to true, [1] represents the number of records, and id stores the ID set of all records that meet the query fields A=5and B=5and C=true.

[0097] For the query field conditions corresponding to the query field BA, if the limited data includes value-limited data and value range-limited data, the corresponding preset statistical tree model can be as follows: Figure 5 shown.

[0098] Figure 5 The root node 500 records the total amount of database data.

[0099] Each node in the first node layer 501 represents a value interval range statistics node corresponding to the query field B, where NRB1 represents the first value interval range statistics node corresponding to the query field B, and the interval range is 1 to 200, where [5] is the number of records in the interval.

[0100] Each node in the second node layer 502 represents a value statistics node under the NRB1 value range statistics node, where NVB1 represents the value statistics node of the query field B=8, [2] represents the number of records, and id stores the ID set of all records that meet the query field B=8.

[0101] Each node in the third node layer 503 represents a value interval range statistics node corresponding to the query field A under the NVB1 value statistics node, wherein NRA1 represents the first value interval range statistics node, the interval range is 1 to 100, and the total number of records is 2.

[0102] Each node in the 4th node layer 504 represents a value statistics node under the NRA1 value range statistics node, where NVA1 represents a value statistics node for the query field A=8, [1] represents the number of records, and id stores the ID set of all records that meet the query field B=8AND A=8.

[0103] For the query field conditions corresponding to the query field BA group, if the restricted data includes value restricted data, the corresponding preset statistical tree model can be as follows: Figure 6 shown.

[0104] Figure 6 The root node 600 records the total amount of database data.

[0105] Each node in the first node layer 601 represents a value statistics node corresponding to the query field B, where NVB1 represents a value statistics node where the query field B is equal to 8, [2] represents the number of records, and id stores the ID set of all records where the query field B is equal to 8.

[0106] Each node in the second node layer 602 represents all the value statistics nodes that meet the conditions of the query field A under NVB1, among which NVA4 represents the value statistics node of the query field A=8, [1] represents the number of records, and id stores the ID set of all records in the database that meet the query field B=8AND A=8.

[0107] From the above content, it can be seen that the number of query fields in the preset query field conditions will affect the depth of the statistical tree model, and the order of the fields will affect the node order of the statistical tree.

[0108] It should be noted that in order to ensure the accuracy of the query results, when data updates are monitored in the database, the information recorded on the corresponding nodes of the corresponding statistical tree model can be updated, which can specifically include updating the query fields, updating the corresponding limiting data, and updating the corresponding statistical values.

[0109] The above content introduces the generation process of the statistical tree model. The following introduces the specific process of data query.

[0110] Based on the above example, assuming that the query field condition to be queried is A=5, see Figure 7 As shown, according to the query field condition to be queried, the Figure 7 The target statistical tree model in . The node path is as follows Figure 7 As shown by the middle arrow, if the value interval range statistics node is not set, there is no process of matching the value interval range statistics node, and the final data statistics value is 2.

[0111] Assume that the query field conditions to be queried are A=5and B=5and C=true, see Figure 8 As shown, according to the query field condition to be queried, the Figure 8 The target statistical tree model in . The node path is as follows Figure 8 As shown by the middle arrow, if the value interval range statistics node is not set, there is no process of matching the value interval range statistics node, and the final data statistics value is 1.

[0112] Assume that the query field condition to be queried is A=5and B=5or C=true, see Fig. 9 As shown, according to the query field condition to be queried, the Fig. 9 The target statistical tree model in . The logical operation relationship between the query fields to be queried is analyzed. This condition corresponds to two search and matching processes. The first match satisfies the records of A=5 and B=5, and one is matched. The second match satisfies the records of C=true, and three are matched. The node path is as follows Fig. 9 As shown by the arrow in the middle, the union is finally taken based on the unique identification ID field of the two matching results to obtain result 3.

[0113] Assume that the query field condition to be queried is A=5or B=8and C=false, see Fig.10 As shown, according to the query field condition to be queried, the Fig.10The target statistical tree model in . The logical operation relationship between the query fields to be queried is analyzed. This condition corresponds to two search and matching processes. The first match satisfies the records of A=5, and 2 matches are found. The second match satisfies the records of B=8and C=false, and 1 match is found. The node path is as follows Fig.10 As shown by the arrow in the middle, the union is finally taken based on the unique identification ID field of the two matching results to obtain result 3.

[0114] Assume that the query field conditions to be queried are A>=1and A<=100, see Fig.11 As shown, according to the query field condition to be queried, the Fig.11 The target statistics tree model in. When range query is performed, the advantage of value interval range statistics node is reflected. When there is a complete match, the number of records can be directly obtained through the value interval range statistics node. When there is an incomplete match, it is necessary to traverse and search for the value statistics node of the lower layer. The range A>=1and A<=100 completely matches the value interval node NARA1 and directly returns the result 5.

[0115] The embodiment of the present application establishes a statistical tree model, and stores the total number of records with different values ​​on the nodes of the statistical tree model in a space-for-time manner, which can effectively avoid full table scanning when querying the total number of records that meet the conditions, saving a lot of overhead. At the same time, the method provided by the embodiment of the present application is not only applicable to databases, but also to other business scenarios that require fast return of the total number of records, such as file systems.

[0116] Embodiment 2:

[0117] This application embodiment provides a data query device, see Fig.12 As shown, including:

[0118] The acquisition module 1201 is used to acquire the query field condition to be queried, wherein the query field condition includes the information of the query field in the database and the limiting data corresponding to the query field.

[0119] Model matching module 1202 is used to match the target statistical tree model from the preset statistical tree model library according to the query field condition. Each statistical tree model in the statistical tree model library includes a node layer generated according to the database and the preset query field condition. Each node in the node layer records the query field information, the limited data corresponding to the node and the statistical value. The statistical value recorded in each node in the node layer is the total number of data statistics corresponding to the query field recorded in the node when the limited data recorded in the node is met. The query field information recorded in each node in the node layer is the same.

[0120] The determination module 1203 is used to determine the data statistical value of the database that meets the query field condition to be queried according to the query field condition to be queried and the statistical value recorded in the corresponding node in the target statistical tree model.

[0121] Each statistical tree model in the statistical tree model library includes a node layer generated according to the database and preset query field conditions. Each node in the node layer records the query field information, the limited data corresponding to the node and the statistical value. The statistical value recorded in each node in the node layer is the total number of data statistics corresponding to the query field recorded in the node when the limited data recorded in the node is met. The query field information recorded in each node in the same node layer is the same.

[0122] In an exemplary embodiment, the model matching module 1202 is used to match a target statistical tree model from a statistical tree model library according to the query arrangement order of the query fields in the query field conditions to be queried. Preferably, a statistical tree model whose field order in the preset query field conditions is consistent with the query arrangement order is selected as the target statistical tree model.

[0123] Here we first explain the statistical values ​​recorded by each node in the node layer.

[0124] When the number of node layers generated by a statistical tree model according to the database and the preset query field conditions is 1, then at this time, the statistical value of each node record in the node layer can be the total number of data statistics in the database when the query field of the node record meets the limited data of the node record.

[0125] When the number of node layers generated by a statistical tree model according to the database and the preset query field conditions is greater than 1, then at this time, the statistical value recorded in each node in the first node layer can be the total number of data statistics in the database for the query field recorded in the node when the restricted data of the node record is met, and the statistical value recorded in each node in the i-th node layer is the total number of data statistics in the database for the query field corresponding to the i-th node layer when the restricted data corresponding to the node is met and the corresponding node of the i-1th layer is met, and i is an integer greater than 1.

[0126] It should be noted that the limiting data in this embodiment includes but is not limited to at least one of value interval range limiting data and value limiting data.

[0127] For example, for a certain statistical tree model, the restricted data recorded in each node can be value interval range restricted data, value restricted data, or both value interval range restricted data and value restricted data. Alternatively, the restricted data recorded in each node in a certain node layer can be value interval range restricted data, and the restricted data recorded in each node in another node layer can be value restricted data. Recording value interval range restricted data in the node can speed up the range search process.

[0128] Optionally, there is at least one statistical tree model in the statistical tree model library that satisfies the following conditions:

[0129] The query fields corresponding to at least one group of adjacent node layers are the same, and the limiting data corresponding to each node in the upper node layer in the adjacent node layer is value range limiting data, and the limiting data corresponding to each node in the lower node layer in the adjacent node layer is value limiting data.

[0130] In an exemplary embodiment, the query field condition to be queried may include information of at least two query fields, limiting data corresponding to each query field, and a logical operation relationship between the query fields. The determination module 1203 is used to analyze the logical operation relationship between the query fields, determine a search strategy for searching the target statistical tree model, search the target statistical tree model according to the search strategy, obtain a node path in the target statistical tree model that meets the query field condition to be queried, and determine the data statistical value of the database that meets the query field condition to be queried according to the statistical value recorded on the corresponding node in the node path.

[0131] When the logical operation relationship between the query fields to be queried includes an "or operation", multiple node paths may be obtained, and the fields corresponding to different node paths may come from the same source data. Therefore, in order to improve the accuracy of the query results, on each node of the statistical tree model, the statistical value of the record is also associated with the corresponding source data identity. The source data identity is used to characterize the data identity of the data that meets the statistical requirements of the node. Therefore, the determination module is also used to add the statistical values ​​recorded in the last layer of nodes in each node path when at least two node paths are determined, and subtract the number of repeated statistical data according to the corresponding source data identity to obtain the data statistical value of the database that meets the query field condition requirements to be queried.

[0132] In an exemplary embodiment, the data query device may also include an update module for updating the information recorded on the corresponding node of the corresponding statistical tree model when monitoring data updates in the database, which may specifically include updating the query field, updating the corresponding limiting data, and updating the corresponding statistical value.

[0133] Embodiment three:

[0134] Based on the same inventive concept, the present application embodiment provides a device, see Fig.13 As shown, it includes a processor 1301 and a memory 1302. The memory 1302 stores a computer program. The processor 1301 executes the computer program to implement the steps of the data query method in the above-mentioned embodiment 1, which will not be repeated here.

[0135] Understandably, Figure 6 The structure shown is for illustration only, and the device may also include Figure 6 More or fewer components as shown, or with Figure 6 Different configurations shown.

[0136] The processor 1301 may be an integrated circuit chip with signal processing capabilities. The processor 1301 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It may implement or execute various methods, steps, and logic block diagrams disclosed in the embodiments of the present application.

[0137] The memory 1302 may include but is not limited to random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable read-only memory (EEPROM), etc.

[0138] This embodiment also provides a computer-readable storage medium, such as a floppy disk, a CD, a hard disk, a flash memory, a USB flash disk, an SD (Secure Digital Memory Card) card, an MMC (Multimedia Card) card, etc., in which one or more programs for implementing the above steps are stored. These one or more programs can be executed by one or more processors to implement the steps of the data query method in the above embodiment 1, which will not be repeated here.

[0139] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0140] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiment method can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method.

[0141] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A data query method, characterized in that: include: Obtaining a query field condition to be queried, wherein the query field condition includes information of the query field in a database and limiting data corresponding to the query field; According to the query field condition, a target statistical tree model is matched from a preset statistical tree model library, each statistical tree model in the statistical tree model library includes a node layer generated according to the database and the preset query field condition, each node in the node layer records the query field information, the limited data corresponding to the node and the statistical value, the statistical value recorded in each node in the node layer is the total number of data statistics corresponding to the query field recorded in the node when the limited data recorded in the node is met, and the query field information recorded in each node in the node layer is the same; Determine the data statistics of the database that meet the query field condition to be queried according to the query field condition to be queried and the statistical values ​​recorded in the corresponding nodes in the target statistical tree model; Among them, there is at least one statistical tree model including at least 2 layers of node layers in the statistical tree model library, the statistical value recorded in each node in the first node layer of the statistical tree model is the total number of data statistics in the database when the query field recorded in the node meets the limited data of the node record, the statistical value recorded in each node in the i-th node layer is the total number of data statistics in the database when the query field corresponding to the i-th node layer meets the limited data corresponding to the node and meets the corresponding node of the i-1th layer, i is an integer greater than 1, and the information of the query field recorded in each node in the same node layer is the same; The query field condition to be queried includes information of at least two query fields and a logical operation relationship between the query fields; the step of determining the data statistical value of the database that meets the query field condition to be queried according to the query field condition to be queried and the statistical value recorded in the corresponding node in the target statistical tree model includes: Analyze the logical operation relationship between the query fields to determine a search strategy for searching the target statistical tree model; Search the target statistical tree model according to the search strategy to obtain a node path in the target statistical tree model that meets the query field condition to be queried; Determine, according to the statistical values ​​recorded on the corresponding nodes in the node path, the statistical values ​​of the data in the database that meet the requirements of the query field condition to be queried; Wherein, on each node of the statistical tree model, for the statistical value, a corresponding source data identity is associated and recorded, and the source data identity is used to characterize the data identity of the data that meets the statistical requirements of the node; When at least two node paths are determined, determining the data statistics of the database that meet the query field condition requirements to be queried according to the statistics recorded on the corresponding nodes in the node paths includes: The statistical values ​​recorded in the last layer of nodes in each of the node paths are added together, and the number of repeated statistical data items is subtracted according to the corresponding source data identity identifier; and the data statistical value of the database that meets the query field condition requirements to be queried is obtained.

2. The data query method according to claim 1, characterized in that: The limiting data is at least one of value interval range limiting data and value limiting data.

3. The data query method according to claim 2, characterized in that: There is at least one statistical tree model in the statistical tree model library that satisfies the following conditions: The query fields corresponding to at least one group of adjacent node layers are the same, and the limiting data corresponding to each node in the upper node layer in the adjacent node layer is value range limiting data, and the limiting data corresponding to each node in the lower node layer in the adjacent node layer is value limiting data.

4. The data query method according to any one of claims 1 to 3, characterized in that: The method further comprises: When data update in the database is detected, the information recorded on the corresponding node of the corresponding statistical tree model is updated.

5. A data query device, characterized in that: include: An acquisition module, used to acquire a query field condition to be queried, wherein the query field condition includes information of the query field in the database and limiting data corresponding to the query field; A model matching module, used for matching a target statistical tree model from a preset statistical tree model library according to the query field condition, wherein each statistical tree model in the statistical tree model library includes a node layer generated according to the database and the preset query field condition, each node in the node layer records the query field information, the limited data corresponding to the node and the statistical value, the statistical value recorded in each node in the node layer is the total number of data statistics corresponding to the query field recorded in the node when the limited data recorded in the node is met, and the query field information recorded in each node in the node layer is the same; A determination module, which determines the data statistical value of the database that meets the query field condition to be queried according to the query field condition to be queried and the statistical value recorded in the corresponding node in the target statistical tree model; Among them, there is at least one statistical tree model including at least 2 layers of node layers in the statistical tree model library, the statistical value recorded in each node in the first node layer of the statistical tree model is the total number of data statistics in the database when the query field recorded in the node meets the limited data of the node record, the statistical value recorded in each node in the i-th node layer is the total number of data statistics in the database when the query field corresponding to the i-th node layer meets the limited data corresponding to the node and meets the corresponding node of the i-1th layer, i is an integer greater than 1, and the information of the query field recorded in each node in the same node layer is the same; The determination module is used to analyze the logical operation relationship between the query fields to determine the search strategy for searching the target statistical tree model; search the target statistical tree model according to the search strategy to obtain the node path in the target statistical tree model that meets the query field condition to be queried; determine the data statistical value of the database that meets the query field condition requirement to be queried according to the statistical value recorded on the corresponding node in the node path; The determination module is used to add the statistical values ​​recorded in the last layer of nodes in each of the node paths, and subtract the number of repeated statistical data according to the corresponding source data identity identifier; to obtain the data statistical value of the database that meets the query field condition requirements to be queried.

6. A device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program, and the processor executes the computer program to implement the method according to any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by at least one processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Query method, query system and query device based on vertical search

    CN102236663A

  • Fast statistical query method for mass medical data

    CN103049556A