WO2017140085A1 - 一种sql执行计划的确定方法及装置 - Google Patents

一种sql执行计划的确定方法及装置 Download PDF

Info

Publication number
WO2017140085A1
WO2017140085A1 PCT/CN2016/090222 CN2016090222W WO2017140085A1 WO 2017140085 A1 WO2017140085 A1 WO 2017140085A1 CN 2016090222 W CN2016090222 W CN 2016090222W WO 2017140085 A1 WO2017140085 A1 WO 2017140085A1
Authority
WO
WIPO (PCT)
Prior art keywords
plan
iteration
tree
plan tree
iteration parameter
Prior art date
Application number
PCT/CN2016/090222
Other languages
English (en)
French (fr)
Inventor
刘辉军
任阳
李茂增
韩峰
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to JP2017518519A priority Critical patent/JP6415708B2/ja
Priority to EP16840285.7A priority patent/EP3232339B1/en
Priority to RU2017113685A priority patent/RU2674886C2/ru
Priority to US15/495,569 priority patent/US10901976B2/en
Publication of WO2017140085A1 publication Critical patent/WO2017140085A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/235Update request formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • G06F16/24534Query rewriting; Transformation
    • G06F16/24542Plan optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • G06F16/24534Query rewriting; Transformation
    • G06F16/24542Plan optimisation
    • G06F16/24544Join order optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • G06F16/24534Query rewriting; Transformation
    • G06F16/24542Plan optimisation
    • G06F16/24545Selectivity estimation or determination

Definitions

  • the present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for determining a SQL execution plan.
  • SQL Structured Query Language
  • a SQL statement indicates the result that the user wants to obtain, for example, querying all customers living in Beijing, but the SQL statement does not tell the server how to execute, so when the server receives a Query command
  • a Parse Tree is formed.
  • the server searches for relevant statistical information in the database, and combines Parse Tree to determine the preferred SQL statement.
  • SQL execution plan can be obtained in the form of a Plan Tree.
  • Each node on a Plan Tree consists of several basic operations, such as traversing multiple tables, performing a nested connection or a hash connection. Basic operation, finally, the server executes the SQL execution plan according to the obtained Plan Tree, and the output result is the result represented by the SQL statement.
  • the execution efficiency of the SQL statement depends to some extent on whether an efficient SQL execution plan can be determined.
  • the statistical information in the database is usually a feature value obtained based on the sampled value. For example, the number of tuples in a relational table (RelTuples), the number of unique non-null values in a field in a relational table (Distinct value) and other eigenvalues, the eigenvalues obtained by these samples usually have some error, and have hysteresis in time. Therefore, the SQL execution plan determined by the server based on the above statistical information is usually not the optimal execution plan.
  • Embodiments of the present invention provide a method and apparatus for determining a SQL execution plan, which can optimize the determination of the SQL execution plan and improve the execution efficiency of the SQL execution plan.
  • a first aspect of the embodiments of the present invention provides a method for determining a structured query language SQL execution plan, where the SQL execution plan corresponds to at least one relationship table, and in the Nth iteration, the method includes: obtaining the N-1th iteration a first iteration parameter generated after executing the first plan tree on the at least one relationship table, wherein N is a natural number greater than 1; establishing a second plan tree according to the first iteration parameter; when the second plan tree and the first When the difference of the plan tree is not greater than the first threshold, the first plan tree or the second plan tree is determined as the SQL execution plan.
  • the first threshold is 0, and correspondingly, when the difference between the second plan tree and the first plan tree is not greater than the first threshold, Determining the first plan tree or the second plan tree as the SQL execution plan, comprising: when the second plan tree is the same as the first plan tree, determining the first plan tree or the second plan tree as The SQL execution plan.
  • the embodiment of the present invention obtains an optimized SQL execution plan by means of iterative execution.
  • it is necessary to compare the plan tree established in the previous iteration process (collectively referred to as the first plan tree in the embodiment of the present invention) and the plan tree established in the current iterative process (in the embodiment of the present invention It is a second plan tree), and the second plan tree is established based on the updated iteration parameter (collectively referred to as the first iteration parameter in the embodiment of the present invention), that is, each time
  • the second plan tree established in the iterative process is established based on the first iteration parameter updated after executing the first plan tree.
  • the final plan tree is not dependent on the statistics in the database. Estimate the iteration parameters, but rely on the iteration parameters recorded during each actual execution of the plan tree in the iterative process. According to the establishment of the plan tree, thereby obtaining a more accurate SQL execution plan of the SQL statement, and improving the execution efficiency of the SQL execution plan.
  • the first iteration parameter includes any one or more relationship tables corresponding to the SQL execution plan. The number of tuples.
  • the first execution parameter is when the SQL execution plan corresponds to the at least two relationship tables The number of tuples in the result set obtained by the connection operation of any one or more of the at least two relation tables is further included.
  • the method further includes: recording the SQL execution plan to determine the status.
  • the method further includes: executing the second plan tree; and recording a second iteration parameter generated when the second plan tree is executed.
  • the beneficial effect obtained by the embodiment of the present invention is that, since the updated first iteration parameter is obtained when the second plan tree is actually executed, the second plan tree established by using the updated first iteration parameter is more accurate.
  • the second iteration parameter includes a tuple number of any one or more relationship tables corresponding to the SQL execution plan .
  • the second iteration parameter when the SQL execution plan corresponds to the at least two relationship tables, the second iteration parameter further includes the at least The number of tuples in the result set obtained by any one or more of the two relational tables after the connection operation.
  • the method further includes: when the second plan tree and the When the difference of the first plan tree is greater than the first threshold, updating the first iteration parameter according to the second iteration parameter; using the second plan tree in the Nth iteration as the first plan tree in the N+1th iteration .
  • the method before the updating the first iteration parameter according to the second iteration parameter, the method further includes: when the second When the iteration parameter is the same as the first iteration parameter, a second plan tree different from the first plan tree is established according to the first iteration parameter.
  • a tenth possible implementation manner of the first aspect after the second plan tree that is different from the first plan tree is established according to the first iteration parameter And further comprising: recording an execution time of executing the second plan tree; when the N is greater than the second threshold, using the second plan tree with the shortest execution time among all N iterations as the SQL execution plan.
  • the second plan tree with the shortest execution time in the all N iterations is used as the SQL execution plan After that, it also includes: recording the SQL execution plan to determine the status.
  • the method before the updating the first iteration parameter according to the second iteration parameter, the method further includes: performing the recording The execution time of the second plan tree; when the N is greater than the third threshold, the second plan tree with the shortest execution time among all N iterations is taken as the SQL execution plan.
  • the second plan tree with the shortest execution time in the all N iterations is executed as the SQL After the plan, it also includes: recording the SQL execution plan to determine the status.
  • the beneficial effect obtained by the embodiment of the present invention is that for those SQL execution plans that have mutated during the iteration process, it is possible to never iterate out the same plan tree as the last established plan tree, so in order to avoid unrestricted
  • the infinite loop can be considered to be executed during the N iterations that have elapsed after the number of iterations N is greater than the threshold.
  • the second plan tree with the shortest time is the optimal plan tree, and then the second plan tree is used as the SQL execution plan.
  • the updating the first iteration parameter according to the second iteration parameter includes: The second iteration parameter and the first iteration parameter are taken as a union, and the result of the union is taken as the first iteration parameter.
  • the method further includes: when the initial iteration is performed, according to the foregoing
  • the stored estimated iteration parameter establishes an initial plan tree; the initial plan tree is executed to obtain an initial iteration parameter; and the estimated iteration parameter is updated according to the initial iteration parameter to obtain the first iteration parameter.
  • the estimating iteration parameter includes a tuple of any one or more relationship tables corresponding to the SQL execution plan number.
  • the initial iteration parameter includes any one or more corresponding to the SQL execution plan The number of tuples in the relational table.
  • the initial execution parameter when the SQL execution plan corresponds to the at least two relational tables The number of tuples in the result set obtained by the connection operation of any one or more of the at least two relation tables is further included.
  • the estimating the iteration parameter is updated according to the initial iteration parameter, to obtain the first
  • the iterative parameter includes: combining the initial iteration parameter and the estimated iteration parameter, and using the result of the union as the first iteration parameter.
  • the method before the initial iteration is performed, the method further includes: querying the SQL execution plan Whether the state is the determined state; when the state of the SQL execution plan is the determined state, the SQL execution plan is executed.
  • the beneficial effects obtained by the embodiment of the present invention are that, after the server has stored the optimized SQL execution plan, when the execution is required to be performed again, the determination of the SQL execution plan does not need to be repeated, thereby improving the execution efficiency of the server.
  • the SQL execution plan further includes a filtering condition, when the SQL
  • the first iteration parameter includes the number of tuples in the one or more relationship tables corresponding to the SQL execution plan that meet the filtering condition.
  • the first iteration parameter further includes: the SQL The number of unique non-null values in a field in any relation table corresponding to the execution plan, and/or the set of columns (MCV) in the relationship table that the number of occurrences exceeds the second threshold.
  • the beneficial effect obtained by the embodiment of the present invention is that the second plan tree obtained in the embodiment of the present invention does not depend on the estimated iteration parameter in the database, but is based on the updated first iteration parameter in the iterative process. Established, and then when the second plan tree is the same as the first plan tree, the second plan tree is used as the SQL execution plan, which can accurately determine the SQL execution plan and improve the execution efficiency of the SQL execution plan.
  • a second aspect of an embodiment of the present invention provides a determining apparatus for a structured query language SQL execution plan, the SQL execution plan corresponding to at least one relation table, the device comprising a memory and a processor coupled to the memory, at the Nth And the first iteration parameter generated after the execution of the first plan tree in the N-1th iteration, wherein N is a natural number greater than 1;
  • An iterative parameter establishes a second plan tree; when the difference between the second plan tree and the first plan tree is not greater than a first threshold, determining the first plan tree or the second plan tree as the SQL execution plan.
  • the first threshold is 0, and correspondingly, the processor is configured to use the second plan tree and the first plan When the tree is the same, the first plan tree or the second plan tree is determined as the SQL execution plan.
  • the first iteration parameter includes any one or more relationship tables corresponding to the SQL execution plan The number of tuples.
  • the first iteration parameter when the SQL execution plan corresponds to the at least two relationship tables, the first iteration parameter The number of tuples in the result set obtained by the connection operation of any one or more of the at least two relation tables is further included.
  • the processor is also used to: record the SQL execution plan to determine the status.
  • the processor is further configured to: execute the second plan tree; record a second iteration parameter generated when the second plan tree is executed.
  • the second iteration parameter includes a tuple number of any one or more relationship tables corresponding to the SQL execution plan .
  • the second execution parameter further includes the at least two relational tables when the SQL execution plan corresponds to the at least two relationship tables The number of tuples in the result set obtained by any one or more of the two relational tables after the connection operation.
  • the processor is further configured to: when the second plan tree and the first plan tree When the difference is greater than the first threshold, the first iteration parameter is updated according to the second iteration parameter; the second plan tree in the Nth iteration is taken as the first plan tree in the N+1th iteration.
  • the processor before updating the first iteration parameter according to the second iteration parameter, is further configured to: when the second iteration parameter is the same as the first iteration parameter, according to the first iteration parameter A second plan tree is created that is different from the first plan tree.
  • the processor is further configured to: record execution time of executing the second plan tree; when the N is greater than the second threshold, use the second plan tree with the shortest execution time among all N iterations as the SQL execution plan.
  • the processor is further configured to: record the SQL execution plan to determine the status.
  • the processor is further configured to: before the updating the first iteration parameter according to the second iteration parameter Recording the execution time of executing the second plan tree; when the N is greater than the third threshold, the second plan tree having the shortest execution time among all N iterations is taken as the SQL execution plan.
  • the second plan tree with the shortest execution time in the all N iterations is executed as the SQL After the plan, the processor is also used to: record the SQL execution plan to determine the status.
  • the processor is specifically configured to: the second iteration parameter and the first The iterative parameters take the union, and the result of the union is taken as the first iteration parameter.
  • the processor is further configured to: when the initial iteration is performed, Establishing an initial planning tree according to the pre-stored estimated iteration parameter; executing the initial planning tree to obtain an initial iteration parameter; updating the initial iteration parameter according to the initial iteration parameter The iteration parameters are estimated to obtain the first iteration parameter.
  • the estimating iteration parameter includes a tuple of any one or more relationship tables corresponding to the SQL execution plan number.
  • the initial iteration parameter includes any one or more corresponding to the SQL execution plan The number of tuples in the relational table.
  • the initial iteration parameter when the SQL execution plan corresponds to the at least two relational tables, the initial iteration parameter The number of tuples in the result set obtained by the connection operation of any one or more of the at least two relation tables is further included.
  • the processor is specifically configured to: the initial iteration parameter and the estimation iteration
  • the parameter takes the union and uses the result of the union as the first iteration parameter.
  • the processor before the initial iteration is executed, is further configured to: query the Whether the state of the SQL execution plan is the determined state; when the state of the SQL execution plan is the determined state, the SQL execution plan is executed.
  • the SQL execution plan further includes a filtering condition, when the SQL
  • the first iteration parameter includes the number of tuples in the one or more relationship tables corresponding to the SQL execution plan that meet the filtering condition.
  • the first iteration parameter further includes: the SQL The number of unique non-null values in a field in any relation table corresponding to the execution plan, and/or the set of columns (MCV) in the relationship table that the number of occurrences exceeds the second threshold.
  • a third aspect of the embodiments of the present invention provides a determining apparatus for a structured query language SQL execution plan, where the SQL execution plan corresponds to at least one relationship table, and the apparatus includes an obtaining unit, an establishing unit, and a determining unit, at the Nth time
  • the acquiring unit is configured to acquire a first iteration parameter generated after executing the first plan tree on the at least one relationship table in the N-1th iteration, where N is a natural number greater than 1;
  • Establishing a second plan tree according to the first iteration parameter; the determining unit is configured to: when the difference between the second plan tree and the first plan tree is not greater than a first threshold, the first plan tree or the second plan The tree is determined to execute the plan for the SQL.
  • the first threshold is 0, and correspondingly, the determining unit is specifically configured to: when the second plan tree is the same as the first plan tree, The first plan tree or the second plan tree is determined as the SQL execution plan.
  • the first iteration parameter includes any one or more relationship tables corresponding to the SQL execution plan. The number of tuples.
  • the first iteration parameter when the SQL execution plan corresponds to the at least two relationship tables, the first iteration parameter The number of tuples in the result set obtained by the connection operation of any one or more of the at least two relation tables is further included.
  • the device further includes a recording unit for recording the SQL execution plan to determine the status.
  • the apparatus further includes an execution unit for executing the second plan tree; the record unit is further configured to record a second iteration parameter generated when the second plan tree is executed.
  • the second iteration parameter includes the number of tuples of any one or more relationship tables corresponding to the SQL execution plan .
  • the second iteration parameter when the SQL execution plan corresponds to the at least two relationship tables, the second iteration parameter further includes the at least The number of tuples in the result set obtained by any one or more of the two relational tables after the connection operation.
  • the apparatus further includes an update unit, configured to: when the second plan tree and the first When the difference of the plan tree is greater than the first threshold, the first iteration parameter is updated according to the second iteration parameter; the second plan tree in the Nth iteration is used as the first plan tree in the N+1th iteration.
  • the establishing unit before the updating the first iteration parameter according to the second iteration parameter, is further configured to: When the second iteration parameter is the same as the first iteration parameter, a second plan tree different from the first plan tree is established according to the first iteration parameter.
  • the recording unit is further configured to record an execution time of executing the second plan tree; the determining unit is further configured to: when the N is greater than the second threshold, use the second plan tree with the shortest execution time among all N iterations as the SQL execution plan.
  • the recording unit is further configured to: record the SQL execution plan to determine a state.
  • the recording unit is further configured to: before the first iteration parameter is updated according to the second iteration parameter : recording the execution time of executing the second plan tree;
  • the determining unit is further configured to use, as the SQL execution plan, the second plan tree with the shortest execution time among all N iterations when the N is greater than the third threshold.
  • the second plan tree with the shortest execution time in the all N iterations is executed as the SQL After the plan, the recording unit is further used to: record the SQL execution plan to determine the status.
  • the updating unit is specifically configured to: the second iteration parameter and the first The iterative parameters take the union, and the result of the union is taken as the first iteration parameter.
  • the establishing unit is further configured to perform, when the initial iteration is performed, The pre-stored estimated iteration parameter establishes an initial plan tree; the execution unit is further configured to execute the initial plan tree to obtain an initial iteration parameter; the update unit is further configured to update the estimated iteration parameter according to the initial iteration parameter to obtain the first iteration parameter .
  • the estimating iteration parameter includes a tuple of any one or more relationship tables corresponding to the SQL execution plan number.
  • the initial iteration parameter includes any one or more corresponding to the SQL execution plan The number of tuples in the relational table.
  • the initial execution parameter when the SQL execution plan corresponds to the at least two relational tables The number of tuples in the result set obtained by the connection operation of any one or more of the at least two relation tables is further included.
  • the updating unit is specifically configured to: the initial iteration parameter and the estimation iteration The parameter is taken as a union, and the result of the union is taken as the first Iteration parameters.
  • the apparatus before the initial iteration, further includes a query unit, where Querying whether the state of the SQL execution plan is the determined state; the determining unit is further configured to execute the SQL execution plan when the state of the SQL execution plan is the determined state.
  • the SQL execution plan further includes a filtering condition, when the SQL
  • the first iteration parameter includes the number of tuples in the one or more relationship tables corresponding to the SQL execution plan that meet the filtering condition.
  • the first iteration parameter further includes: the SQL The number of unique non-null values in a field in any relation table corresponding to the execution plan, and/or the set of columns (MCV) in the relationship table that the number of occurrences exceeds the second threshold.
  • a device for determining a Structured Query Language (SQL) execution plan comprising: a processor, a memory, a bus, and a communication interface; the memory is configured to store a computer execution instruction, the processor and the processor The memory is connected by the bus, and when the determining device is in operation, the processor executes the computer-executed instructions stored in the memory to cause the determining device to perform the first aspect of the first aspect of the first aspect of the present invention
  • SQL Structured Query Language
  • a computer storage medium for storing computer software instructions for determining a SQL execution plan described in the fourth aspect, comprising determining means for executing the SQL execution plan of the fourth aspect Designed program.
  • the name of the determining device of the SQL execution plan is not limited to the device itself, and in actual implementation, these devices may appear under other names. As long as the functions of the respective devices are similar to the present invention, they fall within the scope of the claims of the present invention and their equivalents. within.
  • FIG. 1 is a schematic flowchart of a method for determining a SQL execution plan according to an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of a method for determining another SQL execution plan according to an embodiment of the present invention
  • FIG. 3 is a schematic flowchart of a method for determining another SQL execution plan according to an embodiment of the present invention
  • FIG. 4 is a schematic structural diagram of an apparatus for determining an execution plan of an SQL according to an embodiment of the present invention
  • FIG. 5 is a schematic structural diagram of another apparatus for determining an execution plan of an SQL according to an embodiment of the present disclosure
  • FIG. 6 is a schematic structural diagram of another apparatus for determining a SQL execution plan according to an embodiment of the present invention.
  • FIG. 7 is a schematic structural diagram of another apparatus for determining a SQL execution plan according to an embodiment of the present disclosure.
  • FIG. 8 is a schematic structural diagram of a computer device according to an embodiment of the present invention.
  • first and second are used for descriptive purposes only, and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, features defining “first” and “second” may include one explicitly or implicitly. Or more of this feature. In the description of the present invention, “a plurality” means two or more unless otherwise stated.
  • a method for determining a SQL execution plan provided by an embodiment of the present invention may be specifically applied to a SQL execution plan determination stage.
  • the core principle of the solution is to use an iterative method to establish an iterative parameter generated each time the plan tree is actually executed. Plan the tree for the optimal SQL execution plan.
  • the plan tree is directly established according to the estimated iteration parameter pre-stored in the database (ie, the feature value obtained by using the sampling or estimation method), and The plan tree is used as the SQL execution plan, but the estimated iteration parameters may not be accurate, which leads to the inaccurate SQL execution plan.
  • the iterative method may be used to cyclically establish and execute a plan tree, and the iteration parameters generated in the process of actually executing the plan tree are recorded to update.
  • each iteration process it is necessary to compare the plan tree established in the previous iteration process (collectively referred to as the first plan tree in the embodiment of the present invention) and the plan tree established in the current iterative process (in the embodiment of the present invention It is a second plan tree), and the second plan tree is established based on the updated iteration parameter (collectively referred to as the first iteration parameter in the embodiment of the present invention), that is, each time
  • the second plan tree established in the iterative process is established based on the first iteration parameter updated after executing the first plan tree.
  • the final plan tree is not dependent on the statistics in the database. Estimating the iterative parameters, but based on the iterative parameters recorded during each actual execution of the plan tree in the iterative process, the plan tree is established, thereby obtaining a more accurate SQL execution plan and improving the execution efficiency of the SQL execution plan.
  • the plan tree established at the N-1th iteration is the second plan tree, where N is a natural number greater than 1.
  • the SQL execution plan corresponds to at least one relationship table in the database, and it is possible to set the SQL execution plan to correspond to M relationship tables, where M is a natural number greater than 1.
  • the first iteration parameter may specifically include at least one of the first feature value and/or the second feature value, that is, the first feature value and the second feature value.
  • the first feature value is used to indicate the number of tuples of any one or more relation tables corresponding to the SQL execution plan
  • the second feature value is used to indicate that the SQL execution plan corresponds to the at least two relationship tables, the at least two relationships
  • N (i) is used to represent the first feature value
  • N (i, j, k) is used to represent the second feature value.
  • N (i) is the number of tuples of the i-th relational table
  • N (i, j, k) is a connection operation in the order of the i-th relational table, the j-th relational table, and the k-th relational table ( That is, the number of tuples in the result set after join.
  • the server executing the SQL execution plan may further include determining a filtering condition of the SQL execution plan.
  • the filtering condition is that all the boys in the relationship table are greater than 180 cm in height, and then, the first characteristic value may be further used. Indicates the number of tuples that match the filter condition in the i-th relationship table.
  • the second iteration parameter involved in the embodiment of the present invention specifically includes the first feature value and/or the second feature value, except that the first iteration parameter refers to an iteration updated at the N-1th iteration.
  • the parameter of the second iteration parameter refers to the iteration parameter generated when the second plan tree is executed at the Nth iteration. The manner of updating the first iteration parameter will be specifically described in the embodiment of the present invention.
  • the feature value may further include: a number of unique non-null values in one field in the relation table (ie, Distinct value), and/or a set of columns in the relationship table that exceed the second threshold (ie, MCV, most common Value).
  • the variation may be represented by a Variation in the embodiment of the present invention. Specifically, if the second plan tree established at the Nth iteration is the first established with the N-1th iteration, The plan tree is different, but the second iteration parameter generated when the second plan tree is executed is the same as the first iteration parameter generated when the first plan tree is executed, and the current SQL execution plan needs to be mutated to obtain further Better SQL execution plan.
  • the embodiment of the present invention provides a method for determining a SQL execution plan. Since the second to last iterations are the same in the iterative process, the Nth iteration process is taken as an example. , the method includes:
  • the Nth iteration Since the plan tree established during each iteration and the first iteration parameter generated at the end of the iterative process can be saved, in the Nth iteration, the N-1th iteration can be acquired.
  • the second plan tree can be established according to the first iteration parameter obtained when the first iteration is completed.
  • step 103 the second plan tree established in step 102 is executed, and the second iteration parameter generated when the second plan tree is executed is recorded.
  • the second iteration parameter also includes N (i) and / or N (i, j, k) .
  • step 104 compares whether the second plan tree established at the Nth iteration is the same as the first plan tree established at the N-1th iteration.
  • step 104 further includes comparing whether the second plan tree established at the Nth iteration and the first plan tree established at the N-1th iteration are not greater than a threshold, and the threshold may be preset or trained.
  • the fixed value can also be a dynamic value that is constantly updated in the system and is not limited.
  • the execution steps of the second plan tree and the first plan tree can be compared Whether the difference step is not more than one step, or whether the difference step of the execution steps of the second plan tree and the first plan tree is not more than 99%, etc., is not limited.
  • the subsequent steps involved in comparing whether the first plan tree and the second plan tree are the same or similar expressions are consistent with step 104, and are not described again.
  • the threshold is not 0.
  • the resulting SQL execution plan is a sub-optimal execution plan, but it should be understood that the sub-optimal execution plan determination process saves computing time and resources compared to the optimal execution plan determination process, in some implementations. For example, in an application scenario where computing time and resource requirements are high, a sub-optimal execution plan is adopted.
  • the second iteration parameter is used to update the first iteration parameter.
  • the first eigenvalue and/or the second eigenvalue that are different from the first iteration parameter may be added to the first iteration parameter, that is, the first iteration parameter and the second iteration parameter are taken together.
  • the set obtains the updated first iteration parameter, so that in the N+1 iterations, the second iteration parameter is re-established using the updated first iteration parameter, since the updated first iteration parameter is the actual execution
  • the second plan tree generated in the iterative process is used as the first plan tree in the next iteration process until the second plan tree is established in a certain iteration process and the first plan tree established in the last iteration process. The same.
  • the number of iterations can be set to be incremented by one in order to repeatedly perform the above steps 101-106.
  • the second plan tree established at the Nth iteration is the same as the first plan tree established at the N-1th iteration, the second plan tree is used as the SQL execution plan.
  • step 107 when the second plan tree established at the Nth iteration is the same as the first plan tree established at the N-1th iteration, it is indicated that after the N iterations, the first iteration parameter is All the first eigenvalues and the second eigenvalues are already included. Therefore, when the second plan tree established according to the first iteration parameter has been optimized, the second plan tree can be used as the SQL execution plan.
  • the correspondence between the second plan tree and the SQL statement related to executing the second plan tree may be saved, and when the SQL statement is received again, the server may directly obtain the first from the corresponding storage unit.
  • step 107 further includes, if the second plan tree established at the Nth iteration and the first plan tree established at the N-1th iteration are not greater than a certain threshold, The second plan tree or the first plan tree is used as the SQL execution plan. It should be understood that in this embodiment, the first plan tree and the second plan tree are both sub-optimal plan trees, and one of them may be selected as the SQL execution plan.
  • step 103, step 105, step 106 are optional steps.
  • the execution time of the second plan tree may be recorded.
  • the number of iterations exceeds a predetermined threshold, that is, the iterative algorithm does not converge within the threshold time, all the iteration cycles are selected.
  • the second plan tree with the shortest execution time described above is used as the SQL execution plan.
  • the state of the SQL execution plan is set to a determined state in the server, that is, the optimized SQL execution plan has been determined.
  • the process of determining the SQL execution plan does not need to be repeated, which improves the execution efficiency of the server.
  • the embodiment of the present invention provides a method for determining a SQL execution plan, as shown in FIG. 2, including:
  • the SQL statement carries the identifier of the relational table corresponding to the SQL execution plan.
  • the received SQL statement is: select count(*)from dba, that is, the row of the dba relational table is searched from the relational table identified as dba. number.
  • the server may repeatedly execute the same SQL statement for a period of time, when the SQL execution plan related to the SQL statement is generated for the first time, the correspondence between the SQL execution plan and the SQL statement may be saved, so that When received again When a SQL statement is obtained, it can be queried whether a SQL execution plan corresponding to the SQL statement is stored, that is, whether the state of the SQL execution plan is a determined state.
  • a variable Optimization can be set to indicate whether a SQL execution plan corresponding to the received SQL statement is stored.
  • optimization ⁇ 1 that is, the state of the SQL execution plan is an indeterminate state, it means that the SQL execution plan corresponding to the received SQL statement is not stored, that is, the SQL statement is executed for the first time. Perform steps 202-213 below.
  • an initial plan tree is established according to the pre-stored estimated iteration parameters.
  • step 202 After the initialization operation in step 202 is completed, the first iteration process is started, at which time an initial plan tree can be established based on the estimated iteration parameters stored in the statistical information.
  • the server may execute the initial plan tree established in step 203, and record the initial iteration parameters generated when the initial plan tree is executed, ie, N (i) and/or N (i) , j, k) , so that the estimated iteration parameters in step 203 can be updated using the initial iteration parameters generated when the initial plan tree is executed.
  • the estimated iteration parameter for establishing the initial plan tree in step 203 specifically includes: N (t1) and N (t2) , and N (t2, t1) , and in step 204, the initial iteration parameter generated when the initial plan tree is executed. It may include N (t1) , N (t2) , and N (t1, t2) . In this case, different iteration parameters in the initial iteration parameter and the estimated iteration parameters may be updated into the estimation iteration parameter, that is, the updated estimation.
  • the iterative parameters are: N (t1) , N (t2) , N (t1, t2), and N (t2, t1) , then the updated estimated iteration parameters are taken as the first iteration parameter above, so as to be in the subsequent N-1
  • the second iteration tree is used in the iterative process to establish a second plan tree.
  • the subsequent second to last iteration process can be referred to the following steps 205-213.
  • the Nth iteration process is taken as an example for exemplary description.
  • the first plan tree established at the N-1th iteration can be obtained during the Nth iteration.
  • the second plan tree is established according to the updated first iteration parameter at the N-1th iteration.
  • the first iteration parameter generated when the first plan tree is executed is different from the second iteration parameter generated when the second plan tree is executed, the first iteration parameter is updated by using the second iteration parameter.
  • the first eigenvalue and/or the second eigenvalue that are different from the first iteration parameter may be added to the first iteration parameter, and the updated first iteration parameter, that is, the first iteration parameter, is obtained.
  • the second iteration parameter is taken as a union, and the union result is taken as the updated first iteration parameter.
  • the second plan tree is established according to the updated first iteration parameter at the N-1th iteration.
  • the second plan tree is established according to the updated first iteration parameter (ie, the first iteration parameter obtained in step 204 above) at the first iteration.
  • a second plan tree different from the first plan tree is established according to the updated first iteration parameter at the N-1th iteration.
  • the second plan tree may be established according to the updated first iteration parameter at the N-1th iteration, but unlike the step 207, the second plan tree is established.
  • the first plan tree established at the N-1th iteration is different.
  • the server may establish a second plan tree according to the first iteration parameter, and the second plan tree at this time is the plan tree that the server considers to be optimal under the limitation of the first iteration parameter, and is not necessarily the actual optimal plan tree.
  • the server may be prohibited from generating a second plan tree (ie, the same second plan tree as the first plan tree) that the server considers to be optimal, and generating another second plan tree different from the first plan tree. .
  • step 209 the second plan tree established in step 207 or 208 is executed, and the second iteration parameter generated when the second plan tree is executed is recorded.
  • the second iteration parameter also includes N (i) and / or N (i, j, k) .
  • the first plan tree established in the first iteration that is, the first plan tree established in the first iteration is the initial plan tree established in step 203.
  • step 212 If the second plan tree established during the Nth iteration is established with the N-1th iteration If the first plan tree is different, compare whether the first iteration parameter generated when the first plan tree is executed is the same as the second iteration parameter generated when the second plan tree is executed, that is, whether the SQL execution plan needs to be mutated, and proceed to step 206. The second plan tree established until the Nth iteration is the same as the first plan tree established at the N-1th iteration, and proceeds to step 212.
  • the second plan tree established at the Nth iteration is the same as the first plan tree established at the N-1th iteration, the second plan tree is used as the SQL execution plan.
  • step 214 when the second plan tree established at the Nth iteration is the same as the first plan tree established at the N-1th iteration, it is indicated that after the N iterations, the first iteration parameter is All of the first feature value and the second feature value are already included. Therefore, when the second plan tree established according to the first iteration parameter has been optimized, the second plan tree can be used as the SQL execution plan.
  • the server can directly obtain the SQL execution plan from the corresponding storage unit.
  • steps 301-303 can also be added, as an example, as shown in FIG. 3:
  • the second plan tree with the shortest execution time in all N iterations is taken as the SQL execution plan.
  • the execution time taken to execute the second plan tree may be recorded.
  • step 302 is performed to determine whether the current number of iterations N is greater than a threshold and whether the SQL execution plan needs to be mutated.
  • step 303 is executed, that is, the second execution time recorded in step 301 is the shortest.
  • the plan tree as the SQL execution plan in step 201.
  • the second plan tree with the shortest execution time is the optimal plan tree, and the second plan tree is used as the SQL execution plan.
  • step 302 if it is determined in step 302 that the current number of iterations N is less than the threshold, and/or, the SQL execution plan does not need to be mutated, at this time, iteratively proceeds according to the above steps 210-212 until the number of iterations N is greater than the threshold. And the SQL execution plan does not need to be mutated.
  • the execution time of the second plan tree is executed at each iteration, for example, the execution time of executing the second plan tree in the Nth iteration is T1, and the execution may be performed during the N-1th iteration.
  • the execution time of the second plan tree is T2 and the size of T1. If T1 is less than T2, the T1 with a shorter execution time and the second plan tree corresponding to the shorter time T1 are saved, so that the saved second plan tree That is, the second plan tree with the shortest execution time in the N iterations process, without recording the execution time of the second plan tree at each iteration, and the corresponding second plan tree to save storage resources.
  • An embodiment of the present invention provides a method for determining a SQL execution plan.
  • the first iteration parameter includes a first feature value and/or a second feature value
  • the first feature value is used to indicate the number of tuples of the i-th relationship table
  • the second feature value is used to indicate that at least two relationship tables are connected after the operation
  • the obtained result sets the number of tuples; then, the second iteration parameter is used to establish a second plan tree; when the second plan tree is the same as the first plan tree, the second plan tree is used as the SQL execution plan.
  • the second plan tree finally obtained in the solution is not dependent on the estimated iteration parameters in the database, but is based on the updated first iteration parameter in the iterative process, and then the second plan tree and the first When the plan tree is the same, the second plan tree is executed as SQL
  • the plan can more accurately determine the SQL execution plan and improve the execution efficiency of the SQL execution plan.
  • FIG. 4 is a schematic structural diagram of an apparatus for determining a SQL execution plan according to an embodiment of the present invention.
  • the apparatus for determining a SQL execution plan according to an embodiment of the present invention may be used to implement the implementations of the present invention shown in FIG. 1 to FIG.
  • FIG. 4 For the convenience of the description, only the parts related to the embodiment of the present invention are shown for the convenience of the description. The specific technical solutions are not described in detail with reference to the embodiments of the present invention shown in FIG.
  • the determining device of the SQL execution plan includes: an obtaining unit 01, an establishing unit 02, and a determining unit 03.
  • the device is used in the Nth iteration,
  • the obtaining unit 01 is configured to acquire a first iteration parameter generated after executing the first plan tree on the at least one relationship table in the N-1th iteration, where N is a natural number greater than 1.
  • the establishing unit 02 is configured to establish a second plan tree according to the first iteration parameter
  • a determining unit 03 configured to determine the first plan tree or the second plan tree as the SQL execution plan when a difference between the second plan tree and the first plan tree is not greater than a first threshold .
  • the first threshold is 0, correspondingly, when the difference between the second plan tree and the first plan tree is not greater than a first threshold, the first plan tree or the Determining, by the second plan tree, the execution plan of the SQL, comprising: determining, when the second plan tree is the same as the first plan tree, the first plan tree or the second plan tree as the SQL Implementation plan.
  • the first iteration parameter includes a tuple number of any one or more relationship tables corresponding to the SQL execution plan.
  • the first iteration parameter when the SQL execution plan corresponds to at least two relationship tables, the first iteration parameter further includes a result obtained by the connection operation of any one or more of the at least two relationship tables The number of tuples in the collection.
  • the device further includes:
  • An execution unit 04 configured to execute the second plan tree
  • a recording unit 05 configured to record a second iteration generated when the second plan tree is executed parameter.
  • the recording unit 05 is further configured to record the SQL execution plan to determine a state.
  • the second iteration parameter includes a tuple number of any one or more relation tables corresponding to the SQL execution plan.
  • the second iteration parameter when the SQL execution plan corresponds to at least two relationship tables, the second iteration parameter further includes a result obtained by the connection operation of any one or more of the at least two relationship tables The number of tuples in the collection.
  • the device further includes:
  • the updating unit 06 is configured to: when the difference between the second plan tree and the first plan tree is greater than a first threshold, update the first iteration parameter according to the second iteration parameter; and the Nth iteration
  • the second plan tree in the middle is the first plan tree in the N+1th iteration.
  • the establishing unit 02 is configured to: when the second iteration parameter is the same as the first iteration parameter, establish a second plan tree that is different from the first plan tree according to the first iteration parameter.
  • the recording unit 05 is further configured to record an execution time when the second plan tree is executed.
  • the determining unit 03 is further configured to use, as the SQL execution plan, the second plan tree whose execution time is the shortest among all N iterations when the number of iterations N is greater than the second threshold.
  • the determining unit 03 is further configured to use, as the SQL execution plan, the second plan tree whose execution time is the shortest among all N iterations when the number of iterations N is greater than the third threshold.
  • the recording unit 05 is further configured to record the SQL execution plan to determine a state.
  • the establishing unit 02 is further configured to establish an initial planning tree according to the pre-stored estimated iteration parameter when the initial iteration is performed;
  • the execution unit 04 is further configured to execute the initial plan tree, and obtain the execution of the The initial iteration parameters that are generated when the tree is initially planned;
  • the updating unit 05 is further configured to update the estimated iteration parameter by using the initial iteration parameter to obtain the first iteration parameter.
  • the apparatus further includes a query unit 08, where
  • the query unit 07 is configured to query whether the state of the SQL execution plan is the determined state
  • the determining unit 03 is further configured to execute the SQL execution plan when the state of the SQL execution plan is the determined state.
  • the updating unit 06 is specifically configured to combine the second iteration parameter and the first iteration parameter, and use the result of the union as the first iteration parameter.
  • the determining means of the SQL execution plan shown in FIGS. 4-7 can be implemented in the manner of the computer device (or system) in FIG.
  • FIG. 8 is a schematic diagram of a computer device 100 according to an embodiment of the present invention.
  • the computer device 100 comprises at least one processor 11, a communication bus 12, a memory 13 and at least one communication interface 14.
  • the memory 13 is used to store computer execution instructions
  • the processor 11 is connected to the memory 13 via the bus 12, and when the determining means of the SQL execution plan is executed, the processor 11 executes the computer execution instructions stored in the memory 13 to cause the SQL execution plan determining means
  • the method of determining the SQL execution plan of any of FIGS. 1 to 3 is performed.
  • the specific functions of the foregoing obtaining unit 01, the establishing unit 02, the determining unit 03, the executing unit 04, the recording unit 05, the updating unit 06, and the query unit 07 can all be called by the processor 11 in the computer device 100 to call the computer in the memory 13. Instruction implementation.
  • the processor 11 can be a general purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present invention.
  • CPU central processing unit
  • ASIC application-specific integrated circuit
  • Communication bus 12 can include a path for communicating information between the components described above.
  • the communication interface 14 uses a device such as any transceiver for use with other devices or communication networks Network communication, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Networks (WLAN), etc.
  • Network communication such as Ethernet, Radio Access Network (RAN), Wireless Local Area Networks (WLAN), etc.
  • the memory 13 can be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of information and instructions that can be stored.
  • the dynamic storage device may also be an Electrically Erasable Programmable Read-Only Memory (EEPROM), a Compact Disc Read-Only Memory (CD-ROM) or other optical disc storage, or a disc storage device ( Including compressed optical discs, laser discs, optical discs, digital versatile discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or can be used to carry or store desired program code in the form of instructions or data structures and can be stored by a computer Any other media taken, but not limited to this.
  • the memory 13 can be independently present and connected to the processor via a bus.
  • the memory 13 can also be integrated with the processor.
  • the memory 13 is used to store application code for executing the solution of the present invention, and is controlled by the processor 11.
  • the processor 11 is configured to execute application code stored in the memory 13.
  • processor 11 may include one or more CPUs, such as CPU0 and CPU1 in FIG.
  • computer device 100 can include multiple processors, such as processor 11 and processor 18 in FIG. Each of these processors can be a single-CPU processor or a multi-core processor.
  • a processor herein may refer to one or more devices, circuits, and/or processing cores for processing data, such as computer program instructions.
  • computer device 100 may also include output device 15 and input device 16.
  • the output device 15 is in communication with the processor 11 and can display information in a variety of ways.
  • the output device 15 may be a liquid crystal display (LCD), a light emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector. Wait.
  • the input device 16 communicates with the processor 11, The user's input can be accepted in a variety of ways.
  • input device 16 can be a mouse, keyboard, touch screen device, or sensing device, and the like.
  • the computer device 100 described above may be a general purpose computer device or a special purpose computer device.
  • the computer device 100 can be a desktop computer, a portable computer, a network server, a personal digital assistant (PDA), a mobile phone, a tablet computer, a wireless terminal device, a communication device, an embedded device, or have FIG. A device of similar structure.
  • PDA personal digital assistant
  • Embodiments of the invention do not limit the type of computer device 100.
  • An embodiment of the present invention provides a method for determining a SQL execution plan.
  • the first iteration parameter updated after the N-1th iteration is obtained.
  • the first The iterative parameter includes a first feature value and/or a second feature value
  • the first feature value is used to indicate the number of tuples of the i-th relationship table
  • the second feature value is used to indicate that at least two relationship tables are obtained after the connection operation.
  • the number of tuples in the result set; then, the second iteration parameter is used to establish a second plan tree; when the second plan tree is the same as the first plan tree, the second plan tree is used as the SQL execution plan.
  • the second plan tree finally obtained in the solution is not dependent on the estimated iteration parameters in the database, but is based on the updated first iteration parameter in the iterative process, and then the second plan tree and the first When the plan tree is the same, the second plan tree is used as the SQL execution plan, which can accurately determine the SQL execution plan and improve the execution efficiency of the SQL execution plan.
  • the disclosed system, apparatus, and method may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the modules or units is only a logical function division.
  • there may be another division manner for example, multiple singles.
  • Meta or components may be combined or integrated into another system, or some features may be omitted or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
  • the integrated unit if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium.
  • the technical solution of the present invention which is essential or contributes to the prior art, or all or part of the technical solution, may be embodied in the form of a software product stored in a storage medium.
  • a number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) or a processor to perform all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. .

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Operations Research (AREA)
  • Computational Linguistics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种SQL执行计划的确定方法及装置,涉及计算机技术领域,可以优化SQL执行计划的确定,提高SQL执行计划的执行效率。其中,所述SQL执行计划对应至少一个关系表,在第N次迭代中,该方法包括:获取在第N次迭代中对所述至少一个关系表执行第一计划树后产生的第一迭代参数,其中N为大于1的自然数;根据所述第一迭代参数建立第二计划树;当所述第二计划树与所述第一计划树的差异不大于第一阈值时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划。

Description

一种SQL执行计划的确定方法及装置
本申请要求于2016年02月19日提交中国专利局、申请号为201610095091.0、发明名称为“一种SQL执行计划的确定方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及计算机技术领域,尤其涉及一种SQL执行计划的确定方法及装置。
背景技术
执行一条SQL(Struc tured Query Language,结构化查询语言)语句通常需要三个阶段,即词法和语法分析阶段、SQL执行计划确定阶段和SQL执行计划执行阶段。
具体的,一条SQL语句表示用户想要得到的结果,例如,查询所有住在北京市的客户,但SQL语句并不会告知服务器如何去执行,因此,当服务器收到一条Query(查询)命令后,经过词法和语法分析阶段确定这条Query命令没有语法错误后,会形成一个Parse Tree(解析树),服务器搜索自身数据库内相关的已统计的统计信息,结合Parse Tree,确定该SQL语句优选的SQL执行计划。其中,SQL执行计划可以以Plan Tree(计划树)的形式得到,一个Plan Tree上的各个节点由若干基本操作组成,例如,遍历多张表,执行一个嵌套连接或Hash(哈希)连接等基本操作,最终,由服务器按照得到的Plan Tree执行该SQL执行计划,输出的结果即为该SQL语句表示的结果。
可以看出,SQL语句的执行效率高低在一定程度上取决于能否确定高效的SQL执行计划,而现有技术中,数据库内的统计信息通常是基于采样值得到的特征值。例如,一个关系表中的元组数(RelTuples)、一个关系表中一个字段内唯一非空数值的数目 (Distinct值)等特征值,这些采样得到的特征值通常存在一定的误差,而且在时间上具有滞后性,因此,服务器基于上述统计信息确定出的SQL执行计划通常不是最优的执行计划。
发明内容
本发明的实施例提供了一种SQL执行计划的确定方法及装置,可以优化SQL执行计划的确定,提高SQL执行计划的执行效率。
为达到上述目的,本发明的实施例采用如下技术方案:
本发明实施例的第一方面提供了一种结构化查询语言SQL执行计划的确定方法,该SQL执行计划对应至少一个关系表,在第N次迭代中,包括:获取在第N-1次迭代中对该至少一个关系表执行第一计划树后产生的第一迭代参数,其中N为大于1的自然数;根据该第一迭代参数建立第二计划树;当该第二计划树与该第一计划树的差异不大于第一阈值时,将该第一计划树或该第二计划树确定为该SQL执行计划。
结合第一方面,在第一方面的第一种可能的实现方式中,该第一阈值为0,对应的,该当该第二计划树与该第一计划树的差异不大于第一阈值时,将该第一计划树或该第二计划树确定为该SQL执行计划,包括,当该第二计划树与该第一计划树相同时,将该第一计划树或该第二计划树确定为该SQL执行计划。
本发明实施例所取得的有益效果是,本发明实施例通过迭代执行的方式获得优化的SQL执行计划。在每一次迭代过程中,需要比较上一次迭代过程中建立的计划树(本发明实施例中统一称为第一计划树)与本次迭代过程中建立的计划树(本发明实施例中统一称为第二计划树),并且,该第二计划树是以上一次迭代过程中更新后的迭代参数(本发明实施例中统一称为第一迭代参数)为依据建立的,也就是说,每次迭代过程中建立的第二计划树,都是基于执行第一计划树后更新的第一迭代参数建立的,那么,经过多次迭代后,最终得到的计划树并不是依赖于数据库内已统计的估算迭代参数,而是以迭代过程中每一次实际执行计划树时记录的迭代参数为依 据,建立计划树,从而得到SQL语句较为准确的SQL执行计划,提高SQL执行计划的执行效率。
结合第一方面或第一方面的第一种可能的实现方式,在第一方面的第二种可能的实现方式中,该第一迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第一方面或第一方面的第一至二种可能的实现方式,在第一方面的第三种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该第一迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第一方面或第一方面的第一至三种可能的实现方式,在第一方面的第四种可能的实现方式中,在该将该第一计划树或该第二计划树确定为该SQL执行计划之后,还包括:记录该SQL执行计划为确定状态。
结合第一方面或第一方面的第一或四任一种可能的实现方式,在第一方面的第五种可能的实现方式中,在该根据该第一迭代参数建立第二计划树之后,还包括:执行该第二计划树;记录执行该第二计划树时产生的第二迭代参数。
本发明实施例所取得的有益效果是,由于该更新后的第一迭代参数是实际执行第二计划树时得到的,因此,使用该更新后的第一迭代参数建立的第二计划树更为准确。
结合第一方面的第五种可能的实现方式,在第一方面的第六种可能的实现方式中,该第二迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第一方面的第五或六种可能的实现方式,在第一方面的第七种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该第二迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第一方面的第五至七任一种可能的实现方式,在第一方面的第八种可能的实现方式中,该方法还包括:当该第二计划树与该 第一计划树的差异大于第一阈值时,根据该第二迭代参数更新该第一迭代参数;将该第N次迭代中的第二计划树作为第N+1次迭代中的第一计划树。
结合第一方面的第八种可能的实现方式,在第一方面的第九种可能的实现方式中,在该根据该第二迭代参数更新该第一迭代参数之前,还包括:当该第二迭代参数与该第一迭代参数相同时,根据该第一迭代参数建立与该第一计划树不相同的第二计划树。
结合第一方面的第九种可能的实现方式,在第一方面的第十种可能的实现方式中,在该根据该第一迭代参数建立与该第一计划树不相同的第二计划树之后,还包括:记录执行该第二计划树的执行时间;当该N大于第二阈值时,将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划。
结合第一方面的第十种可能的实现方式,在第一方面的第十一种可能的实现方式中,在该将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划之后,还包括:记录该SQL执行计划为确定状态。
结合第一方面的第八种可能的实现方式,在第一方面的第十二种可能的实现方式中,在该根据该第二迭代参数更新该第一迭代参数之前,还包括:记录执行该第二计划树的执行时间;当该N大于第三阈值时,将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划。
结合第一方面的第十二种可能的实现方式,在第一方面的第十三种可能的实现方式中,在该将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划之后,还包括:记录该SQL执行计划为确定状态。
本发明实施例所取得的有益效果是,对于那些在迭代过程中已经发生变异的SQL执行计划,有可能永远都无法迭代出与上一次建立的计划树相同的计划树,因此,为了避免无限制的死循环,可以认为当迭代次数N大于阈值后,在已经历的N次迭代过程中,执行 时间最短的第二计划树即为最优的计划树,进而将该第二计划树作为该SQL执行计划。
结合第一方面的第七至十三任一种可能的实现方式,在第一方面的第十四种可能的实现方式中,该根据该第二迭代参数更新该第一迭代参数,包括:将该第二迭代参数和该第一迭代参数取并集,将该并集的结果作为该第一迭代参数。
结合第一方面或第一方面的第二至十四任一种可能的实现方式,在第一方面的第十五种可能的实现方式中,该方法还包括:在初始迭代执行时,根据预先存储的估算迭代参数建立初始计划树;执行该初始计划树得到初始迭代参数;根据该初始迭代参数更新该估算迭代参数,得到该第一迭代参数。
结合第一方面的第十五种可能的实现方式,在第一方面的第十六种可能的实现方式中,该估算迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第一方面的第十五种或第十六种可能的实现方式,在第一方面的第十七种可能的实现方式中,该初始迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第一方面的第十五至十七任一种可能的实现方式,在第一方面的第十八种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该初始迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第一方面的第十五至十八任一种可能的实现方式,在第一方面的第十九种可能的实现方式中,该根据该初始迭代参数更新该估算迭代参数,得到该第一迭代参数,包括:将该初始迭代参数和该估算迭代参数取并集,将该并集的结果作为该第一迭代参数。
结合第一方面的第十五至十九任一种可能的实现方式,在第一方面的第二十种可能的实现方式中,在该初始迭代执行之前,还包括:查询该SQL执行计划的状态是否为该确定状态;当该SQL执行计划的状态为该确定状态时,执行该SQL执行计划。
本发明实施例所取得的有益效果是,当服务器已经存储了经过优化后的SQL执行计划后,当需要再次执行时,不需要重复进行SQL执行计划的确定,提高了服务器的执行效率。
结合第一方面或第一方面的第二到第二十任一种可能的实现方式,在第一方面的第二十一种可能的实现方式中,该SQL执行计划还包括过滤条件,当SQL执行计划还包括过滤条件时,该第一迭代参数包括该SQL执行计划对应的任意一个或多个关系表内符合该过滤条件的元组数。
结合第一方面或第一方面的第二到第二十一任一种可能的实现方式,在第一方面的第二十二种可能的实现方式中,该第一迭代参数还包括:该SQL执行计划对应的任一关系表中一个字段内唯一非空数值的数目,和/或,该关系表中出现次数超过第二阈值的列的集合(MCV)。
本发明实施例所取得的有益效果是,本发明实施例中得到的第二计划树并不是依赖于数据库内已统计的估算迭代参数,而是以迭代过程中更新后的第一迭代参数为依据建立的,进而当第二计划树与第一计划树相同时,将第二计划树作为SQL执行计划,可较为准确的确定出SQL执行计划,提高SQL执行计划的执行效率。
本发明实施例的第二方面提供了一种结构化查询语言SQL执行计划的确定装置,该SQL执行计划对应至少一个关系表,所述装置包括存储器和耦合于该存储器的处理器,在第N次迭代中,包括:该处理器用于:获取在第N-1次迭代中对该至少一个关系表执行第一计划树后产生的第一迭代参数,其中N为大于1的自然数;根据该第一迭代参数建立第二计划树;当该第二计划树与该第一计划树的差异不大于第一阈值时,将该第一计划树或该第二计划树确定为该SQL执行计划。
结合第二方面,在第二方面的第一种可能的实现方式中,该第一阈值为0,对应的,该处理器用于当该第二计划树与该第一计划 树相同时,将该第一计划树或该第二计划树确定为该SQL执行计划。
结合第二方面或第二方面的第一种可能的实现方式,在第二方面的第二种可能的实现方式中,该第一迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第二方面或第二方面的第一至二种可能的实现方式,在第二方面的第三种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该第一迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第二方面或第二方面的第一至三种可能的实现方式,在第二方面的第四种可能的实现方式中,在该将该第一计划树或该第二计划树确定为该SQL执行计划之后,该处理器还用于:记录该SQL执行计划为确定状态。
结合第二方面或第二方面的第一或四任一种可能的实现方式,在第二方面的第五种可能的实现方式中,在该根据该第一迭代参数建立第二计划树之后,该处理器还用于:执行该第二计划树;记录执行该第二计划树时产生的第二迭代参数。
结合第二方面的第五种可能的实现方式,在第二方面的第六种可能的实现方式中,该第二迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第二方面的第五或六种可能的实现方式,在第二方面的第七种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该第二迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第二方面的第五至七任一种可能的实现方式,在第二方面的第八种可能的实现方式中,该处理器还用于:当该第二计划树与该第一计划树的差异大于第一阈值时,根据该第二迭代参数更新该第一迭代参数;将该第N次迭代中的第二计划树作为第N+1次迭代中的第一计划树。
结合第二方面的第八种可能的实现方式,在第二方面的第九种 可能的实现方式中,在该根据该第二迭代参数更新该第一迭代参数之前,该处理器还用于:当该第二迭代参数与该第一迭代参数相同时,根据该第一迭代参数建立与该第一计划树不相同的第二计划树。
结合第二方面的第九种可能的实现方式,在第二方面的第十种可能的实现方式中,在该根据该第一迭代参数建立与该第一计划树不相同的第二计划树之后,该处理器还用于:记录执行该第二计划树的执行时间;当该N大于第二阈值时,将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划。
结合第二方面的第十种可能的实现方式,在第二方面的第十一种可能的实现方式中,在该将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划之后,该处理器还用于:记录该SQL执行计划为确定状态。
结合第二方面的第八种可能的实现方式,在第二方面的第十二种可能的实现方式中,在该根据该第二迭代参数更新该第一迭代参数之前,该处理器还用于:记录执行该第二计划树的执行时间;当该N大于第三阈值时,将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划。
结合第二方面的第十二种可能的实现方式,在第二方面的第十三种可能的实现方式中,在该将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划之后,该处理器还用于:记录该SQL执行计划为确定状态。
结合第二方面的第七至十三任一种可能的实现方式,在第二方面的第十四种可能的实现方式中,该处理器具体用于:将该第二迭代参数和该第一迭代参数取并集,将该并集的结果作为该第一迭代参数。
结合第二方面或第二方面的第二至十四任一种可能的实现方式,在第二方面的第十五种可能的实现方式中,该处理器还用于:在初始迭代执行时,根据预先存储的估算迭代参数建立初始计划树;执行该初始计划树得到初始迭代参数;根据该初始迭代参数更新该 估算迭代参数,得到该第一迭代参数。
结合第二方面的第十五种可能的实现方式,在第二方面的第十六种可能的实现方式中,该估算迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第二方面的第十五种或第十六种可能的实现方式,在第二方面的第十七种可能的实现方式中,该初始迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第二方面的第十五至十七任一种可能的实现方式,在第二方面的第十八种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该初始迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第二方面的第十五至十八任一种可能的实现方式,在第二方面的第十九种可能的实现方式中,该处理器具体用于:将该初始迭代参数和该估算迭代参数取并集,将该并集的结果作为该第一迭代参数。
结合第二方面的第十五至十九任一种可能的实现方式,在第二方面的第二十种可能的实现方式中,在该初始迭代执行之前,该处理器还用于:查询该SQL执行计划的状态是否为该确定状态;当该SQL执行计划的状态为该确定状态时,执行该SQL执行计划。
结合第二方面或第二方面的第二到第二十任一种可能的实现方式,在第二方面的第二十一种可能的实现方式中,该SQL执行计划还包括过滤条件,当SQL执行计划还包括过滤条件时,该第一迭代参数包括该SQL执行计划对应的任意一个或多个关系表内符合该过滤条件的元组数。
结合第二方面或第二方面的第二到第二十一任一种可能的实现方式,在第二方面的第二十二种可能的实现方式中,该第一迭代参数还包括:该SQL执行计划对应的任一关系表中一个字段内唯一非空数值的数目,和/或,该关系表中出现次数超过第二阈值的列的集合(MCV)。
本发明实施例的第三方面提供了一种结构化查询语言SQL执行计划的确定装置,该SQL执行计划对应至少一个关系表,所述装置包括获取单元、建立单元和确定单元,在第N次迭代中,包括:该获取单元用于获取在第N-1次迭代中对该至少一个关系表执行第一计划树后产生的第一迭代参数,其中N为大于1的自然数;该建立单元用于根据该第一迭代参数建立第二计划树;该确定单元用于当该第二计划树与该第一计划树的差异不大于第一阈值时,将该第一计划树或该第二计划树确定为该SQL执行计划。
结合第三方面,在第三方面的第一种可能的实现方式中,该第一阈值为0,对应的,该确定单元具体用于当该第二计划树与该第一计划树相同时,将该第一计划树或该第二计划树确定为该SQL执行计划。
结合第三方面或第三方面的第一种可能的实现方式,在第三方面的第二种可能的实现方式中,该第一迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第三方面或第三方面的第一至二种可能的实现方式,在第三方面的第三种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该第一迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第三方面或第三方面的第一至三种可能的实现方式,在第三方面的第四种可能的实现方式中,在该将该第一计划树或该第二计划树确定为该SQL执行计划之后,该装置还包括记录单元,用于记录该SQL执行计划为确定状态。
结合第三方面或第三方面的第一或四任一种可能的实现方式,在第三方面的第五种可能的实现方式中,在该根据该第一迭代参数建立第二计划树之后,该装置还包括执行单元,用于执行该第二计划树;该记录单元还用于记录执行该第二计划树时产生的第二迭代参数。
结合第三方面的第五种可能的实现方式,在第三方面的第六种可能的实现方式中,该第二迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第三方面的第五或六种可能的实现方式,在第三方面的第七种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该第二迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第三方面的第五至七任一种可能的实现方式,在第三方面的第八种可能的实现方式中,该装置还包括更新单元,用于当该第二计划树与该第一计划树的差异大于第一阈值时,根据该第二迭代参数更新该第一迭代参数;将该第N次迭代中的第二计划树作为第N+1次迭代中的第一计划树。
结合第三方面的第八种可能的实现方式,在第三方面的第九种可能的实现方式中,在该根据该第二迭代参数更新该第一迭代参数之前,该建立单元还用于:当该第二迭代参数与该第一迭代参数相同时,根据该第一迭代参数建立与该第一计划树不相同的第二计划树。
结合第三方面的第九种可能的实现方式,在第三方面的第十种可能的实现方式中,在该根据该第一迭代参数建立与该第一计划树不相同的第二计划树之后,该记录单元还用于记录执行该第二计划树的执行时间;该确定单元还用于当该N大于第二阈值时,将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划。
结合第三方面的第十种可能的实现方式,在第三方面的第十一种可能的实现方式中,在该将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划之后,该记录单元还用于:记录该SQL执行计划为确定状态。
结合第三方面的第八种可能的实现方式,在第三方面的第十二种可能的实现方式中,在该根据该第二迭代参数更新该第一迭代参数之前,该记录单元还用于:记录执行该第二计划树的执行时间; 该确定单元还用于当该N大于第三阈值时,将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划。
结合第三方面的第十二种可能的实现方式,在第三方面的第十三种可能的实现方式中,在该将全部N次迭代中该执行时间最短的第二计划树作为该SQL执行计划之后,该记录单元还用于:记录该SQL执行计划为确定状态。
结合第三方面的第七至十三任一种可能的实现方式,在第三方面的第十四种可能的实现方式中,该更新单元具体用于:将该第二迭代参数和该第一迭代参数取并集,将该并集的结果作为该第一迭代参数。
结合第三方面或第三方面的第二至十四任一种可能的实现方式,在第三方面的第十五种可能的实现方式中,该建立单元还用于在初始迭代执行时,根据预先存储的估算迭代参数建立初始计划树;该执行单元还用于执行该初始计划树得到初始迭代参数;该更新单元还用于根据该初始迭代参数更新该估算迭代参数,得到该第一迭代参数。
结合第三方面的第十五种可能的实现方式,在第三方面的第十六种可能的实现方式中,该估算迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第三方面的第十五种或第十六种可能的实现方式,在第三方面的第十七种可能的实现方式中,该初始迭代参数包括该SQL执行计划对应的任意一个或多个关系表的元组数。
结合第三方面的第十五至十七任一种可能的实现方式,在第三方面的第十八种可能的实现方式中,该SQL执行计划对应至少两个关系表时,该初始迭代参数还包括该至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
结合第三方面的第十五至十八任一种可能的实现方式,在第三方面的第十九种可能的实现方式中,该更新单元具体用于:将该初始迭代参数和该估算迭代参数取并集,将该并集的结果作为该第一 迭代参数。
结合第三方面的第十五至十九任一种可能的实现方式,在第三方面的第二十种可能的实现方式中,在该初始迭代执行之前,该装置还包括查询单元,用于查询该SQL执行计划的状态是否为该确定状态;该确定单元还用于当该SQL执行计划的状态为该确定状态时,执行该SQL执行计划。
结合第三方面或第三方面的第二到第二十任一种可能的实现方式,在第三方面的第二十一种可能的实现方式中,该SQL执行计划还包括过滤条件,当SQL执行计划还包括过滤条件时,该第一迭代参数包括该SQL执行计划对应的任意一个或多个关系表内符合该过滤条件的元组数。
结合第三方面或第三方面的第二到第二十一任一种可能的实现方式,在第三方面的第二十二种可能的实现方式中,该第一迭代参数还包括:该SQL执行计划对应的任一关系表中一个字段内唯一非空数值的数目,和/或,该关系表中出现次数超过第二阈值的列的集合(MCV)。
第四方面,提供了一种结构化查询语言(SQL)执行计划的确定装置,其特征在于,包括:处理器、存储器、总线和通信接口;该存储器用于存储计算机执行指令,该处理器与该存储器通过该总线连接,当该确定装置运行时,该处理器执行该存储器存储的该计算机执行指令,以使该确定装置执行如本发明实施例第一方面,第一方面的第一到第二十二中任意一种可能的实现方式所描述的该SQL执行计划的确定方法。
第五方面,提供了一种计算机存储介质,用于储存为第四方面所描述的SQL执行计划的确定装置所用的计算机软件指令,其包含用于执行第四方面的SQL执行计划的确定装置所设计的程序。
本发明中,SQL执行计划的确定装置的名字对设备本身不构成限定,在实际实现中,这些设备可以以其他名称出现。只要各个设备的功能和本发明类似,属于本发明权利要求及其等同技术的范围 之内。
另外,第二方面至第五方面中任一种设计方式所带来的技术效果可参见第一方面中不同可能的实现方式所带来的技术效果,此处不再赘述。
附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍。
图1为本发明实施例提供的一种SQL执行计划的确定方法的流程示意图;
图2为本发明实施例提供的另一种SQL执行计划的确定方法的流程示意图;
图3为本发明实施例提供的另一种SQL执行计划的确定方法的流程示意图;
图4为本发明实施例提供的一种SQL执行计划的确定装置的结构示意图;
图5为本发明实施例提供的另一种SQL执行计划的确定装置的结构示意图;
图6为本发明实施例提供的另一种SQL执行计划的确定装置的结构示意图;
图7为本发明实施例提供的另一种SQL执行计划的确定装置的结构示意图;
图8为本发明实施例提供的一种计算机设备的结构示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。
另外,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括一个 或者更多个该特征。在本发明的描述中,除非另有说明,“多个”的含义是两个或两个以上。
本发明实施例提供的一种SQL执行计划的确定方法,可具体应用于SQL执行计划确定阶段,本方案的核心原理在于:使用迭代的方法,通过每一次实际执行计划树时产生的迭代参数建立计划树,以求取最优的SQL执行计划。
具体的,在现有技术中,服务器接收SQL语句,确定SQL执行计划时,通常是根据自身数据库内预先存储的估算迭代参数(即利用采样或者估算方法得到的特征值)直接建立计划树,并将该计划树作为SQL执行计划,但由于估算迭代参数可能并不准确,进而导致确定出的SQL执行计划不够准确。
因此,在本发明实施例提供的SQL执行计划的确定方法中,可利用迭代的方法,循环建立并执行计划树,并将每次实际执行计划树的过程中产生的迭代参数记录下来,以更新上一次迭代过程中的利用采样或估算方法得到的特征值,进而,在下一次迭代过程中使用该更新后的迭代参数重新建立计划树,直至相邻两次迭代过程中建立的计划树相同,则将该计划树作为SQL执行计划。
在每一次迭代过程中,需要比较上一次迭代过程中建立的计划树(本发明实施例中统一称为第一计划树)与本次迭代过程中建立的计划树(本发明实施例中统一称为第二计划树),并且,该第二计划树是以上一次迭代过程中更新后的迭代参数(本发明实施例中统一称为第一迭代参数)为依据建立的,也就是说,每次迭代过程中建立的第二计划树,都是基于执行第一计划树后更新的第一迭代参数建立的,那么,经过多次迭代后,最终得到的计划树并不是依赖于数据库内已统计的估算迭代参数,而是以迭代过程中每一次实际执行计划树时记录的迭代参数为依据,建立计划树,从而得到较为准确的SQL执行计划,提高SQL执行计划的执行效率。
为详细阐述本发明实施例提供的一种SQL执行计划的确定方法,以下对本发明实施例中可能涉及的一些专业词汇进行解释。
首先,为清楚地阐述本发明实施例中涉及的迭代过程,不妨设上一次迭代为第N-1次迭代,本次迭代为第N次迭代,则第N-1次迭代时建立的计划树为第一计划树,将第N次迭代时建立的计划树为第二计划树,其中,N为大于1的自然数。
所述SQL执行计划对应数据库中的至少一个关系表,不妨设SQL执行计划对应M个关系表,其中M为大于1的自然数。
不妨设第一迭代参数具体可以包括第一特征值和/或第二特征值,即第一特征值和第二特征值中的至少一个。第一特征值用于指示SQL执行计划对应的任意一个或多个关系表的元组数,第二特征值用于指示所述SQL执行计划对应至少两个关系表时,所述至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。本发明实施例中用N(i)表示第一特征值,用N(i,j,k)表示第二特征值。其中,N(i)为第i个关系表的元组数,N(i,j,k)为按照第i个关系表、第j个关系表以及第k个关系表的顺序进行连接操作(即join)后得到的结果集中元组的个数。
进一步地,服务器执行SQL执行计划还可以包括确定SQL执行计划的过滤条件,例如,该过滤条件为要求关系表中所有身高大于180厘米的男生,那么,此时,该第一特征值可进一步用于指示第i个关系表内符合该过滤条件的元组数。
类似的,本发明实施例中涉及的第二迭代参数也具体包括第一特征值和/或第二特征值,不同的是,第一迭代参数是指在第N-1次迭代时更新的迭代参数,而第二迭代参数是指在第N次迭代时执行第二计划树时产生的迭代参数,第一迭代参数的更新方式将在本发明实施例中进行具体的描述。
进一步地,特征值还可以包括:关系表中一个字段内唯一非空数值的数目(即Distinct值),和/或,关系表中出现次数超过第二阈值的列的集合(即MCV,most common value)。
变异,在本发明实施例中可以用Variation来表示,具体的,若第N次迭代时建立的第二计划树,与第N-1次迭代时建立的第一 计划树不相同,但是,执行该第二计划树时产生的第二迭代参数与执行该第一计划树时产生的第一迭代参数相同,则认为当前的SQL执行计划需要发生变异,才能进一步获取更优的SQL执行计划。
结合附图1所示,发明实施例提供一种SQL执行计划的确定方法,由于迭代过程中第2至最后一次迭代过程均相同,因此,此处以第N次迭代过程为例进行示例性的说明,该方法包括:
101、获取执行第一计划树产生的第一迭代参数。
由于每一次迭代过程中建立的计划树以及在当次迭代过程结束时生成的第一迭代参数均可被保存,因此,在第N次迭代过程中,可获取到第N-1次迭代时建立的第一计划树以及上述第一迭代参数。
102、根据所述第一迭代参数建立第二计划树。
例如,N=2时,可根据第1次迭代完成时获得的第一迭代参数建立第二计划树。
103、执行该第二计划树,并记录执行该第二计划树时产生的第二迭代参数。
具体的,在步骤103中,执行步骤102中建立的第二计划树,并记录执行该第二计划树时产生的第二迭代参数。
类似的,该第二迭代参数也包括N(i)和/或N(i,j,k)
104、比较第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树是否相同。
需要说明的是,当N=2时,则上述第N-1次迭代即第1次迭代时建立的初始计划树。
应理解,示例性的,步骤104比较第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树是否相同。在一些实施例中,步骤104还包括比较第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树是否不大于阈值,阈值可以是预先设定或者训练得到的固定值,也可以是在系统中不断更新的动态值,不做限定。示例性的,可以比较第二计划树和第一计划树的执行步骤 的差异步骤是否不大于1个步骤,或者可以比较第二计划树和第一计划树的执行步骤的差异步骤是否不大于99%等,不做限定。后续步骤中涉及比较第一计划树和第二计划树是否相同或者类似表述时和步骤104一致,不再赘述。一般的,当阈值不为0时,得到的SQL执行计划是次优的执行计划,但是应理解次优执行计划的确定过程比起最优执行计划的确定过程节省运算时间和资源,在一些实施例中,比如对运算时间和资源要求较高的应用场景中,会采用次优执行计划。
105、若第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树不相同,则使用该第二迭代参数更新该第一迭代参数。
具体的,可以将第二迭代参数中,与第一迭代参数不相同的第一特征值和/或第二特征值添加至该第一迭代参数,即将第一迭代参数和第二迭代参数取并集,得到更新后的第一迭代参数,以便于在N+1次迭代时,使用该更新后的第一迭代参数重新建立第二计划树,由于该更新后的第一迭代参数是实际执行第二计划树时得到的第一特征值和/或第二特征值,因此,使用该更新后的第一迭代参数建立的第二计划树更为准确。
106、使用第二计划树更新第一计划树,并设置迭代次数加1。
此时,本次迭代过程中生成的第二计划树便作为下次迭代过程中的第一计划树,直至某次迭代过程中建立第二计划树与上一次迭代过程中建立的第一计划树相同为止。
并且,可设置迭代次数加1,以便于重复执行上述步骤101-106。
107、若第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树相同,则将该第二计划树作为SQL执行计划。
具体的,在步骤107中,当第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树相同时,说明经过N次迭代后,该第一迭代参数中已包含了所有的第一特征值和第二特征值,因此,此时根据第一迭代参数建立的第二计划树已经达到最优,则可以将该第二计划树作为SQL执行计划。
此时,可保存该第二计划树与执行该第二计划树相关的SQL语句之间的对应关系,当再次收到该SQL语句时,服务器便可以直接从相应的存储单元中获取到该第二计划树,即SQL执行计划。
在一些实施例中,和步骤104类似,步骤107还包括若第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树不大于某一阈值,则将该第二计划树或第一计划树作为SQL执行计划。应理解,在该实施例中第一计划树和第二计划树均为次优计划树,可以任选其中之一作为SQL执行计划。
应理解,在一些实施例中或者一些实施例的示例性迭代周期中,步骤103、步骤105、步骤106为可选步骤。
另外,可选的,在每一个迭代周期中,可以记录第二计划树的执行时间,当迭代次数超过预定的阈值时,即迭代算法在阈值时间内没有收敛的情况下,选择全部迭代周期中上述执行时间最短的第二计划树作为SQL执行计划。
可选的,在将该第二计划树作为SQL执行计划之后,在服务器中将该SQL执行计划的状态设置为确定状态,即经过优化的该SQL执行计划已经确定。在后续步骤中,当SQL执行计划的状态为确定状态时,不需要再重复确定SQL执行计划的过程,提高了服务器的执行效率。
进一步地,在图1所示的SQL执行计划的确定方法的基础上,本发明实施例提供还一种SQL执行计划的确定方法,如图2所示,包括:
201、查询所述SQL执行计划的状态是否为确定状态。
具体的,SQL语句中携带有SQL执行计划对应的关系表的标识,例如,接收到的SQL语句为:select count(*)from dba,即从标识为dba的关系表中查找dba关系表的行数。
由于服务器可能会在一段时间内反复多次执行同一条SQL语句,因此,在第一次生成一条SQL语句相关的SQL执行计划时,可以保存该SQL执行计划与该SQL语句的对应关系,这样,当再次收 到一条SQL语句时,可以查询是否存储有与这条SQL语句对应的SQL执行计划,即所述SQL执行计划的状态是否为确定状态。
示例性的,可以设置变量Optimization,用来指示是否存储有与接收到的SQL语句对应的SQL执行计划。
此时,服务器可以查询与该SQL语句对应的变量Optimization是否为1,若Optimization=1,则说明已经存储有与接收到的SQL语句对应的SQL执行计划,那么,服务器便可以直接从相应的存储单元中获取到该SQL执行计划。
相反的,若Optimization≠1,即,所述SQL执行计划的状态是不确定状态,则说明未存储有与接收到的SQL语句对应的SQL执行计划,即第一次执行该SQL语句,此时执行下述步骤202-213。
202、若所述SQL执行计划为不确定状态,则对后续迭代过程中的变量进行初始化。
在步骤202中,若Optimization≠1,此时,可以对迭代中的变量进行初始化,例如,设置迭代次数N等于1,设置Optimization=0,设置Variation(变异)=0。
203、在初始迭代执行时,根据预先存储的估算迭代参数建立初始计划树。
当步骤202中的初始化操作完成之后,开始第1次迭代过程,此时,可以根据统计信息中存储的估算迭代参数建立初始计划树。
由于第1次迭代时,还没有建立计划树,因此,还无法从执行计划树的过程中采集到实际的迭代参数,因此,此时刻沿用现有技术,即使用统计信息中存储的估算迭代参数建立初始计划树T0
204、执行所述初始计划树,得到执行所述初始计划树时产生的初始迭代参数,使用所述初始迭代参数更新所述估算迭代参数。
与现有技术不同的是,在步骤204中,服务器可以执行步骤203中建立的初始计划树,并且,记录执行初始计划树时产生的初始迭代参数,即N(i)和/或N(i,j,k),这样,便可以使用执行初始计划树时产生的初始迭代参数,更新步骤203中的估算迭代参数。
示例性的,假设步骤201中的SQL语句中携带有2个关系表的标识,即t1和t2。那么,步骤203中建立初始计划树的估算迭代参数具体包括:N(t1)和N(t2)、和N(t2,t1),而在步骤204中,执行初始计划树时产生的初始迭代参数可能包括N(t1)、N(t2)、和N(t1,t2),此时,可以将初始迭代参数中与估算迭代参数中不同的迭代参数更新到估算迭代参数中,即更新后的估算迭代参数为:N(t1)、N(t2)、N(t1,t2)和N(t2,t1),则将更新后的估算迭代参数作为上述第一迭代参数,以便于在后续N-1次迭代过程中使用更新后的第一迭代参数建立第二计划树。
进一步地,后续第2至最后一次迭代过程均可参见下述步骤205-213,具体的,此处以第N次迭代过程为例进行示例性的说明。
205、在第N次迭代时,获取在第N-1次迭代时建立的第一计划树。
由于每一次迭代过程中建立的计划树均可被保存,因此,在第N次迭代过程中,可获取到第N-1次迭代时建立的第一计划树。
206、判断SQL执行计划是否需要变异。
也即第一迭代参数是否和第二迭代参数相同,如果相同,则需要变异,否则不需要变异。应理解此步骤中N>1,示例性的,此处以N=2为例进行说明,经过步骤203-204的第1次迭代过程,在第2次迭代时,首先可判断是否需要变异,即Variation是否等于1。
若Variation≠1,则执行步骤207,若Variation=1,则执行步骤208。
207、若不需要变异,则根据第N-1次迭代时更新后的第一迭代参数建立第二计划树。
具体的,若执行第一计划树时产生的第一迭代参数与执行第二计划树时产生的第二迭代参数不相同,则使用该第二迭代参数更新该第一迭代参数。可以将第二迭代参数中,与第一迭代参数不相同的第一特征值和/或第二特征值添加至该第一迭代参数,将得到更新后的第一迭代参数,即将第一迭代参数和第二迭代参数取并集,并将并集结果作为更新后的第一迭代参数。
即,若Variation≠1,即不需要变异,则根据第N-1次迭代时更新后的第一迭代参数建立第二计划树。
例如,N=2时,若Variation≠1,则根据第1次迭代时更新后的第一迭代参数(即上述步骤204中得到的第一迭代参数)建立第二计划树。
208、若需要变异,则根据第N-1次迭代时更新后的第一迭代参数,建立与上述第一计划树不同的第二计划树。
具体的,若Variation=1,即需要变异,也可根据第N-1次迭代时更新后的第一迭代参数建立第二计划树,但与步骤207不同的是,建立的第二计划树与第N-1次迭代时建立的第一计划树不相同。
例如,第1次迭代时建立的计划树为初始计划树,那么,当N=3时,若Variation=1,则使用第2次迭代时更新后的第一迭代参数建立第二计划树,且保证第二计划树与第2次迭代时建立的第一计划树不相同。
应理解,服务器可以根据第一迭代参数建立第二计划树,此时的第二计划树是服务器认为的在第一迭代参数的限制下最优的计划树,而未必是实际最优的计划树,当需要变异时,可以禁止服务器生成上述服务器认为最优的第二计划树(即与第一计划树相同的第二计划树),而生成另一个与第一计划树不同的第二计划树。
209、执行该第二计划树,并记录执行该第二计划树时产生的第二迭代参数。
具体的,在步骤209中,执行步骤207或208中建立的第二计划树,并记录执行该第二计划树时产生的第二迭代参数。
类似的,该第二迭代参数也包括N(i)和/或N(i,j,k)
210、比较第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树是否相同。
需要说明的是,当N=2时,上述第N-1次迭代时,即第1次迭代时建立的第一计划树即为步骤203中建立的初始计划树。
211、若第N次迭代时建立的第二计划树与第N-1次迭代时建立 的第一计划树不相同,则比较执行第一计划树时产生的第一迭代参数与执行第二计划树时产生的第二迭代参数是否相同,即判断SQL执行计划是否需要变异,进入步骤206,直到第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树相同,进入步骤212。
212、若第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树相同,则将该第二计划树作为该SQL执行计划。
具体的,在步骤214中,当第N次迭代时建立的第二计划树与第N-1次迭代时建立的第一计划树相同时,说明经过N次迭代后,该第一迭代参数中已包含了所有的第一特征值和第二特征值,因此,此时根据第一迭代参数建立的第二计划树已经达到最优,则可以将该第二计划树作为该SQL执行计划。
并且,保存该第二计划树与该SQL语句之间的对应关系,并设置变量Optimization=1,这样,当再次收到该SQL语句时,判断Optimization=1,则说明已经存储有与接收到的SQL语句对应的SQL执行计划,那么,服务器便可以直接从相应的存储单元中获取到该SQL执行计划。
另外,在201-212的基础上,还可以增加步骤301-303,示例性的,如图3所示:
301、记录第N次迭代时,执行该第二计划树的执行时间。
302、判断迭代次数N是否大于阈值,SQL执行计划是否需要变异。
303、若迭代次数N大于阈值,且SQL执行计划需要变异,则将全部N次迭代中执行时间最短的第二计划树作为该SQL执行计划。
具体的,在上述步骤209,即执行该第二计划树时,可以记录执行该第二计划树所花费的执行时间。
进而,在步骤上述209之后,且在步骤210之前,执行步骤302,即判断当前的迭代次数N是否大于阈值,且SQL执行计划是否需要变异。
具体的,若迭代次数N大于阈值,且SQL执行计划需要变异,即N>阈值,且Variation=1,则执行步骤303,即将N次迭代过程中,步骤301中记录的执行时间最短的第二计划树,作为步骤201中该SQL执行计划。
这样一来,对于那些在迭代过程中已经发生变异的SQL执行计划,有可能永远都无法迭代出与上一次建立的计划树相同的计划树,因此,为了避免无限制的死循环,可以认为当迭代次数N大于阈值后,在已经历的N次迭代过程中,执行时间最短的第二计划树即为最优的计划树,进而将该第二计划树作为该SQL执行计划。
相应的,若在步骤302中,判断出当前的迭代次数N小于阈值,和/或,SQL执行计划不需要变异,此时,仍按照上述步骤210-212进行迭代,直至迭代次数N大于阈值,且SQL执行计划不需要变异。
另外,在记录每一次迭代时执行第二计划树的执行时间时,例如,第N次迭代过程中执行第二计划树的执行时间为T1,此时可以比较第N-1次迭代过程中执行第二计划树的执行时间T2与T1的大小,若T1小于T2,则保存执行时间较短的T1,以及执行时间较短的T1所对应的第二计划树,这样,保存的第二计划树即为N次迭代过程中执行时间最短的第二计划树,而无需记录每一次迭代时执行第二计划树的执行时间,和对应的第二计划树,以节省存储资源。
本发明的实施例提供一种SQL执行计划的确定方法,以第N次迭代过程为例,首先,获取在第N-1次迭代时更新后的第一迭代参数,示例性的,不妨设该第一迭代参数包括第一特征值和/或第二特征值,第一特征值用于指示第i个关系表的元组数,第二特征值用于指示至少两个关系表经过连接操作后得到的结果集中元组的个数;然后,使用该第一迭代参数建立第二计划树;当第二计划树与第一计划树相同时,则将第二计划树作为该SQL执行计划。本方案中最终得到的第二计划树并不是依赖于数据库内已统计的估算迭代参数,而是以迭代过程中更新后的第一迭代参数为依据建立的,进而当第二计划树与第一计划树相同时,将第二计划树作为SQL执行 计划,可较为准确的确定出SQL执行计划,提高SQL执行计划的执行效率。
图4为本发明实施例提供的一种SQL执行计划的确定装置的结构示意图,本发明实施例提供的SQL执行计划的确定装置可以用于实施上述图1-图3所示的本发明各实施例实现的方法,为了便于说明,仅示出了与本发明实施例相关的部分,具体执行的技术方案参照图1-图3所示的本发明各实施例,不再赘述。
具体的,如图4所示,SQL执行计划的确定装置包括:获取单元01、建立单元02和确定单元03。所述装置用于在第N次迭代中,
其中,获取单元01,用于获取在第N-1次迭代中对所述至少一个关系表执行第一计划树后产生的第一迭代参数,其中N为大于1的自然数;
建立单元02,用于根据所述第一迭代参数建立第二计划树;
确定单元03,用于当所述第二计划树与所述第一计划树的差异不大于第一阈值时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划。
示例性的,所述第一阈值为0,对应的,所述当所述第二计划树与所述第一计划树的差异不大于第一阈值时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划,包括,当所述第二计划树与所述第一计划树相同时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划。
示例性的,所述第一迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
示例性的,所述SQL执行计划对应至少两个关系表时,所述第一迭代参数还包括所述至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
进一步地,如图5所示,所述装置还包括:
执行单元04,用于执行所述第二计划树;
记录单元05,用于记录执行所述第二计划树时产生的第二迭代 参数。
示例性的,所述记录单元05还用于记录该SQL执行计划为确定状态。
示例性的,所述第二迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
示例性的,所述SQL执行计划对应至少两个关系表时,所述第二迭代参数还包括所述至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
进一步地,如图6所示,所述装置还包括:
更新单元06,用于当所述第二计划树与所述第一计划树的差异大于第一阈值时,根据所述第二迭代参数更新所述第一迭代参数;将所述第N次迭代中的第二计划树作为第N+1次迭代中的第一计划树。
进一步地,所述建立单元02,具体用于当该第二迭代参数与该第一迭代参数相同时,根据所述第一迭代参数建立与所述第一计划树不相同的第二计划树。
进一步地,所述记录单元05,还用于记录执行所述第二计划树时的执行时间。
所述确定单元03,还用于当所述迭代次数N大于第二阈值时,将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划。
所述确定单元03,还用于当所述迭代次数N大于第三阈值时,将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划。
进一步地,所述记录单元05,还用于记录该SQL执行计划为确定状态。
进一步地,所述建立单元02,还用于在初始迭代执行时,根据预先存储的估算迭代参数建立初始计划树;
所述执行单元04,还用于执行所述初始计划树,得到执行所述 初始计划树时产生的初始迭代参数;
所述更新单元05,还用于使用所述初始迭代参数更新所述估算迭代参数,得到所述第一迭代参数。
进一步地,如图7所示,所述装置还包括查询单元08,其中,
所述查询单元07,用于查询该SQL执行计划的状态是否为该确定状态;
所述确定单元03,还用于当该SQL执行计划的状态为该确定状态时,执行所述SQL执行计划。
进一步地,所述更新单元06,具体用于将所述第二迭代参数和所述第一迭代参数取并集,将所述并集的结果作为所述第一迭代参数。
如图8所示,图4-图7中所示的SQL执行计划的确定装置可以以图8中的计算机设备(或系统)的方式来实现。
图8所示为本发明实施例提供的计算机设备100的示意图。计算机设备100包括至少一个处理器11,通信总线12,存储器13以及至少一个通信接口14。
存储器13用于存储计算机执行指令,处理器11与存储器13通过总线12连接,当SQL执行计划的确定装置运行时,处理器11执行存储器13存储的计算机执行指令,以使SQL执行计划的确定装置执行如图1-图3中任一项的SQL执行计划的确定方法。
其中,上述获取单元01、建立单元02、确定单元03、执行单元04、记录单元05、更新单元06和查询单元07的具体功能均可以由计算机设备100内的处理器11调用存储器13内的计算机指令实现。
处理器11可以是一个通用中央处理器(CPU),微处理器,特定应用集成电路(application-specific integrated circuit,ASIC),或一个或多个用于控制本发明方案程序执行的集成电路。
通信总线12可包括一通路,在上述组件之间传送信息。所述通信接口14,使用任何收发器一类的装置,用于与其他设备或通信网 络通信,如以太网,无线接入网(RAN),无线局域网(Wireless Local Area Networks,WLAN)等。
存储器13可以是只读存储器(read-onlymemory,ROM)或可存储静态信息和指令的其他类型的静态存储设备,随机存取存储器(random access memory,RAM)或者可存储信息和指令的其他类型的动态存储设备,也可以是电可擦可编程只读存储器(Electrically Erasable Programmable Read-Only Memory,EEPROM)、只读光盘(Compact Disc Read-Only Memory,CD-ROM)或其他光盘存储、光碟存储(包括压缩光碟、激光碟、光碟、数字通用光碟、蓝光光碟等)、磁盘存储介质或者其他磁存储设备、或者能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其他介质,但不限于此。存储器13可以是独立存在,通过总线与处理器相连接。存储器13也可以和处理器集成在一起。
其中,所述存储器13用于存储执行本发明方案的应用程序代码,并由处理器11来控制执行。所述处理器11用于执行所述存储器13中存储的应用程序代码。
在具体实现中,作为一种实施例,处理器11可以包括一个或多个CPU,例如图8中的CPU0和CPU1。
在具体实现中,作为一种实施例,计算机设备100可以包括多个处理器,例如图8中的处理器11和处理器18。这些处理器中的每一个可以是一个单核(single-CPU)处理器,也可以是一个多核(multi-CPU)处理器。这里的处理器可以指一个或多个设备、电路、和/或用于处理数据(例如计算机程序指令)的处理核。
在具体实现中,作为一种实施例,计算机设备100还可以包括输出设备15和输入设备16。输出设备15和处理器11通信,可以以多种方式来显示信息。例如,输出设备15可以是液晶显示器(liquid crystal display,LCD),发光二级管(light emitting diode,LED)显示设备,阴极射线管(cathode ray tube,CRT)显示设备,或投影仪(projector)等。输入设备16和处理器11通信, 可以以多种方式接受用户的输入。例如,输入设备16可以是鼠标、键盘、触摸屏设备或传感设备等。
上述的计算机设备100可以是一个通用计算机设备或者是一个专用计算机设备。在具体实现中,计算机设备100可以是台式机、便携式电脑、网络服务器、掌上电脑(Personal Digital Assistant,PDA)、移动手机、平板电脑、无线终端设备、通信设备、嵌入式设备或有图8中类似结构的设备。本发明实施例不限定计算机设备100的类型。
本发明的实施例提供一种SQL执行计划的确定方法,以第N次迭代过程为例,首先,获取在第N-1次迭代时更新后的第一迭代参数,示例性的,该第一迭代参数包括第一特征值和/或第二特征值,第一特征值用于指示第i个关系表的元组数,第二特征值用于指示至少两个关系表经过连接操作后得到的结果集中元组的个数;然后,使用该第一迭代参数建立第二计划树;当第二计划树与第一计划树相同时,则将第二计划树作为该SQL执行计划。本方案中最终得到的第二计划树并不是依赖于数据库内已统计的估算迭代参数,而是以迭代过程中更新后的第一迭代参数为依据建立的,进而当第二计划树与第一计划树相同时,将第二计划树作为SQL执行计划,可较为准确的确定出SQL执行计划,提高SQL执行计划的执行效率。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单 元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器(processor)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。

Claims (43)

  1. 一种结构化查询语言SQL执行计划的确定方法,所述SQL执行计划对应至少一个关系表,其特征在于,在第N次迭代中,包括:
    获取在第N-1次迭代中对所述至少一个关系表执行第一计划树后产生的第一迭代参数,其中N为大于1的自然数;
    根据所述第一迭代参数建立第二计划树;
    当所述第二计划树与所述第一计划树的差异不大于第一阈值时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划。
  2. 根据权利要求1所述的方法,其特征在于,所述第一阈值为0,对应的,所述当所述第二计划树与所述第一计划树的差异不大于第一阈值时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划,包括:当所述第二计划树与所述第一计划树相同时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划。
  3. 根据权利要求1或2所述的方法,其特征在于,所述第一迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
  4. 根据权利要求1-3任一项所述的方法,其特征在于,所述SQL执行计划对应至少两个关系表时,所述第一迭代参数还包括所述至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
  5. 根据权利要求1-4任一项所述的方法,其特征在于,在所述将所述第一计划树或所述第二计划树确定为所述SQL执行计划之后,还包括:
    记录所述SQL执行计划为确定状态。
  6. 根据权利要求1-5任一项所述的方法,其特征在于,在所述根据所述第一迭代参数建立第二计划树之后,还包括:
    执行所述第二计划树;
    记录执行所述第二计划树时产生的第二迭代参数。
  7. 根据权利要求6所述的方法,其特征在于,所述第二迭代参 数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
  8. 根据权利要求6或7所述的方法,其特征在于,所述SQL执行计划对应至少两个关系表时,所述第二迭代参数还包括所述至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
  9. 根据权利要求6-8任一项所述的方法,其特征在于,所述方法还包括:
    当所述第二计划树与所述第一计划树的差异大于第一阈值时,根据所述第二迭代参数更新所述第一迭代参数;
    将所述第N次迭代中的第二计划树作为第N+1次迭代中的第一计划树。
  10. 根据权利要求9所述的方法,其特征在于,在所述根据所述第二迭代参数更新所述第一迭代参数之前,还包括:
    当所述第二迭代参数与所述第一迭代参数相同时,根据所述第一迭代参数建立与所述第一计划树不相同的第二计划树。
  11. 根据权利要求10所述的方法,其特征在于,在所述根据所述第一迭代参数建立与所述第一计划树不相同的第二计划树之后,还包括:
    记录执行所述第二计划树的执行时间;
    当所述N大于第二阈值时,将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划。
  12. 根据权利要求11所述的方法,其特征在于,在所述将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划之后,还包括:
    记录所述SQL执行计划为确定状态。
  13. 根据权利要求9所述的方法,其特征在于,在所述根据所述第二迭代参数更新所述第一迭代参数之前,还包括:
    记录执行所述第二计划树的执行时间;
    当所述N大于第三阈值时,将全部N次迭代中所述执行时间最短 的第二计划树作为所述SQL执行计划。
  14. 根据权利要求13所述的方法,其特征在于,在所述将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划之后,还包括:
    记录所述SQL执行计划为确定状态。
  15. 根据权利要求8-14任一项所述的方法,其特征在于,所述根据所述第二迭代参数更新所述第一迭代参数,包括:
    将所述第二迭代参数和所述第一迭代参数取并集,将所述并集的结果作为所述第一迭代参数。
  16. 根据权利要求1-15中任一项所述的方法,其特征在于,所述方法还包括:
    在初始迭代执行时,根据预先存储的估算迭代参数建立初始计划树;
    执行所述初始计划树得到初始迭代参数;
    根据所述初始迭代参数更新所述估算迭代参数,得到所述第一迭代参数。
  17. 根据权利要求16所述的方法,其特征在于,所述估算迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
  18. 根据权利要求16或17所述的方法,其特征在于,所述初始迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
  19. 根据权利要求16-18任一项所述的方法,其特征在于,所述SQL执行计划对应至少两个关系表时,所述初始迭代参数还包括所述至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
  20. 根据权利要求16-19任一项所述的方法,其特征在于,所述根据所述初始迭代参数更新所述估算迭代参数,得到所述第一迭代参数,包括:
    将所述初始迭代参数和所述估算迭代参数取并集,将所述并集的 结果作为所述第一迭代参数。
  21. 根据权利要求16-20任一项所述的方法,其特征在于,在所述初始迭代执行之前,还包括:
    查询所述SQL执行计划的状态是否为所述确定状态;
    当所述SQL执行计划的状态为所述确定状态时,执行所述SQL执行计划。
  22. 一种结构化查询语言SQL执行计划的确定装置,所述SQL执行计划对应至少一个关系表,其特征在于,所述装置包括:存储器和耦合于存储器的处理器,在第N次迭代中:
    所述处理器用于获取在第N-1次迭代中对所述至少一个关系表执行第一计划树后产生的第一迭代参数,其中N为大于1的自然数;
    根据所述第一迭代参数建立第二计划树;
    当所述第二计划树与所述第一计划树的差异不大于第一阈值时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划。
  23. 根据权利要求22所述的装置,其特征在于,所述第一阈值为0,对应的,所述当所述第二计划树与所述第一计划树的差异不大于第一阈值时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划,包括,当所述第二计划树与所述第一计划树相同时,将所述第一计划树或所述第二计划树确定为所述SQL执行计划。
  24. 根据权利要求22或23所述的装置,其特征在于,所述第一迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
  25. 根据权利要求22-24任一项所述的装置,其特征在于,所述SQL执行计划对应至少两个关系表时,所述第一迭代参数还包括所述至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
  26. 根据权利要求22-25任一项所述的装置,其特征在于,在所述将所述第一计划树或所述第二计划树确定为所述SQL执行计划之后,所述处理器还用于:
    记录所述SQL执行计划为确定状态。
  27. 根据权利要求22-26任一项所述的装置,其特征在于,在所述根据所述第一迭代参数建立第二计划树之后,所述处理器还用于:
    执行所述第二计划树;
    记录执行所述第二计划树时产生的第二迭代参数。
  28. 根据权利要求27所述的装置,其特征在于,所述第二迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
  29. 根据权利要求27或28所述的装置,其特征在于,所述SQL执行计划对应至少两个关系表时,所述第二迭代参数还包括所述至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
  30. 根据权利要求27-29任一项所述的装置,其特征在于,所述处理器还用于:
    当所述第二计划树与所述第一计划树的差异大于第一阈值时,根据所述第二迭代参数更新所述第一迭代参数;
    将所述第N次迭代中的第二计划树作为第N+1次迭代中的第一计划树。
  31. 根据权利要求30所述的装置,其特征在于,在所述根据所述第二迭代参数更新所述第一迭代参数之前,所述处理器还用于:
    当所述第二迭代参数与所述第一迭代参数相同时,根据所述第一迭代参数建立与所述第一计划树不相同的第二计划树。
  32. 根据权利要求31所述的装置,其特征在于,在所述根据所述第一迭代参数建立与所述第一计划树不相同的第二计划树之后,所述处理器还用于:
    记录执行所述第二计划树的执行时间;
    当所述N大于第二阈值时,将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划。
  33. 根据权利要求32所述的装置,其特征在于,在所述将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划之 后,所述处理器还用于:
    记录所述SQL执行计划为确定状态。
  34. 根据权利要求30所述的装置,其特征在于,在所述根据所述第二迭代参数更新所述第一迭代参数之前,所述处理器还用于:
    记录执行所述第二计划树的执行时间;
    当所述N大于第三阈值时,将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划。
  35. 根据权利要求34所述的装置,其特征在于,在所述将全部N次迭代中所述执行时间最短的第二计划树作为所述SQL执行计划之后,所述处理器还用于:
    记录所述SQL执行计划为确定状态。
  36. 根据权利要求29-35任一项所述的装置,其特征在于,所述处理器具体用于:
    将所述第二迭代参数和所述第一迭代参数取并集,将所述并集的结果作为所述第一迭代参数。
  37. 根据权利要求22-36中任一项所述的装置,其特征在于,所述处理器还用于:
    在初始迭代执行时,根据预先存储的估算迭代参数建立初始计划树;
    执行所述初始计划树得到初始迭代参数;
    根据所述初始迭代参数更新所述估算迭代参数,得到所述第一迭代参数。
  38. 根据权利要求37所述的装置,其特征在于,所述估算迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
  39. 根据权利要求37或38所述的装置,其特征在于,所述初始迭代参数包括所述SQL执行计划对应的任意一个或多个关系表的元组数。
  40. 根据权利要求37-39任一项所述的装置,其特征在于,所述SQL执行计划对应至少两个关系表时,所述初始迭代参数还包括所述 至少两个关系表中任意一个或多个至少两个关系表经过连接操作后得到的结果集合中的元组数。
  41. 根据权利要求37-40任一项所述的装置,其特征在于,所述处理器具体用于:
    将所述初始迭代参数和所述估算迭代参数取并集,将所述并集的结果作为所述第一迭代参数。
  42. 根据权利要求37-41任一项所述的装置,其特征在于,在所述初始迭代执行之前,所述处理器还用于:
    查询所述SQL执行计划的状态是否为所述确定状态;
    当所述SQL执行计划的状态为所述确定状态时,执行所述SQL执行计划。
  43. 一种结构化查询语言SQL执行计划的确定装置,其特征在于,包括:处理器、存储器、总线和通信接口;
    所述存储器用于存储计算机执行指令,所述处理器与所述存储器通过所述总线连接,当所述确定装置运行时,所述处理器执行所述存储器存储的所述计算机执行指令,以使所述确定装置执行如权利要求1-21中任意一项所述SQL执行计划的确定方法。
PCT/CN2016/090222 2016-02-19 2016-07-15 一种sql执行计划的确定方法及装置 WO2017140085A1 (zh)

Priority Applications (4)

Application Number Priority Date Filing Date Title
JP2017518519A JP6415708B2 (ja) 2016-02-19 2016-07-15 Sql実行計画を決定するための方法および装置
EP16840285.7A EP3232339B1 (en) 2016-02-19 2016-07-15 Method and device for determining sql execution plan
RU2017113685A RU2674886C2 (ru) 2016-02-19 2016-07-15 Способ и устройство для определения плана исполнения sql
US15/495,569 US10901976B2 (en) 2016-02-19 2017-04-24 Method and apparatus for determining SQL execution plan

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610095091.0 2016-02-19
CN201610095091.0A CN107102995B (zh) 2016-02-19 2016-02-19 一种sql执行计划的确定方法及装置

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US15/495,569 Continuation US10901976B2 (en) 2016-02-19 2017-04-24 Method and apparatus for determining SQL execution plan

Publications (1)

Publication Number Publication Date
WO2017140085A1 true WO2017140085A1 (zh) 2017-08-24

Family

ID=59625589

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/090222 WO2017140085A1 (zh) 2016-02-19 2016-07-15 一种sql执行计划的确定方法及装置

Country Status (6)

Country Link
US (1) US10901976B2 (zh)
EP (1) EP3232339B1 (zh)
JP (1) JP6415708B2 (zh)
CN (1) CN107102995B (zh)
RU (1) RU2674886C2 (zh)
WO (1) WO2017140085A1 (zh)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10558668B2 (en) 2016-07-01 2020-02-11 International Business Machines Corporation Result set output criteria
CN108197187B (zh) * 2017-12-26 2020-06-16 金蝶软件(中国)有限公司 查询语句的优化方法、装置、存储介质和计算机设备
CN108733789B (zh) * 2018-05-11 2021-11-19 北京奥星贝斯科技有限公司 数据库操作指令的执行计划演进方法、装置以及设备
CN109876445B (zh) * 2019-01-11 2022-08-09 珠海金山网络游戏科技有限公司 一种基于行为树的高解耦引导方法及系统
CN113849520B (zh) * 2021-09-30 2024-05-28 平安科技(深圳)有限公司 异常sql的智能识别方法、装置、电子设备及存储介质

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060212429A1 (en) * 2005-03-17 2006-09-21 Microsoft Corporation Answering top-K selection queries in a relational engine
CN101576880A (zh) * 2008-05-06 2009-11-11 山东省标准化研究院 基于极值优化的数据库查询优化方法
CN103793467A (zh) * 2013-09-10 2014-05-14 浙江鸿程计算机系统有限公司 一种基于超图和动态规划的大数据实时查询优化方法

Family Cites Families (54)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH05334368A (ja) * 1992-06-02 1993-12-17 Hitachi Ltd データベース問合せ処理方法
US5671403A (en) * 1994-12-30 1997-09-23 International Business Machines Corporation Iterative dynamic programming system for query optimization with bounded complexity
US5608904A (en) 1995-02-13 1997-03-04 Hewlett-Packard Company Method and apparatus for processing and optimizing queries having joins between structured data and text data
US6487547B1 (en) * 1999-01-29 2002-11-26 Oracle Corporation Database appliance comprising hardware and software bundle configured for specific database applications
JP2001142898A (ja) * 1999-11-16 2001-05-25 Hitachi Ltd 問合せ処理の実行可否判定方法
US7398221B1 (en) * 2001-03-30 2008-07-08 Rapt, Inc. Method and apparatus for component plan analysis under uncertainty
US7107262B2 (en) * 2003-02-20 2006-09-12 International Business Machines Corporation Incremental data query performance feedback model
JP2005018430A (ja) * 2003-06-26 2005-01-20 Ntt Data Corp データベース管理システム及び問い合わせ最適化方法
US8825629B2 (en) * 2003-09-06 2014-09-02 Oracle International Corporation Method for index tuning of a SQL statement, and index merging for a multi-statement SQL workload, using a cost-based relational query optimizer
US7353219B2 (en) * 2004-05-28 2008-04-01 International Business Machines Corporation Determining validity ranges of query plans based on suboptimality
US7831592B2 (en) * 2004-10-29 2010-11-09 International Business Machines Corporation System and method for updating database statistics according to query feedback
US8161038B2 (en) * 2004-10-29 2012-04-17 International Business Machines Corporation Maintain optimal query performance by presenting differences between access plans
US7610264B2 (en) * 2005-02-28 2009-10-27 International Business Machines Corporation Method and system for providing a learning optimizer for federated database systems
RU2409848C2 (ru) * 2005-10-28 2011-01-20 Медиарайф Местль Унд Райф Коммуникационс-Унд Информационстехнологиен Оег Способ управления системой реляционной базы данных
US7877381B2 (en) * 2006-03-24 2011-01-25 International Business Machines Corporation Progressive refinement of a federated query plan during query execution
JP2007293723A (ja) * 2006-04-26 2007-11-08 Hitachi Information Systems Ltd データベース管理システム及び管理方法
US7877373B2 (en) * 2006-06-30 2011-01-25 Oracle International Corporation Executing alternative plans for a SQL statement
US7739269B2 (en) * 2007-01-19 2010-06-15 Microsoft Corporation Incremental repair of query plans
US20080201295A1 (en) * 2007-02-21 2008-08-21 Mylavarapu Praveena Caching plans with using data values
DE602007002474D1 (de) * 2007-04-27 2009-10-29 Software Ag Verfahren und Datenbanksystem zur Durchführung einer XML-Datenbankabfrage
US7941425B2 (en) * 2007-07-25 2011-05-10 Teradata Us, Inc. Techniques for scoring and comparing query execution plans
US9189522B2 (en) * 2007-10-17 2015-11-17 Oracle International Corporation SQL execution plan baselines
US10983998B2 (en) * 2008-06-25 2021-04-20 Microsoft Technology Licensing, Llc Query execution plans by compilation-time execution
US8775413B2 (en) * 2008-06-30 2014-07-08 Teradata Us, Inc. Parallel, in-line, query capture database for real-time logging, monitoring and optimizer feedback
US7974213B2 (en) * 2008-11-21 2011-07-05 At&T Intellectual Property I, L.P. Methods and apparatus to select composite link cost-out thresholds
US8311863B1 (en) * 2009-02-24 2012-11-13 Accenture Global Services Limited Utility high performance capability assessment
US8185519B2 (en) * 2009-03-14 2012-05-22 Microsoft Corporation Techniques for exact cardinality query optimization
US8380699B2 (en) * 2009-09-04 2013-02-19 Hewlett-Packard Development Company, L.P. System and method for optimizing queries
CN102053961A (zh) * 2009-10-27 2011-05-11 中兴通讯股份有限公司 Sql语句的检验方法、装置及提高数据库可靠性的系统
US20110161310A1 (en) * 2009-12-30 2011-06-30 Wei Tang Database query plan analysis and difference processing
CN102262636B (zh) * 2010-05-25 2012-10-10 中国移动通信集团浙江有限公司 生成数据库分区执行计划的方法及装置
US8898146B2 (en) * 2010-09-22 2014-11-25 Hewlett-Packard Development Company, L.P. System and method for comparing database query plans
WO2013049715A1 (en) * 2011-09-29 2013-04-04 Cirro, Inc. Federated query engine for federation of data queries across structure and unstructured data
US8417689B1 (en) * 2011-11-21 2013-04-09 Emc Corporation Programming model for transparent parallelization of combinatorial optimization
US9002813B2 (en) * 2011-12-22 2015-04-07 Sap Se Execution plan preparation in application server
US8924373B2 (en) * 2012-08-09 2014-12-30 International Business Machines Corporation Query plans with parameter markers in place of object identifiers
US9720966B2 (en) * 2012-12-20 2017-08-01 Teradata Us, Inc. Cardinality estimation for optimization of recursive or iterative database queries by databases
US9146960B2 (en) * 2012-12-20 2015-09-29 Teradata Us, Inc. Adaptive optimization of iterative or recursive query execution by database systems
CN103092970A (zh) * 2013-01-24 2013-05-08 华为技术有限公司 一种数据库操作方法及设备
US9576026B2 (en) * 2013-03-13 2017-02-21 Futurewei Technologies, Inc. System and method for distributed SQL join processing in shared-nothing relational database clusters using self directed data streams
US10268724B2 (en) * 2013-03-15 2019-04-23 Teradata Us, Inc. Techniques for improving the performance of complex queries
US20160253366A1 (en) * 2013-10-15 2016-09-01 Hewlett Packard Enterprise Development Lp Analyzing a parallel data stream using a sliding frequent pattern tree
US9996601B2 (en) * 2013-11-14 2018-06-12 Empire Technology Development Llc Data synchronization
CN103761080B (zh) * 2013-12-25 2017-02-15 中国农业大学 一种基于SQL的MapReduce作业生成方法及系统
CN103984726B (zh) * 2014-05-16 2017-03-29 上海新炬网络信息技术有限公司 一种数据库执行计划的局部修正方法
CN105243068A (zh) * 2014-07-09 2016-01-13 华为技术有限公司 数据库系统的查询方法、服务器和能耗测试系统
US9864740B2 (en) * 2015-02-05 2018-01-09 Ciena Corporation Methods and systems for creating and applying a template driven element adapter
US20160246842A1 (en) * 2015-02-25 2016-08-25 Futurewei Technologies, Inc. Query optimization adaptive to system memory load for parallel database systems
US10115116B2 (en) * 2015-03-02 2018-10-30 Microsoft Technology Licensing, Llc Optimizing efficiency and cost of crowd-sourced polling
US10180978B2 (en) * 2015-03-19 2019-01-15 Sap Se Interface providing decision support in complex problem environment
US10585887B2 (en) * 2015-03-30 2020-03-10 Oracle International Corporation Multi-system query execution plan
US9916353B2 (en) * 2015-04-01 2018-03-13 International Business Machines Corporation Generating multiple query access plans for multiple computing environments
US10108664B2 (en) * 2015-04-01 2018-10-23 International Business Machines Corporation Generating multiple query access plans for multiple computing environments
US10216793B2 (en) * 2015-11-03 2019-02-26 Sap Se Optimization of continuous queries in hybrid database and stream processing systems

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060212429A1 (en) * 2005-03-17 2006-09-21 Microsoft Corporation Answering top-K selection queries in a relational engine
CN101576880A (zh) * 2008-05-06 2009-11-11 山东省标准化研究院 基于极值优化的数据库查询优化方法
CN103793467A (zh) * 2013-09-10 2014-05-14 浙江鸿程计算机系统有限公司 一种基于超图和动态规划的大数据实时查询优化方法

Also Published As

Publication number Publication date
EP3232339A1 (en) 2017-10-18
EP3232339A4 (en) 2018-03-07
JP6415708B2 (ja) 2018-10-31
EP3232339B1 (en) 2019-02-27
CN107102995B (zh) 2020-02-21
CN107102995A (zh) 2017-08-29
JP2018509666A (ja) 2018-04-05
RU2017113685A (ru) 2018-10-23
US20170242884A1 (en) 2017-08-24
RU2017113685A3 (zh) 2018-10-23
RU2674886C2 (ru) 2018-12-13
US10901976B2 (en) 2021-01-26

Similar Documents

Publication Publication Date Title
US11550769B2 (en) Data processing method, apparatus, and system
WO2017140085A1 (zh) 一种sql执行计划的确定方法及装置
US10133778B2 (en) Query optimization using join cardinality
US10534775B2 (en) Cardinality estimation for database query planning
US10585887B2 (en) Multi-system query execution plan
WO2019085087A1 (zh) 接口测试及测试数据生成方法、装置、终端和存储介质
EP3173944B1 (en) Database access method and apparatus and database system
WO2016134580A1 (zh) 一种数据查询方法及装置
US10599652B2 (en) Database query time estimator
US11366808B2 (en) Query processing method, data source registration method, and query engine
US11132366B2 (en) Transforming directed acyclic graph shaped sub plans to enable late materialization
US10783143B2 (en) Computing columnar information during join enumeration
US20170371922A1 (en) Database Management for Mobile Devices
Liang et al. Mid-model design used in model transition and data migration between relational databases and nosql databases
US9734177B2 (en) Index merge ordering
CN111897824A (zh) 数据操作方法、装置、设备和存储介质
WO2023231615A1 (zh) 一种基于数据湖的物化列创建方法以及数据查询方法
US10789249B2 (en) Optimal offset pushdown for multipart sorting
CN109753533A (zh) 一种多源关系型数据库客户端开发方法及装置
JP6034240B2 (ja) 分析方法、分析装置および分析プログラム
CN108073584B (zh) 一种数据处理方法及服务器
CN114416784B (zh) 处理数据库查询语句的方法、装置及原生分布式数据库
US11803545B1 (en) Runtime statistics feedback for query plan cost estimation
CN112732704B (zh) 一种数据处理方法、装置及存储介质
CN115563148A (zh) 数据库查询方法和装置

Legal Events

Date Code Title Description
REEP Request for entry into the european phase

Ref document number: 2016840285

Country of ref document: EP

WWE Wipo information: entry into national phase

Ref document number: 2016840285

Country of ref document: EP

ENP Entry into the national phase

Ref document number: 2017518519

Country of ref document: JP

Kind code of ref document: A

ENP Entry into the national phase

Ref document number: 2017113685

Country of ref document: RU

Kind code of ref document: A

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16840285

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE