A method, device, storage medium and electronic equipment for data query
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING OCEANBASE TECHNOLOGY CO LTD
- Filing Date
- 2022-10-26
- Publication Date
- 2026-08-07
AI Technical Summary
但在执行计划时,需要先进行多张表的连接计算,再根据输出限制条件输出结果,这会导致在对多张表进行连接计算时可能会存在大量的无效数据的计算,会使查询的速度低,从而会降低查询的性能
[0052] The data query method provided in this specification involves determining the table corresponding to the table identifier carried in the obtained query statement as the table to be queried, determining the driving table and non-driving table based on the connection relationship between each table to be queried, restricting the driving table according to the output restriction conditions carried in the query statement, and connecting the restricted driving table and non-driving table to obtain the query result corresponding to the query statement.
Smart Images

Figure CN115617856B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of computer technology, and in particular to a method, apparatus, storage medium, and electronic device for data retrieval. Background Technology
[0002] With the development of technology, databases have been widely used. As databases become more widely used, the privacy of the data stored within database tables has received increasing attention.
[0003] Database tables store different information. When querying specific information, the execution plan for the generated query might first join multiple tables containing that information before performing the query. There are many ways to join tables in a database, such as inner join, outer join, and cross join. The join methods between tables may be the same or different. Furthermore, the query might retrieve all rows of data for a specific piece of information, or it might only retrieve one or a few rows. When retrieving only one or a few rows, the execution plan requires joining multiple tables first, obtaining the join results, and then outputting the results based on the output constraints in the query. However, performing join calculations on multiple tables before outputting results can lead to a large amount of invalid data being calculated during the join operations, slowing down the query and thus reducing query performance.
[0004] Therefore, how to perform efficient data queries is an urgent problem to be solved. Summary of the Invention
[0005] This specification provides a method, apparatus, storage medium, and electronic device for data retrieval, in order to partially solve the aforementioned problems existing in the prior art.
[0006] The following technical solution is adopted in this specification:
[0007] This manual provides a method for data querying, including:
[0008] Obtain a query statement, wherein the query statement carries the identifier of the table to be queried, the join conditions between the tables to be queried, and the output restrictions of the query statement;
[0009] Identify the tables corresponding to each table identifier as the tables to be queried;
[0010] Based on each table to be queried and the join conditions between them, the driving table and the non-driving table are determined;
[0011] Based on the output constraints, the driving table is subjected to constraint processing to obtain the constrained driving table;
[0012] Based on the join conditions between the tables to be queried, the non-driving table and the restricted driving table are joined to obtain the query result corresponding to the query statement.
[0013] Optionally, the connection includes an external connection;
[0014] The driving table is determined based on each table to be queried and the join conditions between them, specifically including:
[0015] The set of tables to be queried is the set of tables to be queried.
[0016] Based on the connection conditions between the tables to be queried, a preset partitioning strategy is used to divide the set of tables to be queried into subsets of tables to be queried.
[0017] For each subset of tables to be queried, identify the tables in that subset that are excluding joins. Based on the join conditions between the tables in that subset that are excluding joins, join the tables in that subset to obtain the driving table.
[0018] Optionally, a join is performed based on the join conditions between tables in the subset of tables to be queried, excluding the join operation, to obtain the driving table, specifically including:
[0019] Based on the preset transformation strategy, the join conditions between the tables in the subset of tables to be queried are transformed into equivalent conditions.
[0020] Based on the transformed join conditions between the tables in the subset of tables to be queried (excluding joins), the tables in the subset of tables to be queried (excluding joins) are joined to obtain the driving table.
[0021] Optionally, the output constraints include a first type of condition and a second type of condition;
[0022] When the output constraint is a first type of condition, the driving table is constrained according to the output constraint to obtain a constrained driving table, specifically including:
[0023] Determine the number of output results in the first type of condition, filter the data of the number of output results in the driving table, and determine a table composed of the data of the number of output results as the restricted driving table;
[0024] When the output constraint is a second type of condition, the driving table is restricted according to the output constraint to obtain a restricted driving table, specifically including:
[0025] Determine the starting position and offset n of the data in the second type of condition. According to the sorting of each data in the driving table, filter the n data after the starting position of the data in the driving table, and determine the table composed of the n data as the restricted driving table, where n is a positive integer.
[0026] Optionally, if the output constraint is a second type of condition, the driving table is restricted according to the output constraint, specifically including:
[0027] Determine the join fields included in the join conditions between the driving table and the non-driving table;
[0028] When the join field has a unique constraint in the non-driving table, and the subset of tables to be queried is the same as the set of tables to be queried, the driving table is restricted according to the second type of condition to obtain the restricted driving table.
[0029] Optionally, for each subset of tables to be queried, identify the tables in that subset other than those with joins, specifically including:
[0030] For each subset of tables to be queried, construct a connected graph corresponding to that subset of tables, with the tables contained in that subset as nodes and the connection conditions between the tables contained in that subset as edges.
[0031] The tables contained in the nodes of the connected graph, excluding those whose edge connection condition is an outer join, are the tables in the subset of tables to be queried, excluding those whose connection condition is an outer join.
[0032] Optionally, a preset partitioning strategy is used to partition the set of tables to be queried, resulting in a subset of tables to be queried, specifically including:
[0033] The set of tables to be queried is divided into subsets by dividing tables with join conditions into the same subset of tables to be queried, wherein different subsets of tables to be queried have no intersection.
[0034] This specification provides a data query device, comprising:
[0035] The acquisition module is used to acquire a query statement, wherein the query statement carries the identifier of the table to be queried, the join conditions between the tables to be queried, and the output restrictions of the query statement.
[0036] The determination module is used to determine the table corresponding to each table identifier, which will be used as the table to be queried.
[0037] The connection module is used to determine the driving table and non-driving table based on each table to be queried and the connection conditions between the tables to be queried.
[0038] The restriction module is used to restrict the driving table according to the output restriction conditions to obtain the restricted driving table;
[0039] The output module connects the non-driving table and the restricted driving table according to the connection conditions between the tables to be queried, and obtains the query result corresponding to the query statement.
[0040] Optionally, the connection includes an external connection;
[0041] The connection module is specifically used to: take the set of tables to be queried as the set of tables to be queried; divide the set of tables to be queried according to the connection conditions between the tables to be queried, using a preset partitioning strategy, to obtain subsets of tables to be queried; for each subset of tables to be queried, determine the tables in the subset of tables to be queried except for the joins, and join the tables in the subset of tables to be queried except for the joins according to the connection conditions between the tables in the subset of tables to be queried, to obtain the driving table.
[0042] Optionally, the connection module is specifically used to: perform equivalent transformation on the connection conditions between tables in the subset of tables to be queried according to a preset transformation strategy; and connect the tables in the subset of tables to be queried except for the join according to the transformed connection conditions between the tables in the subset of tables to be queried, except for the join, to obtain the driving table.
[0043] Optionally, the output constraints include a first type of condition and a second type of condition;
[0044] When the output constraint is a first type of condition, the constraint module is specifically used to determine the number of output results in the first type of condition, filter the data of the number of output results in the driving table, and determine a table composed of the data of the number of output results as the restricted driving table.
[0045] When the output constraint is a second type of condition, the constraint module is specifically used to determine the starting position and offset n of the data in the second type of condition, filter the n data after the starting position of the data in the driving table according to the sorting of each data in the driving table, and determine the table composed of the n data as the restricted driving table, where n is a positive integer.
[0046] Optionally, if the output restriction condition is a second type of condition, the restriction module is specifically used to determine the connection field included in the connection condition between the driving table and the non-driving table; when the connection field has a unique constraint in the non-driving table and the subset of tables to be queried is the same as the set of tables to be queried, the driving table is restricted according to the second type of condition to obtain the restricted driving table.
[0047] Optionally, the connection module is specifically used to construct, for each subset of tables to be queried, a connected graph corresponding to the subset of tables to be queried, with the tables contained in the subset as nodes and the connection conditions between the tables contained in the subset as edges; and to determine that the tables contained in the nodes of the connected graph other than those with the connection conditions of outer connections are the tables in the subset of tables to be queried that are not connected.
[0048] Optionally, the connection module is specifically used to divide the set of tables to be queried into subsets by dividing tables with connection conditions into the same subset of tables to be queried, wherein different subsets of tables to be queried have no intersection.
[0049] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described data query method.
[0050] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-described data query method.
[0051] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:
[0052] The data query method provided in this specification involves determining the table corresponding to the table identifier carried in the obtained query statement as the table to be queried, determining the driving table and non-driving table based on the connection relationship between each table to be queried, restricting the driving table according to the output restriction conditions carried in the query statement, and connecting the restricted driving table and non-driving table to obtain the query result corresponding to the query statement.
[0053] As can be seen from the above method, when performing data query, the table to be queried is determined according to the table identifier in the query statement. Based on the connection relationship between the tables to be queried, the driving table and the non-driving table are determined. The driving table is first restricted by the output constraints in the query statement. Then, the restricted driving table is joined with the non-driving table to obtain the query result corresponding to the query statement. This reduces the amount of computation in the connection process, reduces the calculation of invalid data, and speeds up the data query. Attached Figure Description
[0054] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and their descriptions, serving to explain this specification and do not constitute an undue limitation thereof.
[0055] In the picture:
[0056] Figure 1 This is a flowchart illustrating one of the data query methods described in this specification.
[0057] Figure 2 This is a connected graph corresponding to a subset 1 in this specification;
[0058] Figure 3 A schematic diagram of a data query device provided in this specification;
[0059] Figure 4 The corresponding information provided in this specification Figure 1 A schematic diagram of an electronic device. Detailed Implementation
[0060] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0061] The embodiments of this specification provide a method, apparatus, storage medium, and electronic device for data querying. The technical solutions provided by the embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0062] Figure 1 This is a flowchart illustrating a data query method described in this specification, which specifically includes the following steps:
[0063] S100: Obtain a query statement, wherein the query statement carries the identifier of the table to be queried, the join conditions between the tables to be queried, and the output restrictions of the query statement.
[0064] In real-world applications, users may need to query multiple tables when performing data queries. The connection methods between these tables may be the same or different. For example, the connection methods between the tables in a query statement may be a mixture of outer joins and inner joins, rather than a single connection method.
[0065] Therefore, in this specification, the device used to execute the query statement obtains the query statement, which carries the identifier of the table to be queried, the join conditions between the tables to be queried, and the output restrictions of the query statement. The device executing the query statement can be the server containing the table to be queried, or a device such as a server or personal computer (PC) capable of executing the scheme described in this specification. For ease of explanation, the following description uses a server as the execution subject.
[0066] Output constraints carried in a query statement restrict the output results. There are two types: one restricts the number of output results, and the other restricts the starting position and offset of the data. For example, suppose query statement 1 is:
[0067]
[0068] Query statement 1 means taking table t1 as the primary table, performing a left outer join with t2 based on the condition t1.c1 = t2.c1, and then performing an inner join with t3 based on the condition t1.c2 = t3.c2, resulting in result 1. Then, taking table t4 as the primary table, performing a left outer join with t5 based on the condition t4.c1 = t5.c1, and then performing an inner join with t6 based on the condition t4.c2 = t6.c2, resulting in result 2. Result 1 and result 2 are then cross-joined to obtain the final table to be queried. The first 10 data points from all fields in this table are output as the query results. In query statement 1, t1 to t6 are table identifiers, and "t1 left join t2 on t1.c1 = t2.c1, t3 where t1.c2 = t3.c2" and "t4 left join t5 on t4.c1 = t5.c1, t6 where t4.c2 = t6.c2" are join conditions. The output restriction condition in query statement 1 is "limit". The output constraint "10" limits the number of output results. It means that the first 10 data entries from the joined table are taken, and the resulting table is the result of query statement 1. Let's assume query statement 2 is:
[0069]
[0070]
[0071] Query statement 2 means taking table t1 as the main table, performing a left outer join with t2 according to the condition t1.c1 = t2.c1, and then performing an inner join with t3 according to the condition t1.c2 = t3.c2. The result will be output starting from the 10th data point, with a total of 1 output result. In query statement 2, t1 to 3 are table identifiers, "t1 left join t2 on t1.c1 = t2.c1,t3where t1.c2 = t3.c2" is the join condition, and the output restriction condition in query statement 2 is "limit 10,1". This output restriction condition limits the starting position and offset of the data, indicating that one data point will be taken from the joined table starting from the 10th data point, that is, the 11th data point. The table consisting of the 11th data point will be the query result of query statement 2.
[0072] S102: Determine the table corresponding to each table identifier as the table to be queried.
[0073] The server determines the tables corresponding to each table identifier and uses them as the tables to be queried. Continuing with the previous example, the table identifiers in query statement 1 are t1 to 6. Based on each table identifier, the server determines the tables in the database. The table identifiers t1 to 6 correspond to tables 1 to 6 in the database, and tables 1 to 6 are used as the tables to be queried.
[0074] S104: Determine the driving table and non-driving table based on each table to be queried and the connection conditions between them.
[0075] The server determines the driving table and non-driving tables based on the tables to be queried and the join conditions between them. The join methods can include outer join, inner join, cross join, etc. The driving table is the base table in the table join. When performing a table join, the data in the driving table is used as the base data for the loop, and then the data in the non-driving table is filtered based on each base data condition.
[0076] Specifically, the join methods between the tables to be queried include outer joins. Based on a preset transformation strategy, the join conditions between the tables to be queried are equivalently transformed. Then, based on the transformed join conditions (excluding outer joins), the tables to be queried are joined to obtain the driving table. The preset transformation strategy is based on the principle of relational algebraic equivalence transformation, ensuring that the table obtained by joining with the transformed join conditions is identical to the table obtained by joining with the untransformed join conditions. Continuing with the previous example, query statement 1 uses two join methods: inner join and outer join. Following the preset transformation strategy, the join conditions between tables 1 to 6 in query statement 1 are equivalently transformed. In query statement 1, table 1 is first outer joined with table 2, then inner joined with table 3. After the transformation strategy, table 1 is first inner joined with table 3, then outer joined with table 2. The transformed join condition is "t1 inner join t3 on t1.c2=t3.c2 left join t2 on t1.c1=t2.c1". Based on the transformed join condition, all tables except those used for the outer join are joined, i.e., tables 1 and 3 are inner joined. This resulting table is used as the driving table 1. Using the same method as in the previous example, tables 4 to 6 are joined in the same way to obtain the driving table 2. Simultaneously, non-driving tables are identified from the tables to be queried: tables 2 and 5.
[0077] Furthermore, to facilitate obtaining the driving table, the set of tables to be queried can be considered as the query table set. Based on the join conditions between the query tables, a preset partitioning strategy is used to divide the query table set into subsets. For each subset, the tables other than those with joins are identified. Based on the join conditions between these tables, they are joined to obtain the driving table. Specifically, when partitioning the query table set using the preset partitioning strategy, tables with join conditions are grouped into the same subset. Different subsets do not overlap. If, according to the preset partitioning strategy, the query table set cannot be divided into at least two subsets, the set is directly used as the subset.
[0078] Continuing with the example in step S102, query statement 1 uses two join methods: inner join and outer join. The set of tables 1-6 is taken as the query set. Based on the join conditions between the tables (i.e., tables 1-6), the query set is divided according to the method of grouping tables with join conditions into the same subset of the query sets. The join between table 1 and table 2 is an outer join, and the join between table 1 and table 3 is an inner join. However, there are no joins or join conditions between table 1 and tables 4-6. Furthermore, the join between table 4 and table 5 is an outer join, and the join between table 4 and table 6 is an inner join. Therefore, the query set can be divided into two subsets: subset 1 and subset 2. Subset 1 contains tables 1-3, and the join condition between the tables in subset 1 is "t1 left join t2 on t1.c1=t2.c1,t3 where". t1.c2 = t3.c2”, Subset 2 contains tables 4 to 6, and the join condition between the tables in Subset 2 is “t4 left join t5 on t4.c1 = t5.c1, t6 where t4.c2 = t6.c2”, Subset 1 and Subset 2 have no intersection.
[0079] After obtaining each subset of tables to be queried, for each subset, identify the tables in the subset excluding joins. According to a preset transformation strategy, perform equivalent transformations on the join conditions between the tables in the subset. Based on the transformed join conditions between the tables in the subset excluding joins, join the tables in the subset excluding joins to obtain the driving table.
[0080] Continuing with the previous example, for subset 1, according to the preset transformation strategy, the join conditions between tables 1 to 3 in subset 1 are equivalently transformed. In subset 1, table 1 is first outer joined with table 2, and then inner joined with table 3. After the transformation strategy, table 1 is first inner joined with table 3, and then outer joined with table 2. That is, the transformed join condition is "t1 inner join t3 on t1.c2=t3.c2 left join t2 on t1.c1=t2.c1". Based on the transformed join condition, the tables other than the outer join are joined, that is, tables 1 and 3 are inner joined. The resulting table is used as the driving table 1. Using the same method as in the previous example, subset 2 is joined in the same way to obtain the driving table 2. At the same time, non-driving tables are determined from each subset. The non-driving table in subset 1 is table 2, and the non-driving table in subset 2 is table 5.
[0081] S106: Based on the output constraint conditions, the driving table is subjected to constraint processing to obtain the constrained driving table.
[0082] The server applies restrictions to the driver table based on the output constraints, resulting in a restricted driver table. The output constraints include a first type of condition and a second type of condition.
[0083] Specifically, the server determines the output constraints in the query statement. When the output constraint is a first-type condition, it needs to determine the number of output results under the first-type condition, filter the data in the driving table based on the number of output results, and determine a table composed of the data based on the number of output results as the constrained driving table. When the output constraint is a second-type condition, it determines the join fields contained in the join conditions between the driving table and the non-driving table, and determines whether the join fields have unique constraints in the non-driving table, and whether the subset of tables to be queried is the same as the set of tables to be queried. When the join field has a unique constraint in the non-driving table, and the subset of tables to be queried is the same as the set of tables to be queried, determine the starting position and offset n of the data in the second type of condition. According to the sorting of the data in the driving table, filter the n data after the starting position in the driving table to determine the table composed of n data, which is the restricted driving table. Here, n is a positive integer. The data in the field with the unique constraint in the table must be unique and cannot appear repeatedly. That is, if the above join field is the primary key in the non-driving table, then the above join field has a unique constraint. Otherwise, it is necessary to determine whether the above join field has appeared more than twice in the non-driving table. If so, the above join field does not have a unique constraint; otherwise, the above join field has a unique constraint.
[0084] Continuing with the previous example, the output restriction condition in query statement 1 is "limit 10". This output restriction condition is a first-type condition, determining that the number of output results under the first-type condition is 10. We then filter 10 data points from driving table 1, creating a table composed of these 10 filtered data points, which becomes the restricted driving table 1. We apply the same restriction to driving table 2 to obtain the restricted driving table 2.
[0085] Assuming that field c1 in query statement 2 is a field with a unique constraint in table 2, and processing query statement 2 according to the examples in steps S102 to S104, the driving table obtained in step S104 is driving table 3, and the output restriction condition in query statement 2 is "limit 10,1". This output restriction condition is a second type of condition. Determine the connection field contained in the connection condition between driving table 3 and non-driving table (i.e., table 2), which is field c1. Determine whether field c1 has a unique constraint in table 2, and whether the subset of tables to be queried is the same as the set of tables to be queried. Field c1 has a unique constraint in Table 2, and the subset of tables to be queried is the same as the set of tables to be queried. It is necessary to determine the starting position and offset n of the data in the output constraint condition (i.e., “limit10,1”), that is, the starting position of the data is 10 and the offset is 1. According to the sorting of each data in the driving table 3, the data after the 10th data in the driving table 3 is filtered, and the table formed by the filtered data (i.e. the 11th data in the driving table 3) is determined as the restricted driving table 3.
[0086] S108: Based on the connection conditions between the tables to be queried, connect the non-driving table and the restricted driving table to obtain the query result corresponding to the query statement.
[0087] The server joins the non-driving table and the restricted driving table based on the join conditions between the tables to be queried, obtaining the query result corresponding to the query statement. Continuing with the previous example, for query statement 1, based on the join condition between table 2 and the restricted driving table 1, table 2 is joined with the restricted driving table 1, resulting in the first join result. Based on the join condition between table 5 and the restricted driving table 2, table 5 is joined with the restricted driving table 2, resulting in the second join result. The first join result and the second join result are then cross-joined, and the join result after cross-joining is restricted, resulting in the query result corresponding to query statement 1. For query statement 2, based on the join condition between table 2 and the restricted driving table 3, table 2 is joined with the restricted driving table 3, resulting in the query result corresponding to query statement 2.
[0088] Generally, when performing data queries, the tables to be queried are first identified based on the table identifiers in the query statement. These tables are then joined according to the join conditions. The resulting joins are then processed according to output constraints, and the processed results are output as the query results. However, in this method, the tables to be queried are identified based on the table identifiers in the query statement. A preset partitioning strategy is used to divide the set of tables to be queried into subsets. Based on the join relationships between the tables in these subsets, a preset transformation strategy is used to transform them. According to the transformed join conditions, the tables in the subsets other than those joined are joined to obtain the driving table. The output constraints in the query statement are determined, and it is judged whether the driving table can be restricted based on the join fields of the non-driving tables and the number of subsets. The restricted driving table is then joined with the non-driving tables to obtain the query results. By employing a preset transformation strategy, the join relationships between the tables to be queried are transformed. The tables in the tables to be queried, except for the non-join tables, are joined to obtain the driving table that can be restricted. Thus, the driving table can be restricted first, and then joined with the non-driving tables. This reduces the calculation of invalid data and speeds up the query.
[0089] Continuing with the previous example, assuming that tables 1-6 each contain 20 data points and the data in each table matches, for query statement 1, under normal circumstances, tables 1-6 would first be joined based on the join conditions. This process requires filtering other tables using the 20 data points from the main table as the filtering condition, especially when performing a cross join between result 1 and result 2, which requires significant computation. However, while this method uses the 20 data points from the main table as the filtering condition for other tables in step S104 (excluding the outer join), resulting in driving table 1 and driving table 2, step S106 restricts driving table 1 and driving table 2 to only contain 10 data points each. Then, an outer join is performed between the driving table and the non-driving table, and the results are cross-joined. This method uses 10 data points as the filtering condition in both the outer join and subsequent cross join, significantly reducing computation and speeding up the query compared to the usual approach.
[0090] For query statement 2, under normal circumstances, tables 1 to 3 are joined first based on the join conditions between tables 1 and 3. In this process, the other tables need to be filtered using 20 data points from the main table as the filter condition. The result containing 20 data points after the join is output starting from the 10th data point, with the output result being 1, that is, the 11th data point is used as the query result. However, although this method filters the other tables using 20 data points from the main table as the filter condition when performing joins other than the outer join in step S104 above, resulting in driving table 3, driving table 3 is restricted in step S106 above. The restricted driving table 3 contains only 1 data point. Then, driving table 3 is outer joined with table 2, and the result is directly used as the query result. This method restricts the driving table before performing the outer join and filters using 1 data point as the filter condition, directly obtaining the query result. Compared with the general case, this reduces a lot of calculation and speeds up the query.
[0091] In step S104 of the above method, for each subset of tables to be queried, when determining the tables in the subset other than those with outer joins, a connected graph corresponding to the subset of tables to be queried can be constructed, with the tables contained in the subset as nodes and the connection conditions between the tables in the subset as edges. The tables contained in the nodes of the connected graph other than those with outer joins on the edges are determined to be the tables in the subset of tables to be queried that are not included in outer joins. An example is provided in step S104 of the above method. Figure 2 As shown, Figure 2 This specification defines a connected graph corresponding to subset 1. For query statement 1, there are subset 1 and subset 2, which are subsets of the tables to be queried. For subset 1, a connected graph can be constructed with tables 1 to 3 contained in subset 1 as nodes and the connection conditions between the tables contained in subset 1 as edges. Figure 3 Node 1 contains table 1, node 2 contains table 2, and node 3 contains table 3. The edges connecting the nodes contain the join conditions between the tables. The join conditions between the tables are... Figure 3 The edges connecting the nodes are not further marked. Identify the tables contained in the nodes of the connected graph other than those whose edge connection condition is an outer join, namely Table 1 and Table 3. Treat Table 1 and Table 3 as the tables in the subset of tables to be queried, excluding those with outer joins. Construct the connected graph corresponding to subset 2 using the above method, and determine the tables in subset 2 other than those with outer joins, namely Table 4 and Table 6.
[0092] Based on the created connected graph, in step S106 of the above method, when the output constraint is a second type of condition, the join field contained in the join condition between the driving table and the non-driving table can be determined, and it can be determined whether the join field has a unique constraint in the non-driving table and whether there is only one connected graph. When the join field has a unique constraint in the non-driving table and there is only one connected graph, the driving table can be restricted according to the second type of condition to obtain the restricted driving table.
[0093] The execution server described in this manual contains multiple components such as an optimizer and an executor. The optimizer can generate an execution plan corresponding to the query statement according to the methods described in steps S100 to S108 above. Then, the executor performs data querying according to the execution plan generated by the optimizer to obtain the query result corresponding to the query statement.
[0094] The above describes a data query method provided by one or more embodiments of this specification. Based on the same idea, this specification also provides a corresponding data query apparatus, such as... Figure 3 As shown.
[0095] Figure 3 This specification provides a schematic diagram of a data query device, specifically including:
[0096] The acquisition module 200 is used to acquire a query statement, wherein the query statement carries the identifier of the table to be queried, the connection conditions between the tables to be queried, and the output restriction conditions of the query statement.
[0097] The determination module 202 is used to determine the table corresponding to each table identifier, which is the table to be queried.
[0098] The connection module 204 is used to determine the driving table and non-driving table based on each table to be queried and the connection conditions between the tables to be queried;
[0099] The restriction module 206 is used to perform restriction processing on the driving table according to the output restriction conditions to obtain the restricted driving table;
[0100] The output module 208 connects the non-driving table and the restricted driving table according to the connection conditions between the tables to be queried, and obtains the query result corresponding to the query statement.
[0101] Optionally, the connection includes an external connection;
[0102] The connection module 204 is specifically used to: take the set of tables to be queried as the set of tables to be queried; divide the set of tables to be queried according to the connection conditions between the tables to be queried, using a preset partitioning strategy, to obtain subsets of tables to be queried; for each subset of tables to be queried, determine the tables in the subset of tables to be queried except for the joins, and join the tables in the subset of tables to be queried except for the joins according to the connection conditions between the tables in the subset of tables to be queried, to obtain the driving table.
[0103] Optionally, the connection module 204 is specifically used to: perform equivalent transformation on the connection conditions between tables in the subset of tables to be queried according to a preset transformation strategy; and connect the tables in the subset of tables to be queried except for the join according to the transformed connection conditions between the tables in the subset of tables to be queried, except for the join, to obtain the driving table.
[0104] Optionally, the output constraints include a first type of condition and a second type of condition;
[0105] When the output restriction condition is a first type of condition, the restriction module 206 is specifically used to determine the number of output results in the first type of condition, filter the data of the number of output results in the driving table, and determine a table composed of the data of the number of output results as the restricted driving table.
[0106] When the output constraint is a second type of condition, the constraint module 206 is specifically used to determine the starting position and offset n of the data in the second type of condition, filter the n data after the starting position of the data in the driving table according to the sorting of each data in the driving table, and determine the table composed of the n data as the restricted driving table, where n is a positive integer.
[0107] Optionally, if the output restriction condition is a second type of condition, the restriction module 206 is specifically used to determine the connection field included in the connection condition between the driving table and the non-driving table; when the connection field has a unique constraint in the non-driving table and the subset of tables to be queried is the same as the set of tables to be queried, the driving table is restricted according to the second type of condition to obtain the restricted driving table.
[0108] Optionally, the connection module 204 is specifically used to construct, for each subset of tables to be queried, a connected graph corresponding to the subset of tables to be queried, with the tables contained in the subset as nodes and the connection conditions between the tables contained in the subset as edges; and to determine that the tables contained in the nodes of the connected graph other than those with the connection conditions of the edges being external connections are the tables in the subset of tables to be queried that are not external connections.
[0109] Optionally, the connection module 204 is specifically used to divide the set of tables to be queried into subsets by dividing tables with connection conditions into the same subset of tables to be queried, wherein different subsets of tables to be queried have no intersection.
[0110] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 The data query method shown.
[0111] This instruction manual also provides Figure 4 The diagram shows a schematic structural representation of the electronic device. Figure 4 At the hardware level, the electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for the business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to achieve the above-mentioned functions. Figure 1 The data query method is shown. Of course, in addition to the software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. In other words, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0112] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0113] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, ASICs, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0114] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0115] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware.
[0116] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0117] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0118] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0119] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0120] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0121] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0122] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0123] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0124] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0125] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0126] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0127] The above description is merely an embodiment of this specification and is not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.
Claims
1. A method for data querying, comprising: Obtain a query statement, wherein the query statement carries the identifier of the table to be queried, the join conditions between the tables to be queried, and the output restrictions of the query statement; Identify the tables corresponding to each table identifier as the tables to be queried; Based on each table to be queried and the join conditions between the tables to be queried, determine the driving table and the non-driving table; and based on the join conditions between the tables to be queried, divide the set of tables to be queried to obtain each subset of tables to be queried. According to the output constraint conditions, the driving table is subjected to constraint processing to obtain a constrained driving table; wherein, when the output constraint conditions are the second type of conditions used to constrain the starting position and offset of data, if the connection field contained in the connection condition between the driving table and the non-driving table has a unique constraint in the non-driving table, and the subset of tables to be queried is the same as the set of tables to be queried, the driving table is subjected to constraint processing according to the second type of conditions to obtain a constrained driving table; Based on the join conditions between the tables to be queried, the non-driving table and the restricted driving table are joined to obtain the query result corresponding to the query statement.
2. The method of claim 1, wherein the connection includes an external connection; For each subset of tables to be queried, identify the tables in that subset that are excluded from joins. Based on the join conditions between the tables in that subset that are excluded from joins, join the tables in that subset to obtain the driving table.
3. The method as described in claim 2, wherein, based on the join conditions between tables in the subset of tables to be queried (excluding joins), the tables in the subset of tables to be queried (excluding joins) are joined to obtain the driving table, specifically including: Based on the preset transformation strategy, the join conditions between the tables in the subset of tables to be queried are transformed into equivalent conditions. Based on the transformed join conditions between the tables in the subset of tables to be queried (excluding joins), the tables in the subset of tables to be queried (excluding joins) are joined to obtain the driving table.
4. The method of claim 2, wherein the output constraint further includes a first type of condition for limiting the number of output results; When the output constraint is a first type of condition, the driving table is constrained according to the output constraint to obtain a constrained driving table, specifically including: Determine the number of output results in the first type of condition, filter the data of the number of output results in the driving table, and determine a table composed of the data of the number of output results as the restricted driving table; When the output constraint is a second type of condition, the driving table is restricted according to the output constraint to obtain a restricted driving table, specifically including: Determine the starting position and offset n of the data in the second type of condition. According to the sorting of each data in the driving table, filter the n data after the starting position of the data in the driving table, and determine the table composed of the n data as the restricted driving table, where n is a positive integer.
5. The method as described in claim 2, for each subset of tables to be queried, determining the tables in the subset excluding those joined, specifically includes: For each subset of tables to be queried, construct a connected graph corresponding to that subset of tables, with the tables contained in that subset as nodes and the connection conditions between the tables contained in that subset as edges. The tables contained in the nodes of the connected graph, excluding those whose edge connection condition is an outer join, are the tables in the subset of tables to be queried, excluding those whose connection condition is an outer join.
6. The method as described in claim 2, wherein a preset partitioning strategy is used to partition the set of tables to be queried to obtain a subset of tables to be queried, specifically including: The set of tables to be queried is divided into subsets by dividing tables with join conditions into the same subset of tables to be queried, wherein different subsets of tables to be queried have no intersection.
7. A data query apparatus, comprising: The acquisition module is used to acquire a query statement, wherein the query statement carries the identifier of the table to be queried, the join conditions between the tables to be queried, and the output restrictions of the query statement. The determination module is used to determine the table corresponding to each table identifier, which will be used as the table to be queried. The connection module is used to determine the driving table and non-driving table based on each table to be queried and the connection conditions between the tables to be queried; and to divide the set of tables to be queried into subsets based on the connection conditions between the tables to be queried. The restriction module is used to restrict the driving table according to the output restriction conditions to obtain a restricted driving table; wherein, when the output restriction conditions are the second type of conditions used to restrict the starting position and offset of data, if the connection field contained in the connection condition between the driving table and the non-driving table has a unique constraint in the non-driving table, and the subset of tables to be queried is the same as the set of tables to be queried, the driving table is restricted according to the second type of conditions to obtain a restricted driving table; The output module connects the non-driving table and the restricted driving table according to the connection conditions between the tables to be queried, and obtains the query result corresponding to the query statement.
8. The apparatus of claim 7, wherein the connection includes an external connection; The connection module is specifically used to, for each subset of tables to be queried, determine the tables in the subset excluding joins, and connect the tables in the subset excluding joins according to the join conditions between the tables in the subset excluding joins, to obtain the driving table.
9. The apparatus of claim 8, wherein the connection module is specifically configured to: perform equivalent transformation on the connection conditions between tables in the subset of tables to be queried according to a preset transformation strategy; and connect the tables in the subset of tables to be queried except for those with connections, according to the transformed connection conditions between the tables in the subset of tables to be queried except for those with connections, to obtain a driving table.
10. The apparatus of claim 8, wherein the output limiting condition further includes a first type of condition; When the output constraint is a first type of condition, the constraint module is specifically used to determine the number of output results in the first type of condition, filter the data of the number of output results in the driving table, and determine a table composed of the data of the number of output results as the restricted driving table. When the output constraint is a second type of condition, the constraint module is specifically used to determine the starting position and offset n of the data in the second type of condition, filter the n data after the starting position of the data in the driving table according to the sorting of each data in the driving table, and determine the table composed of the n data as the restricted driving table, where n is a positive integer.
11. The apparatus of claim 8, wherein the connection module is specifically configured to: construct, for each subset of tables to be queried, a connected graph corresponding to the subset of tables to be queried, with the tables contained in the subset of tables to be queried as nodes and the connection conditions between the tables contained in the subset of tables to be queried as edges; and determine that the tables contained in the nodes of the connected graph other than those with connection conditions of external connections are the tables in the subset of tables to be queried other than those with external connections.
12. The apparatus of claim 8, wherein the connection module is specifically configured to partition the set of tables to be queried into a subset of tables to be queried by partitioning tables with connection conditions into the same subset of tables to be queried, wherein, Different subsets of tables to be queried have no overlap.
13. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in any one of claims 1 to 6.
14. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method for inquiring data in trans-partition databases and trans-partition inquiring device
CN106156168A
Table data query method, table data query device and table data query system for distributed database
CN113420033A