Data query method and device, computer readable storage medium and electronic device
By converting complex query statements into relational calculus expressions and performing tuple calculus to construct a query tree, the problem of database middleware being unable to handle complex query statements in cross-node queries is solved, achieving more efficient and accurate data querying.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA TELECOM CORP LTD
- Filing Date
- 2021-07-13
- Publication Date
- 2026-04-17
AI Technical Summary
Existing database middleware cannot effectively handle complex query statements when performing nested queries across nodes, resulting in incorrect query results.
The complex query statement is converted into a relational calculus expression, tuple calculus is performed, a query tree is constructed, and the query result is obtained based on the tuple formula.
It improves the accuracy and efficiency of cross-node data queries and solves the problem of incorrect query results in existing technologies.
Smart Images

Figure CN113486117B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a data query method, a data query device, a computer-readable storage medium, and an electronic device. Background Technology
[0002] With the development of information technology, IT systems in various fields generate a large amount of data every moment. Traditional single database architecture is difficult to adapt to systems with rapidly increasing data volume. Therefore, distributed databases have emerged, which has also promoted the development of database middleware.
[0003] With the advent of database middleware, application software no longer needs to handle operations such as sharding clusters, data source switching, transaction processing, and data aggregation. However, existing database middleware has the following problems when performing nested queries across nodes: In the case of table or database sharding, database middleware only has one implementation method for nested queries across nodes. This method directly splits the query statement, sends the simplified statements obtained from the split to each query node for querying, obtains the subquery results, and then performs a simple summary of the subquery results. When there are complex statements or filtering operations, it cannot be effectively processed, resulting in incorrect query results.
[0004] Therefore, a new data query method is needed.
[0005] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0006] The purpose of this disclosure is to provide a data query method, a data query device, a computer-readable storage medium, and an electronic device, thereby overcoming, at least to some extent, the problem of low data query efficiency caused by the limitations and defects of related technologies.
[0007] According to one aspect of this disclosure, a data query method is provided, comprising:
[0008] The system obtains the query statement sent by the application software, and when it is determined that the query statement is a complex statement, it converts the complex statement into a relational calculus expression.
[0009] Perform tuple calculus on the relational calculus expression to obtain the tuple formula corresponding to the relational calculus expression;
[0010] The system obtains and, based on the basic tuples and operational formulas included in the tuple formula, generates query results corresponding to the complex statement, and sends the query results to the application software.
[0011] In one exemplary embodiment of this disclosure, converting the complex statement into a relational calculus expression includes:
[0012] The complex statement is parsed to determine the query conditions, query objects, and selection sequences included in the complex statement;
[0013] The complex statement is converted into a relational calculus expression based on the query conditions, query objects, and selection sequence.
[0014] In one exemplary embodiment of this disclosure, after obtaining the query statement sent by the application software, the data query method further includes:
[0015] When it is determined that the query statement is a simple statement, the query conditions, query objects, and selection sequences included in the simple statement are obtained;
[0016] The query conditions and selection sequence are routed to the query node corresponding to the query object for structured query to obtain the query results corresponding to the simple statement;
[0017] The query results corresponding to the simple statement are aggregated, and the aggregated query results are sent to the application software.
[0018] In one exemplary embodiment of this disclosure, obtaining and, based on the basic tuples and operational formulas included in the tuple formula, obtaining query results corresponding to the complex statement includes:
[0019] Obtain the basic tuples and operational formulas included in the tuple formula, and construct a query tree based on the basic tuples and operational formulas;
[0020] Based on the query tree, the query results corresponding to the complex statement are obtained.
[0021] In one exemplary embodiment of this disclosure, constructing a query tree based on the basic tuples and the operational formula includes:
[0022] Determine whether any of the aforementioned basic tuples and operational formulas can be directly queried;
[0023] When any of the basic tuples and operational formulas are directly searchable, the directly searchable basic tuples and / or operational formulas are used as leaf nodes of the query tree.
[0024] When any of the basic tuples and operational formulas are not directly searchable, the basic tuples and / or operational formulas that are not directly searchable are used as non-leaf nodes of the query tree.
[0025] The query tree is constructed using the leaf nodes and the non-leaf nodes.
[0026] In one exemplary embodiment of this disclosure, obtaining the query result corresponding to the complex statement based on the query tree includes:
[0027] Determine the query node corresponding to the basic tuple or operational formula in the leaf node;
[0028] Based on the basic tuples or operational formulas in the leaf nodes, determine the query nodes corresponding to the basic tuples or operational formulas, and perform queries in the query nodes to obtain the query sub-results corresponding to the basic tuples or operational formulas.
[0029] When the non-leaf node is determined to be the root node, the query sub-result is processed according to the calculation formula in the non-leaf node to obtain the query result corresponding to the complex statement; wherein, the processing includes combination, filtering and aggregation.
[0030] In one exemplary embodiment of this disclosure, after obtaining the query sub-result corresponding to the basic tuple or operational formula, the data query method further includes:
[0031] When it is determined that the non-leaf node is not the root node, the basic tuples or calculation formulas in the non-leaf node are operated on with the query sub-result to obtain the operation result;
[0032] Based on the calculation formula in the root node, the calculation result is processed to obtain the query result corresponding to the complex statement.
[0033] According to one aspect of this disclosure, a data query apparatus is provided, comprising:
[0034] The query statement conversion module is used to obtain the query statement sent by the application software, and when it is determined that the query statement is a complex statement, convert the complex statement into a relational calculus expression.
[0035] The tuple formula acquisition module is used to perform tuple calculus on the relational calculus expression to obtain the tuple formula corresponding to the relational calculus expression;
[0036] The query result acquisition module is used to acquire and obtain the query result corresponding to the complex statement based on the basic tuples and operation formulas included in the tuple formula, and send the query result to the application software.
[0037] According to one aspect of this disclosure, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the data query method described in any of the exemplary embodiments above.
[0038] According to one aspect of this disclosure, an electronic device is provided, comprising:
[0039] Processor; and
[0040] Memory for storing the executable instructions of the processor;
[0041] The processor is configured to execute the data query method described in any of the above exemplary embodiments by executing the executable instructions.
[0042] This disclosure provides a data query method that obtains a query statement sent by application software. When the query statement is determined to be complex, it is converted into a relational calculus expression. Tuple calculus is performed on the relational calculus expression to obtain a tuple formula corresponding to the relational calculus expression. The basic tuples and operational formulas included in the tuple formula are obtained to generate a query result corresponding to the complex statement, and the query result is sent to the application software. On the one hand, by converting the complex statement into a relational calculus expression when it is determined to be complex, performing tuple calculus on the relational calculus expression to obtain a tuple formula, and finally obtaining a query result corresponding to the complex statement based on the tuple formula, this method solves the problem in the prior art where the query statement can only be split into simpler statements and then directly queried to obtain the query result, thus achieving diversity in cross-node data queries. On the other hand, by querying based on the basic tuples and operational formulas in the tuple formula to obtain a query result corresponding to the query statement, the accuracy of cross-node data queries is improved.
[0043] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0044] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure. It is obvious that the drawings described below are merely some embodiments of this disclosure, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0045] Figure 1The flowchart illustrates a data query method according to an example embodiment of the present disclosure.
[0046] Figure 2 A block diagram illustrating a data query system according to an example embodiment of the present disclosure is shown schematically.
[0047] Figure 3 The flowchart illustrates a method for converting complex statements into relational calculus expressions according to an exemplary embodiment of the present disclosure.
[0048] Figure 4 The diagram illustrates a generated shard node according to an example embodiment of the present disclosure.
[0049] Figure 5 The flowchart illustrates a method for retrieving data after receiving a query statement sent by an application software, according to an example embodiment of the present disclosure.
[0050] Figure 6 The flowchart illustrates a method for obtaining query results corresponding to complex statements based on basic tuples and operational formulas in a tuple formula, according to an example embodiment of the present disclosure.
[0051] Figure 7 The flowchart illustrates a method for constructing a query tree based on basic tuples and operational formulas according to an exemplary embodiment of the present disclosure.
[0052] Figure 8 This diagram illustrates a query tree constructed based on a tuple formula according to an example embodiment of the present disclosure.
[0053] Figure 9 The flowchart illustrates a method for obtaining query results corresponding to complex statements based on a query tree according to an example embodiment of the present disclosure.
[0054] Figure 10 The flowchart illustrates a data query method after obtaining query sub-results according to an example embodiment of the present disclosure.
[0055] Figure 11 A flowchart illustrating another data query method according to an example embodiment of the present disclosure is shown schematically.
[0056] Figure 12 The diagram schematically illustrates a data query apparatus according to an exemplary embodiment of the present disclosure.
[0057] Figure 13 An electronic device for implementing the data query method described above is illustrated according to an example embodiment of the present disclosure. Detailed Implementation
[0058] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this disclosure more comprehensive and complete, and to fully convey the concept of the example embodiments to those skilled in the art. The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a full understanding of embodiments of this disclosure. However, those skilled in the art will recognize that the technical solutions of this disclosure can be practiced with one or more of the specific details omitted, or other methods, components, apparatus, steps, etc., can be employed. In other instances, well-known technical solutions are not shown or described in detail to avoid obscuring various aspects of this disclosure.
[0059] Furthermore, the accompanying drawings are merely illustrative of this disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0060] With the development of information technology, IT systems in various fields generate massive amounts of data every moment. Traditional single-database architectures are ill-suited for systems experiencing rapid data growth, leading to the emergence of distributed database systems. This has also spurred the development of database middleware technology, with MyCat being a widely used example. Database middleware acts as an intermediary service between the database and applications, facilitating data processing and interaction. It primarily implements functions such as database sharding, read / write separation, and more. With database middleware, applications no longer need to handle operations such as sharding clusters, data source switching, transaction processing, and data sets.
[0061] Existing database middleware only has one implementation method for cross-node nested queries. This method is rather brute-force, directly splitting the query statement into simple statements, sending the simple statements to each query node for querying, obtaining subquery results, and then summarizing the subquery results before sending them to the application. When complex queries or filtering operations are involved, the existing implementation method cannot handle them effectively, resulting in incorrect query results.
[0062] Based on one or more of the above-mentioned problems, this exemplary embodiment first provides a data query method, which can be run on a device terminal, and the device terminal can be a database middleware; of course, those skilled in the art can also run the method disclosed herein on other platforms as needed, and this exemplary embodiment does not make any special limitations on this.
[0063] Figure 1 A flowchart illustrating the data query method is shown below. (Refer to...) Figure 1 As shown, this data query method may include the following steps:
[0064] Step S110. Obtain the query statement sent by the application software. When it is determined that the query statement is a complex statement, convert the complex statement into a relational calculus expression.
[0065] Step S120. Perform tuple calculus on the relational calculus expression to obtain the tuple formula corresponding to the relational calculus expression;
[0066] Step S130. Obtain and, based on the basic tuples and operational formulas included in the tuple formula, obtain the query result corresponding to the complex statement, and send the query result to the application software.
[0067] The above data query method obtains the query statement sent by the application software. When the query statement is determined to be complex, it is converted into a relational calculus expression. Tuple calculus is performed on the relational calculus expression to obtain a tuple formula corresponding to it. The basic tuples and operational formulas included in the tuple formula are then obtained to generate the query result corresponding to the complex statement, and the query result is sent to the application software. On the one hand, by converting the complex statement into a relational calculus expression when it is determined to be complex, performing tuple calculus on the relational calculus expression to obtain a tuple formula, and finally obtaining the query result corresponding to the complex statement based on the tuple formula, this method solves the problem in existing technologies where query statements can only be split into simpler statements for direct querying, thus achieving diversity in cross-node data queries. On the other hand, by querying based on the basic tuples and operational formulas in the tuple formula to obtain the query result corresponding to the query statement, the accuracy of cross-node data queries is improved.
[0068] The following provides a detailed explanation and description of each step involved in the data query method of the example embodiments of this disclosure.
[0069] First, the application scenarios and purposes of the exemplary embodiments of this disclosure will be explained and described. Specifically, the exemplary embodiments of this disclosure can be applied to querying complex query statements passed in by application software, and mainly study how to improve the accuracy and efficiency of complex query statements.
[0070] This disclosure obtains the query statement passed from the application software, judges the query statement, and when the query statement is complex, it uses relational data model theory to transform the complex statement and performs tuple calculus to obtain a tuple formula. A query tree suitable for multiple query nodes is constructed using the tuple formula, and the query result is obtained based on the query tree and sent to the application software. This avoids the incorrect query results caused by the simple parsing of the query statement in current cross-node nested queries, thus improving the accuracy and efficiency of cross-node queries. Specifically, when the obtained query statement is determined to be complex, it is transformed into a relational calculus expression. Tuple calculus is performed on this relational calculus expression to obtain a tuple formula. A query tree is constructed based on the basic tuples and operational formulas included in the tuple formula, and the query result corresponding to the query statement is obtained based on the query tree, thus improving the accuracy and efficiency of cross-node queries.
[0071] Secondly, the data query system involved in the example embodiments of this disclosure will be explained and described. (Reference) Figure 2 As shown, the data query system may include application software 210, database middleware 220, and database shards 230. Application software 210 sends a query statement to database middleware 220. Database middleware 220, connected to both application software 210 and database shards 230 via a network, receives the query statement from application software 210, parses the query statement, converts it into a relational calculus expression, performs tuple calculus on the relational calculus expression to obtain a tuple formula, constructs a query tree based on the tuple formula, and sends the queryable leaf nodes in the query tree to database shards 230. It also receives query sub-results from database shards and, through the non-queryable leaf nodes in the query tree... The leaf node processes the received query sub-results to obtain the query result and sends the query result to the application software 210; the database shard 230 is connected to the database middleware 220 via the network and is used to split the data table according to the preset data table splitting method to obtain data table shards. It receives the queryable leaf nodes in the query tree sent by the database middleware 220, determines the database shard corresponding to the query statement according to the query statement included in the leaf node, performs the query in the database shard, obtains the query sub-results, and sends the query sub-results to the database middleware 220.
[0072] The following will combine Figure 2 Steps S110-S130 are explained and described in detail.
[0073] In step S110, the query statement sent by the application software is obtained. When it is determined that the query statement is a complex statement, the complex statement is converted into a relational calculus expression.
[0074] The query statement sent by the application software is SQL (Structured Query Language). This query statement can be a single-table query, a multi-table query, or a nested query; in this example embodiment, no specific limitation is made. The query statement can be a simple statement or a complex statement. A simple statement is a single-table query; a complex statement is a query statement other than a single-table query. Other query statements can be multi-table queries, nested queries, set queries, or queries based on derived tables; in this example embodiment, no specific limitation is made on other query statements.
[0075] In this example embodiment, reference Figure 3 As shown, converting a complex statement into a relational calculus expression may include steps S310 and S320:
[0076] Step S310. Parse the complex statement to determine the query conditions, query objects, and selection sequences included in the complex statement;
[0077] Step S320. Convert the complex statement into a relational calculus expression based on the query conditions, query objects, and selection sequence.
[0078] The following will explain and illustrate steps S310 and S320. Specifically, after the database middleware receives the query statement sent by the application software, it first determines whether the query statement is a simple statement or a complex statement. When the query statement is a complex statement, it parses the complex statement to determine the query object, query conditions, and selection sequence included in the complex statement, and converts the complex statement into a relational calculus expression based on the query object, query conditions, and selection sequence.
[0079] For example, when querying a student's grade in both the student table (named "student") and the grade table (named "grade"), the database middleware MyCat offers various table partitioning methods. For the student table, it can be partitioned based on the student's unique identifier, resulting in multiple shard tables. Each shard table can contain 200 or 300 students; in this example, the number of students in each shard table is not specifically limited. For the grade table, the student's unique identifier can be modulo 2 to obtain a grade shard table. Integrating the partitioned student and grade shard tables yields multiple shard nodes. These shard nodes can be referenced... Figure 4 As shown. When the database middleware receives a query statement from the application software, such as `select name from student s where sex='female'and sno not in(select sno from grade g where score<90)`, which means searching for the names of students whose gender is female and whose score is not lower than 90, since this query statement involves two data tables, it can be considered a complex statement. Parsing this complex statement reveals the query conditions as `sex='female'and sno not in (select sno from grade g where score<90)`, the query objects as the `student` table and the `grade` table, and the selection sequence as the students' names. After determining the query conditions, query objects, and selection sequence, this complex statement can be converted into a relational calculus expression. The converted relational calculus expression can be:
[0080]
[0081]
[0082] in, This indicates that there always exists an s that satisfies the condition; s(S)Λs.sex='female' means that s∈S and the student's gender is female, where S represents the student table. Indicates "not"; This indicates that there always exists a g that satisfies the condition; g(G)Λg.score<90 means that g∈G and the student's score is less than 90, where G represents the grade table.
[0083] Furthermore, in this example embodiment, reference is made to... Figure 5As shown, after obtaining the query statement sent by the application software, the data query method may further include steps S510-S530:
[0084] Step S510. When it is determined that the query statement is a simple statement, obtain the query conditions, query objects and selection sequence included in the simple statement;
[0085] Step S520. The query conditions and selection sequence are routed to the query node corresponding to the query object for structured query to obtain the query results corresponding to the simple statement;
[0086] Step S530. Aggregate the query results corresponding to the simple statement and send the aggregated query results to the application software.
[0087] The following will explain and illustrate steps S510-S530. Specifically, after receiving the query statement sent by the application software, the query statement is parsed. When the query statement is a single-table query statement, that is, a simple statement, the query conditions included in the simple statement are simplified to obtain the query conditions, query objects, and selection sequences included in the simple query statement. After obtaining the query conditions, query objects, and selection sequences included in the simple statement, the query node corresponding to the query statement can be determined according to the query object. After obtaining the query node, the query conditions and selection sequences included in the simple statement can be sent to the query node for querying to obtain the query results corresponding to the simple statement. The obtained query results are then aggregated and sent to the application software.
[0088] In step S120, tuple calculus is performed on the relational calculus expression to obtain the tuple formula corresponding to the relational calculus expression.
[0089] In this example embodiment, tuple calculus can be performed on the obtained relational calculus expression. Tuple calculus involves performing an identity transformation on the relational calculus expression. The expression obtained by the identity transformation is the tuple formula corresponding to the relational calculus expression. Taking the relational calculus expression obtained in step S110 as an example, performing an identity transformation on it yields the following tuple formula:
[0090] In step S130, the basic tuples and operation formulas included in the tuple formula are obtained to obtain the query result corresponding to the complex statement, and the query result is sent to the application software.
[0091] The original formula includes basic tuples and operational formulas, referencing the tuple formula obtained in step S120: in, s.sex = 'female' and Λg.grade > 90 are the basic tuples.
[0092] In this example embodiment, reference Figure 6 As shown, obtaining the query result corresponding to the complex statement by acquiring and calculating the basic tuples and operational formulas included in the tuple formula may include steps S610 and S620:
[0093] Step S610. Obtain the basic tuples and operation formulas included in the tuple formula, and construct a query tree based on the basic tuples and operation formulas;
[0094] Step S620. Obtain the query results corresponding to the complex statement based on the query tree.
[0095] The following will explain and illustrate steps S610 and S620. Specifically, after obtaining the tuple formula, the tuple formula can be parsed to determine the basic tuples and operational formulas included in the tuple formula. A query tree can then be constructed based on the basic tuples and operational formulas. The query results corresponding to the complex statement can be obtained through the constructed query tree.
[0096] Further reference Figure 7 As shown, constructing a query tree based on basic tuples and operational formulas may include steps S710-S740:
[0097] Step S710. Determine whether any of the basic tuples and operational formulas can be directly queried;
[0098] Step S720. When any of the basic tuples and operation formulas are directly searchable, the directly searchable basic tuples and / or operation formulas are used as leaf nodes of the query tree;
[0099] Step S730. When any of the basic tuples and operation formulas cannot be directly queried, the basic tuples and / or operation formulas that cannot be directly queried are used as non-leaf nodes of the query tree;
[0100] Step S740. Construct the query tree using the leaf nodes and the non-leaf nodes.
[0101] The following will explain and illustrate steps S710-S740. Specifically, after determining the basic tuples and operational formulas included in the tuple formula, it can be determined whether the basic tuples and operational formulas are directly searchable, that is, whether the basic tuples and operational formulas can be directly sent to the corresponding query node for querying. When the basic tuples and operational formulas are directly searchable, the directly searchable basic tuples and / or operational formulas are used as leaf nodes of the query tree; when any basic tuple or operational formula included in the tuple formula is not directly searchable, the non-searchable basic tuples and / or operational formulas are used as non-leaf nodes of the query tree, and the query tree is constructed through leaf nodes and non-leaf nodes.
[0102] For example, when the tuple formula is At that time, the basic tuple To be directly searchable, in the formula `s.sex = 'female' Λg.grade > 90`, since `s` and `g` are stored in different data tables, this formula is not directly searchable. Therefore, the basic tuple is the leaf node of the query tree, and the formula is the non-leaf node. There is no formula based on `s.sex = 'female' Λg.grade > 90` in this tuple formula; therefore, the formula `s.sex = 'female' Λg.grade > 90` is also the root node of the query tree. The generated query tree is referenced. Figure 8 As shown.
[0103] Furthermore, when a tuple formula includes multiple operational formulas, the node corresponding to that operational formula in the query tree can be determined based on the operational level of the multiple operational formulas. That is, the higher the operational level of the operational formula, the lower the level of the node corresponding to that operational formula in the query tree. For example, when a tuple formula includes two operational formulas, one of which is s.sex = 'female' Λg.grade > 90, and the other is an aggregate function, since the operational level of the aggregate function is higher than that of the ordinary operational formula, the level of the operational formula corresponding to the aggregate function in the query tree is lower than the level of the operational formula s.sex = 'female' Λg.grade > 90 in the query tree. That is, the operational formula corresponding to the aggregate function can be the parent node of the operational formula s.sex = 'female' Λg.grade > 90. The aggregate function can be count(), average(), or sum(), and in this example embodiment, no specific limitation is made on the aggregate function.
[0104] Furthermore, after constructing a query tree based on the tuple formula, the query results corresponding to the complex statement can be obtained from this query tree. (See reference...) Figure 9 As shown, obtaining the query results corresponding to the complex statement based on the query tree can include steps S910-S930:
[0105] Step S910. Determine the query node corresponding to the basic tuple or operation formula in the leaf node;
[0106] Step S920. Based on the basic tuples or operational formulas in the leaf nodes, determine the query node corresponding to the operational formula, and perform a query in the query node to obtain the query sub-results corresponding to the basic tuples or operational formulas;
[0107] Step S930. When the non-leaf node is determined to be the root node, the query sub-result is processed according to the basic tuples or operation formulas in the non-leaf node to obtain the query result corresponding to the complex statement; wherein, the processing includes combination, filtering and aggregation.
[0108] The following will explain and illustrate steps S910-S930. Specifically, firstly, the basic tuples and operational formulas that can be directly sent to the corresponding query nodes for querying are obtained from the tuple formulas; that is, the basic tuples or operational formulas corresponding to the leaf nodes in the query tree are obtained. Then, the query node corresponding to the basic tuple or operational formula is determined based on the basic tuple or operational formula, and the basic tuple or operational formula is routed to the corresponding query node for querying, thereby obtaining the query sub-results corresponding to the basic tuple or operational formula. When the parent node of the leaf node is the root node, that is, when the non-leaf node in the query tree is the root node, the query sub-results obtained from the query are processed according to the operational formula in the root node, thereby obtaining the query results corresponding to the complex statement. The processing can be combining multiple query sub-results, filtering the query sub-results obtained from the query, or aggregating the query sub-results obtained from the query. This example embodiment does not specifically limit the processing.
[0109] For example, based on Figure 8 The query tree shown and Figure 4 When performing a query, the sharded nodes shown first retrieve the leaf nodes of the query tree, where each leaf node contains basic tuples. and basic tuples The basic tuple The corresponding query node is the shard table named "student" in each shard node, along with the basic tuples. The corresponding query nodes are the sharded tables named grade in each sharded table; then, queries are respectively performed in the sharded tables corresponding to the basic tuple and the basic tuple to obtain the query sub-results; among them, the query sub-results include all records in the student table and all records in the grade table; again, if the non-leaf node in the query tree is the root node of the query tree, then, the query sub-results obtained by querying the leaf nodes can be processed according to the operation formula in the root node. Among them, the operation formula in the root node is s.sex = 'female' Λ g.grade > 90, so the query sub-results can be filtered according to this operation formula, and the query result corresponding to the complex statement is obtained as name: 'Wang XX'.
[0110] In this exemplary embodiment, after obtaining the query sub-results corresponding to the basic tuple or operation formula, as shown in Figure 10 , the data query method may further include step S1010 and step S1020:
[0111] Step S1010. When it is determined that the non-leaf node is not the root node, perform an operation on the basic tuple or calculation formula in the non-leaf node and the query sub-results to obtain an operation result; <�
[0112] Step S1020. According to the operation formula in the root node, process the operation result to obtain the query result corresponding to the complex statement.
[0113] Next, step S1010 and step S1020 will be explained and described. Specifically, when the parent node of the leaf node is not the root node, that is, when the level of the query tree is greater than 2, the query sub-results obtained by querying the leaf nodes can be operated with the operation formula in the non-leaf node to obtain an operation result, and the operation formula in the root node can be obtained, and the operation result can be processed according to the operation formula in the root node to obtain the query result corresponding to the complex statement. Among them, the processing can be to combine the obtained operation results, or to filter the operation results, or to aggregate the operation results. In this exemplary embodiment, the processing is not specifically limited.
[0114] After obtaining the query result corresponding to the complex statement, the query result can be sent to the application software.
[0115] The data query method provided in this exemplary embodiment has at least the following advantages: On the one hand, after receiving the query statement sent by the application software, the query statement is first judged. When the query statement is a simple statement, it is split into parts, and the query is performed based on the query conditions obtained from the split. When the query statement is a complex statement, a corresponding query tree is constructed based on the complex statement, and the complex statement is queried based on the query tree to obtain the query results corresponding to the complex statement, thereby improving the accuracy of data query. On the other hand, when constructing the query tree, the complex statement is parsed and converted into a relational calculus expression. Tuple calculus is performed on the relational calculus expression to obtain a tuple formula. The query tree is constructed based on the tuple formula, and the query results corresponding to the complex statement are obtained through the query tree, thereby improving the efficiency of cross-node data query.
[0116] The following, combined with Figure 11 The data query method of the exemplary embodiments of this disclosure will be further explained and described. The data query method may include:
[0117] Step S1102. Receive the query statement sent by the application software;
[0118] Step S1104. Determine whether the query statement is a complex query statement;
[0119] Step S1106. When the query statement is not a complex query statement, simplify the query statement to obtain the query conditions, query objects and selection sequence;
[0120] Step S1108. Route the query conditions and selection sequence to the query node corresponding to the query object to perform the query, obtain the query results, and jump to step S1130;
[0121] Step S1110. When the query statement is a complex statement, parse the complex statement to obtain the query conditions, query objects, and selection sequence in the complex statement;
[0122] Step S1112. Based on the query conditions, query objects, and selection sequence, convert the complex statement into a relational calculus expression;
[0123] Step S1114. Perform tuple calculus on the relational calculus expression to obtain the tuple formula corresponding to the relational calculus expression;
[0124] Step S1116. Obtain the basic tuples and operational formulas included in the tuple formula, and determine whether the basic tuples and / or operational formulas are directly searchable;
[0125] Step S1118. When it can be directly queried, the basic tuples and / or operation formulas are used as leaf nodes, and the process proceeds to step S1122.
[0126] Step S1120. When it is not directly queryable, treat the basic tuple and / or operation formula as a non-leaf node;
[0127] Step S1122. Construct a query tree using leaf nodes and non-leaf nodes, and perform a query based on the leaf nodes in the query tree to obtain the query sub-results;
[0128] Step S1124. Determine whether a non-leaf node is the root node;
[0129] Step S1126. When a non-leaf node is the root node, process the query sub-result according to the operation formula in the root node to obtain the query result, and then proceed to step S1130.
[0130] Step S1128. When a non-leaf node is not the root node, perform a calculation on the query sub-result and the calculation formula in the non-leaf node to obtain the calculation result, and process the calculation result according to the calculation formula in the root node to obtain the query result, and then proceed to step S1130.
[0131] Step S1130. Send the query results to the application software.
[0132] This disclosure also provides a data query device in exemplary embodiments, referencing... Figure 12 As shown, it may include: a query statement conversion module 1210, a tuple formula acquisition module 1220, and a query result acquisition module 1230. Wherein:
[0133] The query statement conversion module 1210 is used to obtain the query statement sent by the application software, and when it is determined that the query statement is a complex statement, convert the complex statement into a relational calculus expression.
[0134] The tuple formula acquisition module 1220 is used to perform tuple calculations on the relational calculus expression to obtain the tuple formula corresponding to the relational calculus expression.
[0135] The query result acquisition module 1230 is used to acquire and obtain the query result corresponding to the complex statement based on the basic tuples and operation formulas included in the tuple formula, and send the query result to the application software.
[0136] The specific details of each module in the aforementioned data query device have been described in detail in the corresponding data query methods, so they will not be repeated here.
[0137] In one exemplary embodiment of this disclosure, converting the complex statement into a relational calculus expression includes:
[0138] The complex statement is parsed to determine the query conditions, query objects, and selection sequences included in the complex statement;
[0139] The complex statement is converted into a relational calculus expression based on the query conditions, query objects, and selection sequence.
[0140] In one exemplary embodiment of this disclosure, after obtaining the query statement sent by the application software, the data query method further includes:
[0141] When it is determined that the query statement is a simple statement, the query conditions, query objects, and selection sequences included in the simple statement are obtained;
[0142] The query conditions and selection sequence are routed to the query node corresponding to the query object for structured query to obtain the query results corresponding to the simple statement;
[0143] The query results corresponding to the simple statement are aggregated, and the aggregated query results are sent to the application software.
[0144] In one exemplary embodiment of this disclosure, obtaining and, based on the basic tuples and operational formulas included in the tuple formula, obtaining query results corresponding to the complex statement includes:
[0145] Obtain the basic tuples and operational formulas included in the tuple formula, and construct a query tree based on the basic tuples and operational formulas;
[0146] Based on the query tree, the query results corresponding to the complex statement are obtained.
[0147] In one exemplary embodiment of this disclosure, constructing a query tree based on the basic tuples and the operational formula includes:
[0148] Determine whether any of the aforementioned basic tuples and operational formulas can be directly queried;
[0149] When any of the basic tuples and operational formulas are directly searchable, the directly searchable basic tuples and / or operational formulas are used as leaf nodes of the query tree.
[0150] When any of the basic tuples and operational formulas are not directly searchable, the basic tuples and / or operational formulas that are not directly searchable are used as non-leaf nodes of the query tree.
[0151] The query tree is constructed using the leaf nodes and the non-leaf nodes.
[0152] In one exemplary embodiment of this disclosure, obtaining the query result corresponding to the complex statement based on the query tree includes:
[0153] Determine the query node corresponding to the basic tuple or operational formula in the leaf node;
[0154] Based on the basic tuples or operational formulas in the leaf nodes, determine the query nodes corresponding to the basic tuples or operational formulas, and perform queries in the query nodes to obtain the query sub-results corresponding to the basic tuples or operational formulas.
[0155] When the non-leaf node is determined to be the root node, the query sub-result is processed according to the calculation formula in the non-leaf node to obtain the query result corresponding to the complex statement; wherein, the processing includes combination, filtering and aggregation.
[0156] In one exemplary embodiment of this disclosure, after obtaining the query sub-result corresponding to the basic tuple or operational formula, the data query method further includes:
[0157] When it is determined that the non-leaf node is not the root node, the basic tuples or calculation formulas in the non-leaf node are operated on with the query sub-result to obtain the operation result;
[0158] Based on the calculation formula in the root node, the calculation result is processed to obtain the query result corresponding to the complex statement.
[0159] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to embodiments of this disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0160] Furthermore, although the steps of the method in this disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.
[0161] In an exemplary embodiment of this disclosure, an electronic device capable of implementing the above-described method is also provided.
[0162] Those skilled in the art will understand that various aspects of this disclosure can be implemented as systems, methods, or program products. Therefore, various aspects of this disclosure can be specifically implemented in the following forms: entirely in hardware, entirely in software (including firmware, microcode, etc.), or in a combination of hardware and software, collectively referred to herein as “circuit,” “module,” or “system.”
[0163] The following reference Figure 13 To describe an electronic device 1300 according to such an embodiment of the present disclosure. Figure 13 The electronic device 1300 shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments disclosed herein.
[0164] like Figure 13 As shown, the electronic device 1300 is manifested in the form of a general-purpose computing device. The components of the electronic device 1300 may include, but are not limited to: at least one processing unit 1310, at least one storage unit 1320, a bus 1330 connecting different system components (including storage unit 1320 and processing unit 1310), and a display unit 1340.
[0165] The storage unit stores program code that can be executed by the processing unit 1310, causing the processing unit 1310 to perform the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of this disclosure. For example, the processing unit 1310 can perform actions such as... Figure 1 The steps shown are as follows: S110: Obtain the query statement sent by the application software; when the query statement is determined to be a complex statement, convert the complex statement into a relational calculus expression; S120: Perform tuple calculus on the relational calculus expression to obtain a tuple formula corresponding to the relational calculus expression; S130: Obtain and, based on the basic tuples and operation formulas included in the tuple formula, obtain the query result corresponding to the complex statement, and send the query result to the application software.
[0166] Storage unit 1320 may include readable media in the form of volatile storage units, such as random access memory (RAM) 13201 and / or cache memory 13202, and may further include read-only memory (ROM) 13203.
[0167] Storage unit 1320 may also include a program / utility 13204 having a set (at least one) of program modules 13205, such program modules 13205 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.
[0168] Bus 1330 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the various bus structures.
[0169] Electronic device 1300 can also communicate with one or more external devices 1400 (e.g., keyboard, pointing device, Bluetooth device, etc.), one or more devices that enable a user to interact with electronic device 1300, and / or any device that enables electronic device 1300 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 1350. Furthermore, electronic device 1300 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 1360. As shown, network adapter 1360 communicates with other modules of electronic device 1300 via bus 1330. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 1300, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0170] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal device, or network device, etc.) to execute the methods according to the embodiments of this disclosure.
[0171] In exemplary embodiments of this disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the methods described above is stored. In some possible implementations, various aspects of this disclosure may also be implemented as a program product including program code that, when the program product is run on a terminal device, causes the terminal device to perform the steps of the various exemplary embodiments of this disclosure described in the "Exemplary Methods" section above.
[0172] The program product for implementing the above-described method according to embodiments of the present disclosure may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto. In this document, the readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0173] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0174] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium, capable of sending, propagating, or transmitting programs for use by or in conjunction with an instruction execution system, apparatus, or device.
[0175] The program code contained on the readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0176] Program code for performing the operations of this disclosure can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0177] Furthermore, the above figures are merely illustrative of the processes included in the method according to exemplary embodiments of this disclosure and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0178] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the claims.
Claims
1. A data query method, characterized in that, include: The system obtains the query statement sent by the application software, and when it is determined that the query statement is a complex statement, it converts the complex statement into a relational calculus expression. Perform tuple calculus on the relational calculus expression to obtain the tuple formula corresponding to the relational calculus expression; Obtain the basic tuples and operational formulas included in the tuple formula, and determine whether any of the basic tuples and operational formulas can be directly queried; when any of the basic tuples and operational formulas can be directly queried, use the directly queried basic tuples and / or operational formulas as leaf nodes of the query tree; when any of the basic tuples and operational formulas cannot be directly queried, use the unqueried basic tuples and / or operational formulas as non-leaf nodes of the query tree; construct the query tree using the leaf nodes and the non-leaf nodes. Based on the query tree, the query results corresponding to the complex statement are obtained, and the query results are sent to the application software.
2. The data query method according to claim 1, characterized in that, Converting the complex statement into a relational calculus expression includes: The complex statement is parsed to determine the query conditions, query objects, and selection sequences included in the complex statement; The complex statement is converted into a relational calculus expression based on the query conditions, query objects, and selection sequence.
3. The data query method according to claim 1, characterized in that, After obtaining the query statement sent by the application software, the data query method further includes: When it is determined that the query statement is a simple statement, the query conditions, query objects, and selection sequences included in the simple statement are obtained; The query conditions and selection sequence are routed to the query node corresponding to the query object for structured query to obtain the query results corresponding to the simple statement; The query results corresponding to the simple statement are aggregated, and the aggregated query results are sent to the application software.
4. The data query method according to claim 1, characterized in that, The query results corresponding to the complex statement are obtained based on the query tree, including: Determine the query node corresponding to the basic tuple or operational formula in the leaf node; Based on the basic tuples or operational formulas in the leaf nodes, determine the query nodes corresponding to the basic tuples or operational formulas, and perform queries in the query nodes to obtain the query sub-results corresponding to the basic tuples or operational formulas. When the non-leaf node is determined to be the root node, the query sub-result is processed according to the calculation formula in the non-leaf node to obtain the query result corresponding to the complex statement; wherein, the processing includes combination, filtering and aggregation.
5. The data query method according to claim 4, characterized in that, After obtaining the query sub-result corresponding to the basic tuple or operational formula, the data query method further includes: When it is determined that the non-leaf node is not the root node, the basic tuples or calculation formulas in the non-leaf node are operated on with the query sub-result to obtain the operation result; Based on the calculation formula in the root node, the calculation result is processed to obtain the query result corresponding to the complex statement.
6. A data query device, characterized in that, include: The query statement conversion module is used to obtain the query statement sent by the application software, and when it is determined that the query statement is a complex statement, convert the complex statement into a relational calculus expression. The tuple formula acquisition module is used to perform tuple calculus on the relational calculus expression to obtain the tuple formula corresponding to the relational calculus expression; The query result acquisition module is used to acquire the basic tuples and operational formulas included in the tuple formula, determine whether any of the basic tuples and operational formulas are directly searchable; when any of the basic tuples and operational formulas are directly searchable, the directly searchable basic tuples and / or operational formulas are used as leaf nodes of the query tree; when any of the basic tuples and operational formulas are not directly searchable, the non-directly searchable basic tuples and / or operational formulas are used as non-leaf nodes of the query tree; and construct the query tree using the leaf nodes and the non-leaf nodes. Based on the query tree, the query results corresponding to the complex statement are obtained, and the query results are sent to the application software.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the data query method according to any one of claims 1-5.
8. An electronic device, characterized in that, include: processor; as well as Memory for storing the executable instructions of the processor; The processor is configured to execute the data query method according to any one of claims 1-5 by executing the executable instructions.