A query statement execution method and device, a storage medium, and an electronic device
By generating candidate execution plans, determining the target predicate statement, and calculating the number of rows in the data table after the join operation, the problem of inaccurate optimization estimation is solved, the selection of the optimal execution plan is realized, and the database query efficiency is improved.
Patent Information
- Application Number
- CN202211735009.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-12-30
AI Technical Summary
In existing technologies, optimizers have low accuracy in estimating the execution plan of data query statements, which makes it impossible to select the optimal execution plan.
By generating candidate execution plans, the target predicate statement required for the join operation is determined, the number of rows in the data table after the join operation is calculated, and the optimal execution plan is selected.
It improved the accuracy of data query operations, selected the optimal execution plan, and enhanced database query efficiency.
Smart Images

Figure CN115905308B_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 executing a query statement. Background Technology
[0002] Currently, when a database executes a data query operation corresponding to a data query statement (i.e., an SQL statement), it first generates various execution plans required to execute the data query operation (i.e., how the database reads and filters data). Then, through the optimizer, it determines the optimal execution plan from the various execution plans and performs the data query according to this optimal execution plan.
[0003] Since different execution plans have different performance when executing data query statements with different numbers of rows in the query results, the optimizer estimates the number of rows of the query results returned when executing the data query statement according to the execution plan, and determines which execution plan to select based on the estimated number of rows of the query results.
[0004] However, in the existing technology, the optimizer has low accuracy in estimating the number of rows of query results returned when executing the data query operation corresponding to the data query statement according to an execution plan, which causes the optimizer to fail to select the optimal execution plan. Summary of the Invention
[0005] This specification provides a method, apparatus, storage medium, and electronic device for executing a query statement, in order to solve the problem in the prior art where the accuracy of the estimated result is low when estimating the number of rows of query results returned when executing the data query operation corresponding to the data query statement according to the execution plan.
[0006] The following technical solution is adopted in this specification:
[0007] This manual provides a method for executing query statements, including:
[0008] Retrieve the query statement to be executed;
[0009] Generate candidate execution plans for the query statement;
[0010] For each candidate execution plan, determine the join operations required to execute the query operation of the query statement according to the candidate execution plan. The join operations are used to connect the data tables to be queried by the query statement.
[0011] For each join operation, select the target predicate statement from the join predicate statements involved in that join operation;
[0012] For each data column involved in the target predicate statement, determine the data column in each data column involved in each connect predicate statement that has the same data as the data in that data column, and take it as the corresponding equivalent data column. Then, determine the number of different data in the data column based on the preset reference number of different data in each data column in the data column and the corresponding equivalent data column.
[0013] Based on the number of different data in each data column involved in the target predicate statement, calculate the number of rows in the joined data table obtained after performing the join operation, and use it as the estimated number of rows corresponding to the join operation;
[0014] Based on the estimated number of rows corresponding to each join operation in each candidate execution plan, a target execution plan is selected from the candidate execution plans, and the query operation corresponding to the query statement is executed according to the target execution plan.
[0015] Optionally, for each join operation, a target predicate statement is selected from the join predicate statements involved in that join operation, specifically including:
[0016] For each join operation, determine each join predicate statement involved in the join operation as a candidate join predicate statement;
[0017] Among the data columns involved in each candidate join predicate statement, at least one data column with the same data is taken as a set of data columns corresponding to the join operation;
[0018] For each set of data columns, determine the set of data tables corresponding to that set of data columns based on the data tables to which each data column in that set belongs;
[0019] Determine whether there is an intersection between the data table set corresponding to the data column set containing the first type of data column, where the first type of data column refers to the data column in the data table that is not joined in the join operation;
[0020] If so, then arbitrarily select one data table from each data table in the intersection as the target data table, and select the connection predicate statement whose data column is the data column of the target data table from each connection predicate statement involved in the connection operation as the target predicate statement.
[0021] Optionally, the method further includes:
[0022] For each join predicate statement involved in the join operation, determine whether the join predicate statement is equivalent to the target predicate statement;
[0023] If not, then the connecting predicate statement is also used as the target predicate statement.
[0024] Optionally, the number of different data in the data column is determined based on a preset reference number of different data in each data column of the data column and the corresponding equivalent data columns. Specifically, this includes:
[0025] For each data column in the data column and each corresponding equal-value data column, obtain the preset reference number of different data in the data column;
[0026] From each of the obtained reference quantities, select the reference quantity with the smallest value as the number of different data in that data column.
[0027] Optionally, based on the number of distinct data items in each data column involved in the target predicate statement, the number of rows in the joined table obtained after performing the join operation is calculated, specifically including:
[0028] If the number of target predicate statements is one, then the join selectivity corresponding to the join operation is determined based on the number of different data in each data column involved in the target predicate statement;
[0029] The number of rows in the resulting connected data table is determined based on the number of rows in each data table that the join operation needs to connect and the join selectivity.
[0030] Optionally, the method further includes:
[0031] If the number of target predicate statements is greater than one, then according to whether the data column involved in each target predicate statement belongs to the first type, the data columns are divided into a first set and a second set. The data columns of the first type refer to the data columns in the data table that are not joined in the join operation.
[0032] Based on the number of distinct data points in each data column of the first set, determine the number of distinct data points in each data column of the first set; and
[0033] The number of different data in each data column of the second set is determined based on the number of different data in each data column of the second set;
[0034] The join selectivity corresponding to the join operation is determined based on the number of different data in each data column of the first set and the number of different data in each data column of the second set.
[0035] The number of rows in the resulting connected data table is determined based on the number of rows in each data table that the join operation needs to connect and the join selectivity.
[0036] Optionally, the number of different data in each data column of the first set is determined based on the number of different data in each data column of the first set, specifically including:
[0037] Determine whether each data column in the first set belongs to the same data table;
[0038] If so, then based on the correlation between each data column in the first set, determine the number of different data in each data column in the first set;
[0039] If not, then determine the number of different data in each data column of the first set based on the number of different data in each data column of the first set.
[0040] Optionally, the number of distinct data points in each data column of the second set is determined based on the number of distinct data points in each data column of the second set, specifically including:
[0041] Determine whether each data column in the second set belongs to the same data table;
[0042] If so, then determine the number of different data in each data column of the second set based on the correlation between each data column in the second set;
[0043] If not, then determine the number of different data in each data column of the second set based on the number of different data in each data column of the second set.
[0044] This specification provides a query statement execution device, including:
[0045] The retrieval module is used to retrieve the query statements to be executed.
[0046] A generation module is used to generate candidate execution plans for the query statement;
[0047] The first determining module is used to determine, for each candidate execution plan, the join operations required when executing the query operation of the query statement according to the candidate execution plan, wherein the join operations are used to connect the data tables to be queried by the query statement;
[0048] The selection module is used to select the target predicate statement from the various join predicate statements involved in each join operation.
[0049] The second determining module is used to determine, for each data column involved in the target predicate statement, the data column in each data column involved in each connecting predicate statement that has the same data as the data in the data column, as the corresponding equivalent data column, and to determine the number of different data in the data column based on the preset reference number of different data in each data column in the data column and the corresponding equivalent data column.
[0050] The estimation module is used to calculate the number of rows in the joined data table obtained after the join operation is performed, based on the number of different data in each data column involved in the target predicate statement, and use this as the estimated number of rows corresponding to the join operation.
[0051] The execution module is used to select a target execution plan from the candidate execution plans based on the estimated number of rows corresponding to each join operation in each candidate execution plan, and execute the query operation corresponding to the query statement according to the target execution plan.
[0052] Optionally, the selection module is specifically used to: for each join operation, determine each join predicate statement involved in the join operation as a candidate join predicate statement; take at least one data column with the same data among the data columns involved in each candidate join predicate statement as a data column set corresponding to the join operation; for each data column set, determine the data table set corresponding to the data column set according to the data table to which each data column in the data column set belongs; determine whether there is an intersection among the data table sets corresponding to the data column set containing data columns of the first type, where the first type of data columns refers to data columns in the data tables not joined in the join operation; if so, arbitrarily select one data table from each data table in the intersection as the target data table, and select the join predicate statement whose data columns involved in the join operation belong to the data columns of the target data table as the target predicate statement.
[0053] Optionally, the selection module is further configured to determine whether the connection predicate statement is equivalent to the target predicate statement for each connection predicate statement involved in the connection operation; if not, then the connection predicate statement is also used as the target predicate statement.
[0054] Optionally, the selection module is specifically used to obtain a preset reference number of different data in each data column of the data column and each data column of the corresponding equal value data column; and select the reference number with the smallest value from each obtained reference number as the number of different data in the data column.
[0055] Optionally, the second determining module is specifically used to: if the number of target predicate statements is one, determine the join selectivity corresponding to the join operation based on the number of different data in each data column involved in the target predicate statement; and determine the number of rows in the joined data table obtained after performing the join operation based on the number of rows in each data table to be joined by the join operation and the join selectivity.
[0056] Optionally, the second determining module is further configured to: if the number of target predicate statements is greater than one, divide the data columns into a first set and a second set according to whether the type of each data column involved in each target predicate statement is a first type, wherein the data columns of the first type refer to the data columns in the data tables not being joined in the join operation; determine the number of different data in each data column in the first set according to the number of different data in each data column in the first set; determine the number of different data in each data column in the second set according to the number of different data in each data column in the second set; determine the join selectivity corresponding to the join operation according to the number of different data in each data column in the first set and the number of different data in each data column in the second set; and determine the number of rows in the joined data table obtained after performing the join operation according to the number of rows in each data table to be joined by the join operation and the join selectivity.
[0057] Optionally, the estimation module is specifically used to determine whether each data column in the first set belongs to the same data table; if so, it determines the number of different data in each data column in the first set based on the correlation between each data column in the first set; if not, it determines the number of different data in each data column in the first set based on the number of different data in each data column in the first set.
[0058] Optionally, the estimation module is specifically used to determine whether each data column in the second set belongs to the same data table; if so, it determines the number of different data in each data column in the second set based on the correlation between each data column in the second set; if not, it determines the number of different data in each data column in the second set based on the number of different data in each data column in the second set.
[0059] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for executing the query statement.
[0060] 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 query statement execution method.
[0061] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:
[0062] The query execution method provided in this specification first obtains the query statement to be executed, generates candidate execution plans for the query statement, and for each candidate execution plan, determines the join operations required to execute the query operation according to that candidate execution plan. The join operations are used to connect the data tables to be queried by the query statement. For each join operation, a target predicate statement is selected from the join predicate statements involved in that join operation. For each data column involved in the target predicate statement, the data columns whose data in the data columns involved in the join predicate statements are identical to the data in that data column are determined. The data column is used as the equivalent data column corresponding to the data column. Based on the preset reference number of different data in each data column of the data column and the equivalent data column corresponding to the data column, the number of different data in the data column is determined. Based on the number of different data in each data column involved in the target predicate statement, the number of rows in the joined data table obtained after the join operation is calculated, which is used as the estimated number of rows corresponding to the join operation. Based on the estimated number of rows corresponding to each join operation in each candidate execution plan, the target execution plan is selected from each candidate execution plan, and the query operation corresponding to the query statement is executed according to the target execution plan.
[0063] As can be seen from the above method, different candidate execution plans corresponding to the query statement to be executed can be analyzed to determine the join operations in each candidate execution plan that are required to join the data tables to execute the query statement to be executed, and to filter the join predicate statements corresponding to each join operation in the query statement to be executed. Thus, according to the target predicate statements corresponding to each selected join operation, the number of rows of data in the data table obtained after each join operation is estimated. Then, according to the number of rows of data in the data table obtained after each join operation in each candidate execution plan, each candidate execution plan can be evaluated to select the optimal candidate execution plan from all candidate execution plans, and the query statement to be executed is executed according to this selected execution plan. Attached Figure Description
[0064] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and are used to explain this specification, but do not constitute an undue limitation thereof. In the drawings:
[0065] Figure 1 This is a flowchart illustrating the execution method of a query statement provided in this specification;
[0066] Figure 2 This is a schematic diagram of a query statement to be executed as provided in this specification;
[0067] Figure 3 This is a schematic diagram of another query statement to be executed provided in this specification;
[0068] Figure 4 This is a schematic diagram of a query statement execution device provided in this specification;
[0069] Figure 5 This specification provides a corresponding Figure 1 A schematic diagram of an electronic device. Detailed Implementation
[0070] 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.
[0071] The technical solutions provided in the various embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0072] Figure 1 This is a flowchart illustrating the execution method of a query statement provided in this specification, including the following steps:
[0073] S100: Retrieves the query statement to be executed.
[0074] S102: Generate candidate execution plans for the query statement.
[0075] In this specification, the database can take the data query statement entered by the user as the query statement to be executed. When the database executes the query operation corresponding to the query statement to be executed, it will first determine how to execute the data query operation (that is, it will generate different candidate execution plans, each candidate execution plan corresponding to a method of executing the data query operation).
[0076] For example, the data to be retrieved in a query statement may come from multiple tables. Therefore, when the database executes the query, it needs to join these tables to obtain a joined table, and then retrieve the data from the joined table. At this time, the different order of joining the tables will also result in different execution efficiencies of the query statement. Therefore, the database will pre-generate different execution plans. Each execution plan contains the execution order of the join operations required to execute the query statement. The optimizer will estimate the number of rows obtained after executing each join operation according to each execution plan, and select the optimal execution plan from the various execution plans based on the estimated number of rows, so that the database can perform data query according to the selected optimal execution plan.
[0077] Before this, the database needs to generate execution plans for each query statement to be executed, and then estimate each execution plan in order to filter the execution plans according to the estimation results.
[0078] The following combination Figure 2 The above implementation plan will be explained in detail.
[0079] Figure 2 This is a schematic diagram of a query statement to be executed as provided in this specification.
[0080] exist Figure 2 The query statement to be executed is "SELECT * FROM T1, T2, T3 WHERE T1.A = T2.B AND T2.B = T3.C AND T1.A = T3.C". In this query statement, "SELECT * FROM T1, T2, T3" means that all data that meets the three join predicate statements "T1.A = T2.B", "T2.B = T3.C", and "T1.A = T3.C" should be retrieved from the data tables T1, T2, and T3.
[0081] When executing the query statement to be executed, the database has multiple execution plans, meaning multiple different execution methods. The first method involves a first join operation, using the join predicate statement T1.A = T2.B to join table T1 and table T2, resulting in the joined table (because this join operation connects tables T1 and T2, the join predicate statement used here is the join predicate statement between these two tables, specifically T1.A = T2.B). Then, based on any one of the join predicate statements T2.B = T3.C and T1.A = T3.C, the joined table T1 and T2 can be joined with table T3 to obtain the query result of the query statement to be executed. The reason why the join predicate statements T2.B = T3.C and T1.A = T3.C can be used is... The reason why any of the join predicate statements in T3.C can be used as the join condition is that since T1.A = T2.B was already made in the first join operation, the data in column A of the data table after joining data table T1 and data table T2 is equal to the data in column B. Therefore, when the join predicate statement T2.B = T3.C is true, T1.A = T3.C will also be true (in other words, these two join predicate statements are equivalent, and the data columns in these two join predicate statements are equivalent; if one is true, the other is automatically true). Therefore, in the second join operation, either the join predicate statement T2.B = T3.C or T1.A = T3.C can be used as the join condition.
[0082] The second execution plan could begin by performing the first join operation, using the join predicate statement T2.B = T3.C to join data table T2 and data table T3, resulting in a combined data table. Then, using either the join predicate statement T1.A = T2.B or T1.A = T3.C, the combined data table T2 and data table T3 could be joined with data table T1 to obtain the query result of the query statement to be executed.
[0083] The third execution plan could be to first perform the first join operation, joining data table T1 and data table T3 according to the join predicate statement T1.A = T3.C, to obtain the data table after joining data table T1 and data table T3. Then, according to any one of the join predicate statements T1.A = T2.B and T2.B = T3.C, the data table after joining data table T1 and data table T3 could be joined with data table T2 to obtain the query result of the above query statement to be executed.
[0084] As can be seen from the above, when a database executes the same query statement, there can be multiple different execution plans. Due to the different join operations in each execution plan, the efficiency of executing the query statement according to different execution plans is also different. Therefore, in order to improve the efficiency of database querying data, the database needs to select the optimal execution plan from all execution plans.
[0085] In this specification, the execution subject used to implement the query statement execution method can refer to a specified device such as a server that has a database deployed, or a specified device such as a desktop computer or laptop computer that has a database deployed. For ease of description, the following will only use the database as the execution subject as an example to explain the query statement execution method provided in this specification.
[0086] S104: For each candidate execution plan, determine the join operations required to execute the query operation of the query statement according to the candidate execution plan, wherein the join operations are used to connect the data tables to be queried by the query statement.
[0087] In this specification, the database can determine the join operations required to execute the query operation of the query statement according to each candidate execution plan. Here, the join operations are used to connect the data tables to be queried by the query statement.
[0088] It should be noted that the table join operation is a common operation in databases (i.e., table join operation). When performing a table join operation, the database can determine the Cartesian product of all data in the two tables to be joined. Then, according to the join predicate statement, the Cartesian product of all data in the two tables can be filtered to obtain the filtered data, and the filtered data can be used as the new data table.
[0089] For example, suppose there are two data tables: table T1 contains column A, and table T2 contains column B. Column A contains data a, b, and c, and column B contains data a, d, and e. The Cartesian product of all data in these two tables is (a, a), (a, d), (a, e), (b, a), (b, d), (b, e), (c, a), (c, d), (c, e). If the join predicate is T1.A = T2.B, this join condition means selecting the row in both tables where the data in column A of table T1 is identical to the data in column B of table T2. This row is then used as the data in the joined table, which is (a, a) in the Cartesian product. Therefore, the row in table T1 corresponding to data a and the row in table T2 corresponding to data a can be selected as the output of the join operation.
[0090] S106: For each join operation, select the target predicate statement from the join predicate statements involved in that join operation.
[0091] As can be seen from the above, when performing each join operation, it is not necessary to use every join predicate statement involved in the execution of that join operation. For each join predicate statement that has an equivalence relationship, it is only necessary to select one join predicate statement to execute.
[0092] Based on this, in this specification, the database can select the target predicate statement from the various connection predicate statements involved in each connection operation, and then execute the connection operation based on the selected target predicate statement.
[0093] Specifically, for each join operation, the database can determine the join predicate statements involved in the join operation as candidate join predicate statements. For each candidate join predicate statement, at least one data column with the same data is taken as a set of data columns corresponding to the join operation. For each set of data columns, based on the data table to which each data column belongs, the database determines the set of data tables corresponding to the set of data columns. It then determines whether there is an intersection among the sets of data tables corresponding to the set of data columns containing data columns of the first type. Here, the first type of data columns can refer to data columns from the data tables not being joined in the join operation. If so, an arbitrary data table is selected from the data tables in the intersection as the target data table, and the join predicate statement whose data columns are the data columns to which the target data table belongs is selected from the join predicate statements involved in the join operation as the target predicate statement.
[0094] The following combination Figure 3 The above content will be explained in detail.
[0095] Figure 3 This is a schematic diagram of another query statement to be executed as provided in this specification.
[0096] exist Figure 3 In the query statement to be executed provided, the database needs to join data tables T1, T2, T3, and T4. Assuming the database has already joined data tables T1, T3, and T4 in previous join operations, the current join operation needs to join the resulting data table with data table T2. At this point, the join predicate statements involved in this join operation are the join predicate statements corresponding to the data columns in data tables T1, T3, and T4 and the data columns in data table T2. Specifically, the four join predicate statements T1.A = T2.B, T3.C = T2.B, T1.X = T2.Y, and T4.Z = T2.Y are considered as candidate join predicate statements. Previously, data tables T1, T3, and T4 were joined... The join predicates used in the process of joining T4 are T1.A=T3.C and T1.X=T4.Z. Therefore, the data in column A is the same as the data in column C, meaning these two columns are equivalent. Similarly, the data in column X is the same as the data in column Z, meaning these two columns are also equivalent. Therefore, this join operation can connect the data table resulting from the join of tables T1, T3, and T4 to table T2 based on any one of the join predicates T1.A = T2.B and T3.C = T2.B, or any one of the join predicates T1.X = T2.Y and T4.Z = T2.Y.
[0097] Furthermore, among the data columns A, B, C, X, Y, and Z involved in each candidate join predicate statement, at least one data column with the same data is taken as a set of data columns corresponding to the join operation. That is, data columns A and C can be a set of data columns {A, C}, data columns X and Z can be a set of data columns {X, Z}, data column B does not have any other data columns with the same data as data column B, therefore, data column B can be a set of data columns {B} alone, and similarly, data column Y can be a set of data columns {Y}.
[0098] Furthermore, for each set of data columns, the database determines the set of data tables corresponding to that set based on the data tables to which each data column belongs. For example, the set of data tables corresponding to the set of data columns {A, C} includes data table T1 to which data column A belongs and data table T2 to which data column C belongs. Therefore, the set of data tables corresponding to the set of data columns {A, C} is {T1, T3}. Similarly, the set of data tables corresponding to the set of data columns {X, Z} is {T1, T4}, the set of data tables corresponding to the set of data columns {B} is {T2}, and the set of data tables corresponding to the set of data columns {Y} is {T2}.
[0099] At this point, the database can determine whether there is an intersection between the set of data tables corresponding to the set of data columns containing the first type of data columns. Here, the first type of data columns are the data columns in the data tables that are not joined in the join operation. As can be seen from the above, when the data table after joining data tables T1, T3, and T4 needs to be joined with data table T2 in the current join operation, data table T2 is the joined data column, and data tables T1, T3, and T4 are the non-joined data columns. At this time, it can be determined that the set of data columns containing the first type of data columns is {A, C}, {X, Z}, and the set of data tables corresponding to the set of data columns containing the first type of data columns is {T1, T3}, {T1, T4}. The intersection at this time is data table T1. Therefore, data table T1 can be used as the target data table.
[0100] It should be noted that in this specification, the database allows data columns belonging to non-joined tables to be placed on one side of the equals sign in each join predicate statement, and data columns belonging to the joined tables to be placed on the other side. For example, assuming the join predicate statement is T2.Y = T1.X, and as we know from the above, table T2 is the joined table, the join predicate statement can be adjusted to T1.X = T2.Y. This is done to facilitate the subsequent calculation of the NDV value of the combined multiple data columns.
[0101] Then, the join predicate statement whose data column is the target data table can be selected from the join predicate statements involved in the join operation, and used as the target predicate statement. That is, the join predicate statement T1.A = T2.B that contains the data column of the target data table T1 can be selected from T1.A = T2.B and T3.C = T2.B, and the join predicate statement T1.X = T2.Y that contains the data column of the target data table T1 can be selected from T1.X = T2.Y and T4.Z = T2.Y. In other words, the two target predicate statements T1.A = T2.B and T1.X = T2.Y are used for the join operation in the current join operation.
[0102] In addition, after the database determines each target predicate statement using the above method, in order to avoid omissions, it can also determine whether each connection predicate statement involved in the connection operation is equivalent to the target predicate statement. If not, the connection predicate statement is also used as the target predicate statement.
[0103] S108: For each data column involved in the target predicate statement, determine the data column in each data column involved in each connecting predicate statement that has the same data as the data in the data column, and take it as the corresponding equivalent data column. Then, determine the number of different data in the data column based on the preset reference number of different data in each data column of the data column and the corresponding equivalent data column.
[0104] Furthermore, after determining the target predicate statement corresponding to each join operation, the database can, for each data column involved in the target predicate statement, determine the data columns in each data column involved in each join predicate statement that have the same data as the data in that data column, and use them as the corresponding equivalent data columns. Based on the preset reference number of different data in each data column of that data column and the corresponding equivalent data columns, the database can determine the number of different data in that data column.
[0105] Specifically, the database can obtain a preset reference number of different data in each data column and each of the corresponding equal-value data columns for the data column, and select the reference number with the smallest value from each obtained reference number as the number of different data in the data column.
[0106] For example: Suppose that there is an equivalent data column B in data column A, where the reference number of different data in data column A is 100 and the reference number of different data in data column B is 50. Then we consider that the number of different data in data column A is the smaller of the two reference numbers mentioned above, which is 50.
[0107] It should be noted that the above reference quantity is the number of different data in each column of each data table, which is pre-calculated by the database. As a reference quantity here, the above number of different quantities can refer to the number of data with different values.
[0108] S110: Based on the number of different data in each data column involved in the target predicate statement, calculate the number of rows in the joined data table obtained after performing the join operation, and use it as the estimated number of rows corresponding to the join operation.
[0109] In this specification, the database can calculate the number of rows in the joined table obtained after the join operation based on the number of different data in each data column involved in the target predicate statement, and use this as the estimated number of rows corresponding to the join operation.
[0110] Specifically, the database can determine whether the number of target predicate statements is one, and then estimate the number of rows corresponding to the join operation based on the determination result.
[0111] If the number of target predicate statements is one, the join selectivity corresponding to the join operation is determined based on the number of different data in each data column involved in the target predicate statement. The number of rows in the joined data table obtained after the join operation is determined based on the number of rows in each data table to be joined by the join operation and the join selectivity.
[0112] If the number of target predicate statements is greater than one, then based on whether the data column involved in each target predicate statement belongs to the first type, the data columns are divided into a first set and a second set. The data columns of the first type refer to the data columns in the data tables not being joined in the join operation. Based on the number of different data in each data column in the first set, the number of different data in each data column in the first set is determined. Similarly, based on the number of different data in each data column in the second set, the number of different data in each data column in the second set is determined. Based on the number of different data in each data column in the first set and the number of different data in each data column in the second set, the join selectivity corresponding to the join operation is determined. Based on the number of rows in each data table that needs to be joined in the join operation and the join selectivity, the number of rows in the joined data table obtained after performing the join operation is determined.
[0113] As can be seen from the above, the first type here refers to the data columns in the non-joined data table in the join operation. In each join predicate statement, the data columns of the first type can be uniformly placed on one side of the equal sign of the join predicate statement. Therefore, in other words, the data columns on the same side of the equal sign in each join predicate statement can be divided into a set.
[0114] In the above, the database can determine whether each data column in the first set belongs to the same data table. If so, it determines the number of different data in each data column in the first set based on the correlation between each data column in the first set. If not, it determines the number of different data in each data column in the first set based on the number of different data in each data column in the first set.
[0115] It's important to note that determining whether the number of target predicates is one is necessary because when the number of target predicate statements is not one, the relationships between different target predicate statements need to be considered. Specifically, when the number of target predicate statements is not one, the joint selection rate among these target predicate statements needs to be calculated when estimating the number of rows.
[0116] In the above content, the method for determining the join selectivity corresponding to the join operation based on the number of different data in each data column involved in the target predicate statement can be referenced by the following formula:
[0117]
[0118] In the above formula, That is, the number of distinct data points in data column A. This refers to the number of different data in data column B. From this, we can see that when the target predicate statement used in this join operation is only one, the join selectivity corresponding to this join operation can be determined based on the number of different data in each data column involved in this target predicate statement.
[0119] For example, assuming the target predicate statement is T1.A=T2.B, then we can choose a larger value from the number of different data in data column A and the number of different data in data column B. The reciprocal of this value is the join selectivity corresponding to this join operation.
[0120] Furthermore, the database determines the number of rows in the resulting joined table based on the number of rows in each table to be joined and the join selectivity, using the following formula:
[0121]
[0122] In the above formula, R1 is the number of rows in the data table to which data column A belongs, and R2 is the number of rows in the data table to which data column B belongs. Therefore, the database can determine the number of rows in the connected data table after performing the join operation based on the number of rows in each data table that needs to be joined by the join operation and the join selectivity.
[0123] Furthermore, when there is more than one target predicate statement, assuming the target predicate statements are T1.A=T2.B and T1.X=T2.Y, it is necessary to calculate the joint selectivity of these two target predicate statements, that is, the selectivity corresponding to (T1.A, T1.X) = (T2.B, T2.Y). Here, (T1.A, T1.X) represents the joint NDV of data column A and data column X, that is, the number of different data in data column A and data column X. Based on the number of rows of each data table to be joined and the joint selectivity, the number of rows of the joined data table obtained after performing the join operation is calculated. The formula for calculating the joint selectivity is as follows.
[0124]
[0125] in, The union of NDV, which is the number of distinct data points contained in data column A and data column X, The NDV is the number of distinct data points contained in data column B and data column Y.
[0126] The reason for calculating the joint NDV of data columns A and X, and the joint NDV of data columns B and Y, is that data columns A and X belong to the same side of the equal sign in the two target predicate statements, while the reason for calculating the joint NDV of data columns B and Y is that data columns A and X belong to the other side of the equal sign in the two target predicate statements.
[0127] The above-mentioned joint NDV, which is the number of different data contained in multiple data columns, can be calculated in two ways. The first method is when multiple data columns belong to the same data table. In this case, it is assumed that there is a relationship between these data columns, and the first calculation formula is used. The first calculation formula is shown below.
[0128]
[0129] In the above formula, C1, C2, ..., CN are the NDV values of different data columns, which are the number of different data in each data column.
[0130] The second scenario is when multiple data columns belong to different data tables. In this case, it is assumed that there is no relationship between these data columns, and the second calculation formula is used. The second calculation formula is shown below.
[0131]
[0132] In the above formula, C1, C2, ..., CN are the NDV values of different data columns, which are the number of different data in each data column.
[0133] In addition, when the data columns on both sides of the equation of each target predicate statement used in the join operation do not belong to the same table, the second formula mentioned above is used uniformly to calculate the joint NDV in order to maintain the consistency of the estimated number of rows.
[0134] Therefore, when selecting the join predicate statement whose data column is the target data table, it can make the data columns on the same side of the equality sign of each selected target predicate statement belong to the same data table as much as possible. This can avoid the problem that when the data columns on the same side of the target predicate statement selected in the join operation belong to the same data table and to different data tables, the number of rows in the final estimated row result will be different because the calculation method of the join NDV is different.
[0135] It should be noted that the reason for trying to ensure that the data columns on the same side of the equal sign of each selected target predicate statement belong to the same data table is that when calculating the joint NDV of each data column in the same data table, the correlation between the data columns can be taken into account, thus making the calculated result more accurate.
[0136] S112: Select a target execution plan from the candidate execution plans based on the estimated number of rows corresponding to each join operation in each candidate execution plan, and execute the query operation corresponding to the query statement according to the target execution plan.
[0137] In this specification, the database can calculate the cost value of each candidate execution plan based on the estimated number of rows corresponding to each join operation in each candidate execution plan using a preset cost calculation formula. Then, based on the calculated cost value of each candidate execution plan, the database can select the target execution plan from the candidate execution plans and execute the query operation corresponding to the query statement according to the target execution plan.
[0138] As can be seen from the above, the database can analyze different candidate execution plans corresponding to the query statement to be executed, to determine the join operations in each candidate execution plan that are required to join the data tables to execute the query statement, and to filter the join predicate statements corresponding to each join operation in the query statement to be executed. Thus, based on the target predicate statements corresponding to each selected join operation, the number of rows of data in the data table obtained after each join operation is estimated. Then, based on the number of rows of data in the data table obtained after each join operation in each candidate execution plan, each candidate execution plan is evaluated to select the optimal candidate execution plan, and the query statement to be executed is executed according to this selected execution plan.
[0139] The above describes one or more embodiments of the query statement execution method provided in this specification. Based on the same idea, this specification also provides a corresponding query statement execution device, such as... Figure 4 As shown.
[0140] Figure 4 This is a schematic diagram of a query statement execution device provided in this specification, the device comprising:
[0141] The acquisition module 401 is used to acquire the query statement to be executed;
[0142] The generation module 402 is used to generate candidate execution plans for the query statement;
[0143] The first determining module 403 is used to determine, for each candidate execution plan, the join operations required when executing the query operation of the query statement according to the candidate execution plan, wherein the join operations are used to connect the data tables to be queried by the query statement;
[0144] Selection module 404 is used to select the target predicate statement from the connection predicate statements involved in each connection operation for each connection operation;
[0145] The second determining module 405 is used to determine, for each data column involved in the target predicate statement, the data column in each data column involved in each connecting predicate statement that has the same data as the data in the data column, as the equivalent data column corresponding to the data column, and to determine the number of different data in the data column based on the preset reference number of different data in each data column in the data column and the equivalent data column corresponding to the data column.
[0146] The estimation module 406 is used to calculate the number of rows in the joined data table obtained after the join operation is performed, based on the number of different data in each data column involved in the target predicate statement, and use this as the estimated number of rows corresponding to the join operation;
[0147] The execution module 407 is used to select a target execution plan from the candidate execution plans based on the estimated number of rows corresponding to each join operation in each candidate execution plan, and execute the query operation corresponding to the query statement according to the target execution plan.
[0148] Optionally, the selection module 404 is specifically configured to: for each join operation, determine each join predicate statement involved in the join operation as a candidate join predicate statement; take at least one data column with the same data among the data columns involved in each candidate join predicate statement as a data column set corresponding to the join operation; for each data column set, determine the data table set corresponding to the data column set according to the data table to which each data column in the data column set belongs; determine whether there is an intersection among the data table sets corresponding to the data column set containing data columns of the first type, where the first type of data columns refers to data columns in the data tables not joined in the join operation; if so, arbitrarily select one data table from each data table in the intersection as the target data table, and select the join predicate statement whose data columns involved in the join operation belong to the data columns of the target data table as the target predicate statement.
[0149] Optionally, the selection module 404 is further configured to determine whether the connection predicate statement is equivalent to the target predicate statement for each connection predicate statement involved in the connection operation; if not, then the connection predicate statement is also used as the target predicate statement.
[0150] Optionally, the selection module 404 is specifically used to obtain a preset reference number of different data in the data column for each data column in the data column and each data column of the corresponding equal value data column; and select the reference number with the smallest value from each obtained reference number as the number of different data in the data column.
[0151] Optionally, the second determining module 405 is specifically used to: if the number of target predicate statements is one, determine the join selectivity corresponding to the join operation based on the number of different data in each data column involved in the target predicate statement; and determine the number of rows in the joined data table obtained after performing the join operation based on the number of rows in each data table to be joined by the join operation and the join selectivity.
[0152] Optionally, the second determining module 405 is further configured to: if the number of target predicate statements is greater than one, divide the data columns into a first set and a second set according to whether the type of each data column involved in each target predicate statement is a first type, wherein the data columns of the first type refer to the data columns in the data tables not being joined in the join operation; determine the number of different data in each data column in the first set according to the number of different data in each data column in the first set; determine the number of different data in each data column in the second set according to the number of different data in each data column in the second set; determine the join selectivity corresponding to the join operation according to the number of different data in each data column in the first set and the number of different data in each data column in the second set; and determine the number of rows in the joined data table obtained after performing the join operation according to the number of rows in each data table to be joined by the join operation and the join selectivity.
[0153] Optionally, the estimation module 406 is specifically used to determine whether each data column in the first set belongs to the same data table; if so, it determines the number of different data in each data column in the first set based on the correlation between each data column in the first set; if not, it determines the number of different data in each data column in the first set based on the number of different data in each data column in the first set.
[0154] Optionally, the estimation module 406 is specifically used to determine whether each data column in the second set belongs to the same data table; if so, it determines the number of different data in each data column in the second set based on the correlation between each data column in the second set; if not, it determines the number of different data in each data column in the second set based on the number of different data in each data column in the second set.
[0155] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 This provides a method for executing query statements.
[0156] This instruction manual also provides Figure 5 The one shown corresponds to Figure 1 A schematic diagram of the structure of an electronic device. (e.g.) Figure 5 At the hardware level, this electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then executes it to achieve the above. Figure 1The method for executing the query statement. 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.
[0157] 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 also 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 also 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.
[0158] 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: ARC 625D, 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, application-specific integrated circuits, 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.
[0159] 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.
[0160] 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 components.
[0161] Those skilled in the art will understand that 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.
[0162] This specification is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this specification. 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.
[0163] 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.
[0164] 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.
[0165] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0166] 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.
[0167] 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.
[0168] 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 process, method, article, or apparatus. Unless otherwise specified, 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 that element.
[0169] 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.
[0170] 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.
[0171] 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.
[0172] The above are merely embodiments of this specification and are 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 executing a query statement, comprising: Retrieve the query statement to be executed; Generate candidate execution plans for the query statement; For each candidate execution plan, determine the join operations required to execute the query operation of the query statement according to the candidate execution plan. The join operations are used to connect the data tables to be queried by the query statement. For each join operation, select the target predicate statement from the join predicate statements involved in that join operation; For each data column involved in the target predicate statement, determine the data column in each data column involved in each connect predicate statement that has the same data as the data in that data column, and take it as the corresponding equivalent data column. Then, determine the number of different data in the data column based on the preset reference number of different data in each data column in the data column and the corresponding equivalent data column. Based on the number of different data in each data column involved in the target predicate statement, calculate the number of rows in the joined data table obtained after performing the join operation, and use it as the estimated number of rows corresponding to the join operation; Based on the estimated number of rows corresponding to each join operation in each candidate execution plan, a target execution plan is selected from the candidate execution plans, and the query operation corresponding to the query statement is executed according to the target execution plan.
2. The method as described in claim 1, wherein for each join operation, a target predicate statement is selected from each join predicate statement involved in the join operation, specifically including: For each join operation, determine each join predicate statement involved in the join operation as a candidate join predicate statement; Among the data columns involved in each candidate join predicate statement, at least one data column with the same data is taken as a set of data columns corresponding to the join operation; For each set of data columns, determine the set of data tables corresponding to that set of data columns based on the data tables to which each data column in that set belongs; Determine whether there is an intersection between the data table set corresponding to the data column set containing the first type of data column, where the first type of data column refers to the data column in the data table that is not joined in the join operation; If so, then arbitrarily select one data table from each data table in the intersection as the target data table, and select the connection predicate statement whose data column is the data column of the target data table from each connection predicate statement involved in the connection operation as the target predicate statement.
3. The method of claim 2, further comprising: For each join predicate statement involved in the join operation, determine whether the join predicate statement is equivalent to the target predicate statement; If not, then the connecting predicate statement is also used as the target predicate statement.
4. The method as described in claim 1, wherein determining the number of different data in the data column based on a preset data column and a reference number of different data in each data column of each equivalent data column corresponding to the data column, specifically includes: For each data column in the data column and each corresponding equal-value data column, obtain the preset reference number of different data in the data column; From each of the obtained reference quantities, select the reference quantity with the smallest value as the number of different data in that data column.
5. The method as described in claim 1, wherein the number of rows in the joined data table obtained after performing the join operation is calculated based on the number of different data in each data column involved in the target predicate statement, specifically including: If the number of target predicate statements is one, then the join selectivity corresponding to the join operation is determined based on the number of different data in each data column involved in the target predicate statement; The number of rows in the resulting connected data table is determined based on the number of rows in each data table that the join operation needs to connect and the join selectivity.
6. The method of claim 5, further comprising: If the number of target predicate statements is greater than one, then according to whether the data column involved in each target predicate statement belongs to the first type, the data columns are divided into a first set and a second set. The data columns of the first type refer to the data columns in the data table that are not joined in the join operation. The number of different data in each data column of the first set is determined based on the number of different data in each data column of the first set; as well as The number of different data in each data column of the second set is determined based on the number of different data in each data column of the second set; The join selectivity corresponding to the join operation is determined based on the number of different data in each data column of the first set and the number of different data in each data column of the second set. The number of rows in the resulting connected data table is determined based on the number of rows in each data table that the join operation needs to connect and the join selectivity.
7. The method as described in claim 6, wherein determining the number of different data in each data column of the first set based on the number of different data in each data column of the first set specifically includes: Determine whether each data column in the first set belongs to the same data table; If so, then based on the correlation between each data column in the first set, determine the number of different data in each data column in the first set; If not, then determine the number of different data in each data column of the first set based on the number of different data in each data column of the first set.
8. The method as described in claim 6, wherein determining the number of different data in each data column of the second set based on the number of different data in each data column of the second set specifically includes: Determine whether each data column in the second set belongs to the same data table; If so, then determine the number of different data in each data column of the second set based on the correlation between each data column in the second set; If not, then determine the number of different data in each data column of the second set based on the number of different data in each data column of the second set.
9. A device for executing a query statement, comprising: The retrieval module is used to retrieve the query statements to be executed. A generation module is used to generate candidate execution plans for the query statement; The first determining module is used to determine, for each candidate execution plan, the join operations required when executing the query operation of the query statement according to the candidate execution plan, wherein the join operations are used to connect the data tables to be queried by the query statement; The selection module is used to select the target predicate statement from the various join predicate statements involved in each join operation. The second determining module is used to determine, for each data column involved in the target predicate statement, the data column in each data column involved in each connecting predicate statement that has the same data as the data in the data column, as the corresponding equivalent data column, and to determine the number of different data in the data column based on the preset reference number of different data in each data column in the data column and the corresponding equivalent data column. The estimation module is used to calculate the number of rows in the joined data table obtained after the join operation is performed, based on the number of different data in each data column involved in the target predicate statement, and use this as the estimated number of rows corresponding to the join operation. The execution module is used to select a target execution plan from the candidate execution plans based on the estimated number of rows corresponding to each join operation in each candidate execution plan, and execute the query operation corresponding to the query statement according to the target execution plan.
10. The apparatus of claim 9, wherein the selection module is specifically configured to: for each join operation, determine each join predicate statement involved in the join operation as a candidate join predicate statement; take at least one data column with the same data among the data columns involved in each candidate join predicate statement as a data column set corresponding to the join operation; for each data column set, determine a data table set corresponding to the data column set according to the data table to which each data column in the data column set belongs; determine whether there is an intersection among the data table sets corresponding to the data column set containing data columns of a first type, wherein the first type of data column refers to the data column in the data table not joined in the join operation; if so, arbitrarily select one data table from each data table in the intersection as the target data table, and select the join predicate statement whose data column involved in the join operation is the data column to which the target data table belongs as the target predicate statement.
11. The apparatus of claim 10, wherein the selection module is further configured to, for each connection predicate statement involved in the connection operation, determine whether the connection predicate statement is equivalent to the target predicate statement; if not, then also use the connection predicate statement as the target predicate statement.
12. The apparatus of claim 9, wherein the selection module is specifically configured to: for each data column in the data column and each corresponding equal-value data column, obtain a preset reference number of different data in the data column; and select the reference number with the smallest value from each obtained reference number as the number of different data in the data column.
13. The apparatus of claim 9, wherein the second determining module is specifically configured to: if the number of the target predicate statements is one, determine the join selectivity corresponding to the join operation based on the number of different data in each data column involved in the target predicate statements; and determine the number of rows in the joined data table obtained after performing the join operation based on the number of rows in each data table to be joined by the join operation and the join selectivity.
14. The apparatus of claim 13, wherein the second determining module is further configured to: if the number of target predicate statements is greater than one, divide each data column into a first set and a second set according to whether the type of each data column involved in each target predicate statement is a first type, wherein the data column of the first type refers to the data column in the data table not being joined in the join operation; determine the number of different data in each data column in the first set according to the number of different data in each data column in the first set; and determine the number of different data in each data column in the second set according to the number of different data in each data column in the second set; determine the join selectivity corresponding to the join operation according to the number of different data in each data column in the first set and the number of different data in each data column in the second set; and determine the number of rows in the joined data table obtained after performing the join operation according to the number of rows in each data table to be joined by the join operation and the join selectivity.
15. The apparatus of claim 14, wherein the estimation module is specifically configured to: determine whether each data column in the first set belongs to the same data table; if so, determine the number of different data in each data column in the first set based on the correlation between each data column in the first set; if not, determine the number of different data in each data column in the first set based on the number of different data in each data column in the first set.
16. The apparatus of claim 14, wherein the estimation module is specifically configured to: determine whether each data column in the second set belongs to the same data table; if so, determine the number of different data in each data column in the second set based on the correlation between each data column in the second set; if not, determine the number of different data in each data column in the second set based on the number of different data in each data column in the second set.
17. 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 8.
18. 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 8.
Citation Information
Patent Citations
Data query method and device, electronic equipment and computer readable storage medium
CN112069164A
Data management method and device of semitransparent encrypted column, equipment and storage medium
CN114996734A