Structured query statement reuse method, device, electronic device and medium
By filtering, optimizing, vectorizing representation and clustering to process structured query statements, combined with graph convolutional neural network and enhanced index selection model, the problem of low SQL template reuse efficiency and unreasonable query index selection in the existing technology is solved. Efficient query performance and load reduction are achieved.
Patent Information
- Application Number
- CN202410154540.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-02
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-02-02
AI Technical Summary
When using SQL templates to reuse structured query statements, the existing technology increases query complexity and parsing steps, resulting in reduced execution efficiency of the data warehouse and increased resource load, and the feature vectors extracted by the long-short-term memory recursive neural network cause query The execution order is wrong, the time cost estimation accuracy is low, and the heuristic algorithm selects a single or fixed query index and ignores interactive relationships, resulting in high load and low user experience.
By obtaining the structured query statement set, filtering statements that meet preset conditions, performing statement optimization processing, vectorization representation, clustering processing, hash storage, optimizing query execution logic and result groups, using graph convolutional neural networks and attention The mechanism extracts features, strengthens the index selection model, considers the interactive relationship between query indexes, and optimizes query statements.
It reduces the data warehouse's repeated execution of similar query operations, improves query efficiency and accuracy, shortens the query time, reduces the data warehouse load, and improves the user experience.
Smart Images

Figure CN118069122B
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the field of computer technology, and in particular to a structured query statement reuse method, device, electronic device, and medium. Background Art
[0002] SQL (Structured Query Language) statements are a database language used to operate data in a data warehouse. Currently, with the rapid development of the Internet, a large amount of data is generated every day. Fast and efficient querying of data stored in data warehouses has become an urgent problem to be solved. For the reuse of structured query statements, the commonly used method is to use SQL templates to achieve the reuse of structured query statements.
[0003] However, it is found in practice that when the above method is used to operate log files, the following technical problems often occur: the reuse of SQL statements through SQL templates will increase the complexity of queries and additional parsing steps, and because the SQL model is an SQL statement containing placeholders, the scope of SQL statements involved is relatively single. If all SQL statements are to be covered, the storage resources of the data warehouse will be wasted, resulting in a decrease in the execution efficiency of the data warehouse and an increase in the load on the data warehouse resources.
[0004] In the process of using technical solutions to solve the above technical problem 1, the following technical problem 2 is often accompanied: because the feature vector extracted by the long short-term memory recursive neural network will cause errors in the execution order of the query execution logic, the execution nodes that were originally unrelated will be executed in a forward and backward order after feature extraction, resulting in the loss of structural information and low accuracy of time cost estimation, and because the heuristic algorithm is used to select structured query statements, it often selects a single query index or a fixed query index, ignoring the change of the query index, and not considering the interactive relationship between the query indexes, resulting in a high load on the data warehouse to execute structured query statements, a long query time and a low user experience. For the above technical problem 2, the conventional solution is generally: use the long short-term memory recursive neural network to extract the structural information of the query execution logic, obtain the time cost value of the structured query statement, and use the heuristic algorithm to determine the optimal query index of the structured query statement according to the time cost value. However, the above conventional solutions still have the following problems: since the feature vectors extracted by the long short-term memory recursive neural network will cause errors in the execution order of the query execution logic, the execution nodes that were originally unrelated will be executed in a forward and backward order after the feature extraction, resulting in the loss of structural information and low accuracy of time cost estimation. In addition, since the heuristic algorithm is used to select structured query statements, a single query index or a fixed query index is often selected, ignoring the changes in the query index, and not considering the interactive correlation between the query indexes, the data warehouse executes the structured query statements with a high load, the query time is long and the user experience is low.
[0005] The above information disclosed in this Background section is only for enhancement of understanding of the background of the inventive concept and therefore it may contain information that does not form the prior art that is already known in this country to a person of ordinary skill in the art. Summary of the invention
[0006] The content of this disclosure is used to introduce concepts in a brief form, which will be described in detail in the detailed implementation section below. The content of this disclosure is not intended to identify the key features or essential features of the technical solution claimed for protection, nor is it intended to limit the scope of the technical solution claimed for protection.
[0007] Some embodiments of the present disclosure propose a structured query statement reuse method, device, electronic device, and medium to solve one or more of the technical problems mentioned in the above background technology section.
[0008] In a first aspect, some embodiments of the present disclosure provide a structured query statement reuse method, comprising: obtaining a structured query statement set; screening out at least one structured query statement that meets a preset condition from the structured query statement set to obtain a target structured query statement set, wherein the preset condition is that the number of executions of the structured query statement within a preset time is greater than or equal to a preset execution threshold; determining whether the target structured query statement set meets a statement optimization condition; in response to determining that there is at least one target structured query statement that meets the statement optimization condition in the target structured query statement set, performing statement optimization processing on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set; vectorizing each target query statement in the target query statement set to generate a query feature vector to obtain a query feature vector set. , wherein the target query statement set is a query statement set consisting of the optimized query statement set and the remaining structured query statement set, and the remaining structured query statement set is a query statement set after removing the optimized query statement set from the target structured query statement set; query statement clustering is performed on the target query statement set according to the query feature vector set to obtain a query statement cluster set; the query execution logic and query result group of each query statement cluster in the query statement cluster set are determined to obtain a query execution logic set and a query result group set; the query execution logic set and the query result group set are hashed and stored; and in response to detecting the structured query statement set to be executed sent by the client, the query execution logic set and the query result group set are reused to obtain the query result to be executed of each structured query statement to be executed in the structured query statement set to be executed.
[0009] In a second aspect, some embodiments of the present disclosure provide a structured query statement reuse device, comprising: an acquisition unit, configured to acquire a structured query statement set; a screening unit, configured to screen out at least one structured query statement that meets a preset condition from the above structured query statement set, and obtain a target structured query statement set, wherein the above preset condition is that the number of executions of the structured query statement within a preset time is greater than or equal to a preset execution threshold; a first determination unit, configured to determine whether the above target structured query statement set meets a statement optimization condition; a statement optimization unit, configured to perform statement optimization processing on each target structured query statement in the above at least one target structured query statement in response to determining that there is at least one target structured query statement that meets the statement optimization condition in the above target structured query statement set, and obtain an optimized query statement set; a vectorization representation unit, configured to perform vectorization representation on each target query statement in the target query statement set to generate a query feature vector, A query feature vector set is obtained, wherein the target query statement set is a query statement set consisting of the optimized query statement set and the remaining structured query statement set, and the remaining structured query statement set is a query statement set after the optimized query statement set is removed from the target structured query statement set; a query statement clustering unit is configured to perform query statement clustering processing on the target query statement set according to the query feature vector set to obtain a query statement class cluster set; a second determination unit is configured to determine the query execution logic and query result group of each query statement class cluster in the query statement class cluster set to obtain a query execution logic set and a query result group set; a reuse unit is configured to hash and store the query execution logic set and the query result group set, and in response to detecting the structured query statement set to be executed sent by the client, reuse the query execution logic set and the query result group set to obtain the query result to be executed of each structured query statement to be executed in the structured query statement set to be executed.
[0010] In a third aspect, some embodiments of the present disclosure provide an electronic device comprising: one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any implementation manner in the first aspect.
[0011] In a fourth aspect, some embodiments of the present disclosure provide a computer-readable medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method described in any implementation manner in the first aspect is implemented.
[0012] The above-mentioned embodiments of the present disclosure have the following beneficial effects: the structured query statement reuse method of some embodiments of the present disclosure can reduce the repeated execution of similar query operations in the data warehouse, improve query efficiency and accuracy, shorten query time, and reduce load. Specifically, the reasons for the reduction of the execution efficiency of the relevant data warehouse and the increase of the load of the data warehouse resources are: the reuse of SQL statements through SQL templates will increase the complexity of the query and the additional parsing steps, and because the SQL model is an SQL statement containing placeholders, the scope of the SQL statements involved is relatively single. If all SQL statements are to be covered, the waste of storage resources of the data warehouse will be increased, resulting in the reduction of the execution efficiency of the data warehouse and the increase of the load of the data warehouse resources. Based on this, the structured query statement reuse method of some embodiments of the present disclosure can first obtain a structured query statement set. Here, the structured query statement set is used to subsequently determine the target structured query statement set for repeated execution. Secondly, at least one structured query statement that meets the preset condition is selected from the above structured query statement set to obtain the target structured query statement set, wherein the above preset condition is the condition that the number of executions of the structured query statement within the preset time is greater than or equal to the preset execution threshold. Here, the target structured query statement set is used for the reuse of subsequent query execution logic and query result group. Again, determine whether the target structured query statement set meets the conditions for statement optimization. Here, it is used to judge the execution efficiency of the target structured query statement so as to improve the performance of the target structured query statement and reduce the query execution time and data warehouse resource consumption. Then, in response to determining that there is at least one target structured query statement that meets the conditions for statement optimization in the target structured query statement set, perform statement optimization processing on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set. Here, the optimization processing can improve the execution efficiency and query performance of the structured query statement and reduce the load of the data warehouse. Subsequently, each target query statement in the target query statement set is vectorized to generate a query feature vector to obtain a query feature vector set, wherein the target query statement set is a query statement set composed of the optimized query statement set and the remaining structured query statement set, and the remaining structured query statement set is a query statement set after the optimized query statement set is removed from the target structured query statement set. Here, the vectorized representation of the target query statement can determine the similarity between each target query statement, so as to reduce the repeated execution of repeated structured query statements in the data warehouse, reduce the load and resource consumption of the data warehouse. Afterwards, based on the above query feature vector set, the above target query statement set is clustered to obtain a query statement class cluster set.Here, the query statement clustering process can directly reuse the query results or query execution logic in the cache when the data warehouse executes similar structured query statements again, without re-execution, reducing resource waste. Then, the query execution logic and query result group of each query statement cluster in the above query statement cluster set are determined to obtain a query execution logic set and a query result group set. Here, it is convenient for the subsequent data warehouse to execute similar structured query data and perform reuse, shorten the query time, and improve the query efficiency and the reuse rate of structured query statements. Finally, the query execution logic set and the query result group set are hashed and stored, and in response to detecting the structured query statement set to be executed sent by the client, the query execution logic set and the query result group set are reused to obtain the query results to be executed of each structured query statement to be executed in the structured query statement set to be executed. Here, the hash cache can be directly reused when a similar structured query statement is executed next time, reducing the execution of structured query statements by the data warehouse and improving query efficiency and accuracy. It can be concluded that the structured query statement reuse method can improve the query performance of structured query statements by optimizing and clustering structured query statements to achieve the reuse of structured query statements with high similarity. To a certain extent, it can reduce the repeated execution of similar query operations in the data warehouse, improve query efficiency and accuracy, shorten query time, and reduce the load on the data warehouse. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that components and elements are not necessarily drawn to scale.
[0014] Figure 1 is a flowchart of some embodiments of the structured query statement reuse method according to the present disclosure;
[0015] Figure 2 It is a schematic diagram of the structure of some embodiments of the structured query statement reuse device according to the present disclosure;
[0016] Figure 3 It is a schematic diagram of the structure of an electronic device suitable for implementing some embodiments of the present disclosure. DETAILED DESCRIPTION
[0017] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0018] It should also be noted that, for ease of description, only the parts related to the invention are shown in the drawings. In the absence of conflict, the embodiments and features in the embodiments of the present disclosure can be combined with each other.
[0019] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0020] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0021] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0022] The present disclosure will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
[0023] Figure 1 The process 100 of some embodiments of the structured query statement reuse method according to the present disclosure is shown. The structured query statement reuse method comprises the following steps:
[0024] Step 101: Obtain a structured query statement set.
[0025] In some embodiments, the execution subject (e.g., electronic device) of the structured query statement reuse method can obtain the structured query statement set through a wired connection or a wireless connection. The structured query statements in the structured query statement set can be historical SQL statements before the current time for querying and modifying data stored in the data warehouse.
[0026] Step 102: Screen out at least one structured query statement that meets a preset condition from the structured query statement set to obtain a target structured query statement set.
[0027] In some embodiments, the execution subject may filter out at least one structured query statement that meets a preset condition from the structured query statement set to obtain a target structured query statement set. The preset condition may be a condition that the number of executions of the structured query statement within a preset time period is greater than or equal to a preset execution threshold. The preset time period may be a preset time threshold. For example, the preset time period may be 1 hour. The preset execution threshold may be a preset execution threshold for repeated execution of the structured query statement.
[0028] As an example, the execution entity may utilize a data warehouse log analysis tool, an SQL audit tool, or a data warehouse performance monitoring tool to filter out at least one structured query statement that meets preset conditions from the structured query statement set to obtain a target structured query statement set.
[0029] Step 103: determine whether the target structured query statement set meets the statement optimization condition.
[0030] In some embodiments, the execution subject may determine whether the target structured query statement set satisfies the statement optimization condition. The statement optimization condition may be a condition for determining whether the target structured query statement needs to be optimized. The statement optimization condition may include but is not limited to at least one of the following: the structured query statement includes more than 3 data table connections and nested loop queries, all fields in the query data table, lack of partitioning of the data table, inefficient indexes that cause scanning of the entire data table or a large number of disk operations.
[0031] Step 104, in response to determining that there is at least one target structured query statement in the target structured query statement set that meets the statement optimization condition, statement optimization processing is performed on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set.
[0032] In some embodiments, the execution subject may, in response to determining that there is at least one target structured query statement in the target structured query statement set that satisfies the statement optimization condition, perform statement optimization processing on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set. The optimized query statements in the optimized query statement set may be query statements after improving the query performance of the structured query statements.
[0033] As an example, in response to determining that there is at least one target structured query statement in the target structured query statement set that meets the statement optimization condition, a dynamic programming algorithm is used to perform statement optimization processing on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set.
[0034] Considering that the conventional solution above uses the long short-term memory recursive neural network to extract the structural information of the query execution logic, obtains the time cost value of the structured query statement, and uses the heuristic algorithm to determine the optimal query index of the structured query statement according to the time cost value, facing the above technical problem 2: because the feature vector extracted by the long short-term memory recursive neural network will cause errors in the execution order of the query execution logic, the execution nodes that were originally unrelated will be executed in a forward and backward order after feature extraction, resulting in the loss of structural information and low accuracy of time cost estimation, and because the heuristic algorithm is often used to select a single query index or a fixed query index for the selection of structured query statements, ignoring the change of the query index, and not considering the interactive correlation between the query indexes, resulting in a high load on the data warehouse to execute structured query statements, a long query time and a low user experience. Combined with the current technical status, it can be decided to adopt the following solution.
[0035] In some optional implementations of some embodiments, in response to determining that there is at least one target structured query statement that meets the statement optimization condition in the target structured query statement set, performing statement optimization processing on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set may include the following steps:
[0036] For each target structured query statement in the at least one target structured query statement, the following statement optimization steps are performed:
[0037] Sub-step 1, determine the pending query execution logic of the above-mentioned target structured query statement. The above-mentioned pending query execution logic may be a step flow of the above-mentioned target structured query statement to obtain data in the data warehouse. The above-mentioned pending query execution logic may include but is not limited to at least one of the following: data table selection operation step, data table connection operation step, index selection operation step, subquery processing step. In practice, the above-mentioned execution subject can determine the pending query execution logic of the above-mentioned target structured query statement through relevant query execution logic instructions.
[0038] Sub-step 2, performing non-numerical feature encoding processing on the non-numerical data group of each execution node in the execution node set included in the above-mentioned execution logic to be queried, so as to generate a non-numerical execution logic feature vector group, and obtain a non-numerical execution logic feature vector group set. Among them, the above-mentioned execution logic to be queried can be a tree-structured data including each execution node. The execution node in each of the above-mentioned execution nodes can be a specific database operation. For example, the above-mentioned execution node can be an index scan operation. The above-mentioned execution node can include but is not limited to at least one of the following: operation type, operation data table name, field name, number of rows in the data table, and memory information occupied by the data table. The number of rows in the above-mentioned data table and the memory information occupied by the above-mentioned data table are numerical data. The above-mentioned operation type, the above-mentioned operation data table and the above-mentioned field name are non-numerical data. The non-numerical execution logic coding features in the above-mentioned non-numerical execution logic coding feature group can be coding features that characterize data distribution feature information of non-numerical data in the form of vectors. In practice, the execution subject may first use one-hot encoding to perform one-hot encoding on the non-numeric data group of each execution node in the execution node set included in the execution logic to be queried, to obtain a non-numeric execution logic encoding feature set. Then, an affine transformation is performed on the non-numeric execution logic encoding feature set to obtain a non-numeric execution logic feature vector set.
[0039] Sub-step 3, inputting the above non-numerical execution logic feature vector set into a long short-term memory recurrent neural network to obtain a non-numerical execution logic sequence feature vector set.
[0040] Sub-step 4, performing numerical feature encoding processing on the numerical data group of each execution node in the execution node set included in the above-mentioned execution logic set to be queried to generate a numerical execution logic feature vector, and obtain a numerical execution logic feature vector set. The above-mentioned numerical execution logic feature vector can be a feature vector obtained by normalizing the time cost required for the execution node to return the result, the time cost required for the structured query statement to return the result, and the numerical value corresponding to the number of data rows corresponding to the execution node.
[0041] Sub-step 5, performing channel feature concatenation on each non-numerical execution logic sequence feature vector in the above-mentioned non-numerical execution logic sequence feature vector set and the numerical execution logic feature vector corresponding to the above-mentioned non-numerical execution logic sequence feature vector in the above-mentioned numerical execution logic feature vector set to generate a query execution logic feature vector and obtain a query execution logic feature vector set.
[0042] Sub-step 6, performing feature stacking processing on the query execution logic feature vector set to obtain a query execution node feature matrix. The query execution node feature matrix can be a matrix obtained by stacking the query execution logic feature vector set into a higher dimension. In practice, the query execution logic feature vector set is subjected to feature stacking processing using a stacking function to obtain a query execution node feature matrix.
[0043] Sub-step 7, performing a depth-first traversal on the execution logic to be queried to obtain a query adjacency matrix corresponding to the execution logic to be queried, wherein the query adjacency matrix may be a matrix representing the depth-first traversal search order of the execution logic to be queried.
[0044] Sub-step 8, extracting graph representation features from the query adjacency matrix and the query execution node feature matrix to obtain a query execution graph representation feature vector. The query execution graph representation feature vector can characterize and extract graph structure feature information from the query adjacency matrix and the query execution node feature matrix. In practice, the execution subject can first input the query adjacency matrix and the query execution node feature matrix into two GCNs (Graph Convolutional Networks) to obtain a query graph representation feature vector. Then, the query graph representation feature vector is subjected to dimensionality reduction convolution processing to obtain a query execution graph representation feature vector.
[0045] Sub-step 9, performing field extraction processing on the target structured query statement to obtain a query field group. The query fields in the query field group may be fields in the data table that appear in the target structured query statement. The query field group may be fields after the five predicates in the structured query statement and data table fields that appear elsewhere in the structured query statement. The five predicates may be Join, Equal, Range, Group by, and Order by.
[0046] Sub-step 10, index conversion processing is performed on the query field group to obtain a candidate query index group. The candidate query index in the candidate query index group can be a candidate query index obtained by sorting and combining the query fields included in the query field group. In practice, the execution subject can preset a field combination selection rule, perform index conversion processing on the query field group, and obtain a candidate query index group. The preset field combination selection rule can be a combination rule of the fields after the predicate in 5 predicates and the data table fields.
[0047] Sub-step 11, for each candidate query index in the candidate query index group, perform the following query cost estimation value determination step:
[0048] The first sub-step is to perform index feature encoding processing on the non-numeric data group and the numerical data group included in the above candidate query index to obtain a non-numeric index feature vector group and a numerical index feature vector group. Among them, the non-numeric index feature vector in the above non-numeric index feature vector group can represent the feature information of the non-numeric data included in the candidate query index. The numerical index feature vector in the above numerical index feature vector group can represent the feature information of the numerical data included in the candidate query index. The non-numeric data group included in the above candidate query index may include: operation type, table name, field name and index name. The numerical data group included in the above candidate query index may be the time cost value of the candidate query index. In practice, the above execution subject may first perform unique hot encoding on the non-numeric data group included in the above candidate query index to obtain a candidate index encoding feature group. Then, perform affine transformation on the above candidate index encoding feature group to obtain a non-numeric index feature vector group. Finally, perform normalization processing on the numerical data group included in the above candidate query index to obtain a numerical index feature vector group.
[0049] The second sub-step is to perform vertical arrangement processing on the non-numerical index feature vector group and the numerical index feature vector group to obtain an index feature matrix.
[0050] The third sub-step is to extract the index feature internal weight features of each index feature vector included in the above-mentioned index feature matrix to obtain an index internal feature vector group. Among them, the index internal feature vectors in the above-mentioned index internal feature vector group can represent the internal feature information of each index feature vector included in the index feature matrix. In practice, the above-mentioned execution entity can first perform row convolution processing on the above-mentioned index feature matrix to obtain a row index feature vector group. Then, the above-mentioned row index feature vector group is input into the multi-dimensional attention mechanism model to obtain a row index internal feature vector group. Finally, the above-mentioned row index internal feature vector group is input into two layers of fully connected layers with different parameters to obtain an index internal feature vector group.
[0051] The fourth sub-step is to perform weighted feature extraction between index features on the above-mentioned index feature matrix to obtain an inter-index feature vector group. Among them, the inter-index feature vectors in the above-mentioned inter-index feature vector group can represent the feature information between each index feature vector. In practice, the above-mentioned execution entity can first perform column convolution processing on the above-mentioned index feature matrix to obtain a column index feature vector group. Then, the above-mentioned column index feature vector group is input into the multi-dimensional attention mechanism model to obtain a column index feature vector group. Finally, the above-mentioned column index internal feature vector group is input into two layers of fully connected layers with different parameters to obtain an inter-index feature vector group.
[0052] The fifth sub-step is to perform matrix product processing on the index feature matrix, the index internal feature vector group and the inter-index feature vector group to obtain a query index feature vector. The query index feature vector can represent feature information of the candidate query index. The matrix product processing can be a Hadamard product.
[0053] The sixth sub-step is to perform residual processing on the query execution graph representation feature vector and the obtained query index feature vector group to obtain a query residual feature vector. In practice, the execution subject may first perform channel feature splicing on the query execution graph representation feature vector and the obtained query index feature vector group to obtain a query splicing feature vector. Then, the query splicing feature vector is input into the residual network to obtain a residual splicing feature vector. Finally, the residual splicing feature vector is element-wise added to the query splicing feature vector to obtain a query residual feature vector.
[0054] The seventh sub-step is to perform regression logic processing on the above-mentioned query residual feature vector to obtain the query cost estimation value of the above-mentioned query execution logic. Among them, the above-mentioned query cost estimation value can represent the time difference between the execution time required for the structured query statement after adding the query index and the execution time required without adding the query index. In practice, the above-mentioned execution subject can input the above-mentioned query residual feature vector into two layers of fully connected layers to obtain the query cost estimation value of the above-mentioned query execution logic. Among them, the last connection layer in the above-mentioned two layers of fully connected layers does not have an activation function set.
[0055] Sub-step 12, using the enhanced index selection model, based on the obtained query cost estimation value group, select the target query index group corresponding to the target structured query statement from the candidate query index group. The enhanced index selection model can be a reinforcement learning model that selects the optimal candidate query index from the candidate query index group. The state of the enhanced index selection model can be a feature vector characterized by the index bitmap of the candidate query index and the memory occupancy feature vector of the data warehouse. The index bitmap of the candidate query index can be a vector composed of 0-1 variables indicating whether each candidate query index in the candidate query index group is used. The action of the enhanced index selection model can be a given state, and the legal action is to select a candidate query index with a corresponding value of 0 in the index bitmap to establish it. After that, the current state will transfer to the next state according to three rules: add the established candidate query index to the memory occupancy feature vector; set the 0-1 variable at the corresponding position in the index bitmap to 1; for each candidate query index in the candidate query index group, if it is covered by the currently established index, set its corresponding position in the index bitmap to 1, and then if it has been established, delete it and subtract the action of its occupied space from the memory occupancy feature vector. The reward function of the enhanced index selection model can be a reward function in which the immediate reward of the intermediate step is 0, and the reward when selecting the last valid candidate query index is set to the ratio of the time cost of the currently selected candidate query index group and the time cost of the target structured query statement. The environment of the enhanced index selection model can be a virtual index creation interface, a data warehouse and a cost estimator. The virtual index creation interface does not create a real physical index, but generates a virtual index that can generate query execution logic, which can reduce the waste of data warehouse memory resources and reduce the load and time of frequent index creation.
[0056] Sub-step 13: optimizing the target structured query statement using the target query index group to obtain an optimized query statement.
[0057] The above-mentioned technical scheme and its related contents, as an inventive point of an embodiment of the present disclosure, solve the second technical problem mentioned in the background technology: "Because the feature vectors extracted by the long short-term memory recursive neural network will cause errors in the execution order of the query execution logic, the execution nodes that were originally unrelated will be executed in a front-and-back order after feature extraction, resulting in the loss of structural information and low accuracy of time cost estimation. In addition, since the use of heuristic algorithms to select structured query statements often selects a single query index or a fixed query index, ignoring the changes in the query index, and not taking into account the interactive correlation between the query indexes, the data warehouse executes structured query statements with a high load, a long query time and a low user experience." The factors that lead to the high load, long query time and low user experience of the data warehouse in executing structured query statements are often as follows: because the existing method uses the long short-term memory recursive neural network to extract the structural information of the query execution logic when estimating the time cost of the structured query statements of the data warehouse, and because the feature vector extracted by the long short-term memory recursive neural network will cause errors in the execution order of the query execution logic, the execution nodes that were originally unrelated are executed in a forward and backward order after feature extraction, resulting in the loss of structural information and low accuracy of the time cost estimation, and because the heuristic algorithm is used to select structured query statements, a single query index or a fixed query index is often selected, ignoring the change of the query index, and the interactive correlation between the query indexes is not considered. If the above factors are solved, the effect of improving the accuracy of the vehicle data can be achieved. In order to achieve this effect, the present disclosure first determines the query execution logic and candidate query index group of the target structured query statement, which can reduce the search space of the data warehouse and reduce the load of the data warehouse. Then, the graph convolutional neural network and attention mechanism are used to extract the features of the query execution logic and the candidate query index group, and generate the query cost estimation value group of the target structured query statement, which can ensure the structural information of the candidate query index and improve the accuracy of the time cost estimation. Finally, the enhanced index selection model is used to optimize the target structured query statement, which can take into account the interactive correlation between query indexes, reduce the load of the data warehouse executing structured query statements, reduce query time and improve user experience.
[0058] Step 105 , vectorize each target query statement in the target query statement set to generate a query feature vector, thereby obtaining a query feature vector set.
[0059] In some embodiments, the above-mentioned execution subject can vectorize each target query statement in the target query statement set to generate a query feature vector and obtain a query feature vector set. Among them, the above-mentioned target query statement set can be a query statement set composed of the above-mentioned optimized query statement set and the remaining structured query statement set. The above-mentioned remaining structured query statement set can be a query statement set after removing the above-mentioned optimized query statement set from the above-mentioned target structured query statement set. The query feature vector group in the above-mentioned query feature vector set can characterize the feature information of the semantic information and structural information of a target query statement. In practice, the above-mentioned execution subject can use a convolutional neural network model to vectorize each target query statement in the target query statement set to generate a query feature vector and obtain a query feature vector set.
[0060] In some optional implementations of some embodiments, the vectorization of each target query statement in the target query statement set to generate a query feature vector and obtain the query feature vector set may include the following steps:
[0061] In the first step, the target query set is preprocessed to obtain a preprocessed target query set, wherein the preprocessing may include but is not limited to at least one of the following: standardization processing and unifying the case of each character string in the target query.
[0062] In the second step, for each preprocessed target query statement in the above preprocessed target query statement set, perform the following vectorization steps:
[0063] Sub-step 1, lexical analysis is performed on the above-mentioned preprocessed target query statement to obtain a query phrase. Among them, the query words in the above-mentioned query phrase can be keywords, operators, and identifiers included in the preprocessed target query statement. The above-mentioned keywords can be command keywords used to describe the structure of the preprocessed target query statement. For example, the above-mentioned keywords can include but are not limited to at least one of the following: select, from, where. The above-mentioned operators may include: arithmetic operators, comparison operators, logical operators and Boolean operators. The above-mentioned identifiers can be table names and field names. In practice, the above-mentioned execution entity can use the lexical analyzer (Lexer) in the data warehouse to perform lexical analysis on the above-mentioned preprocessed target query statement to obtain a query phrase.
[0064] Sub-step 2, removing stop words from the query phrase to obtain a query phrase after removal. The query phrase after removal may be a query phrase obtained by removing stop words from the query phrase. The stop words may be conjunctions and punctuation marks that do not contain actual meaning.
[0065] Sub-step 3, grammatically analyze the query phrase after removal to obtain a query grammar abstract tree. The query grammar abstract tree may be a tree structure that describes the structure and semantic information of the target query statement. In practice, the execution subject may use a grammar analyzer (Parser) of a data warehouse to grammatically analyze the query phrase after removal to obtain a query grammar abstract tree.
[0066] Sub-step 4, classify and split the query syntax abstract tree to obtain a query keyword tree and a query field tree. The query keyword tree may be a tree structure that only includes keywords in the query phrase after removal. The query field tree may be a tree structure that only includes table names and field names in the query phrase after removal. The query keyword tree and the query field tree may be tree structures with the same structure but different nodes.
[0067] Sub-step 5, semantically vectorize the query field tree and the query keyword tree to obtain a query field feature vector tree and a query keyword feature vector tree. In practice, the execution subject may first use a bag-of-words model to semantically vectorize the query field tree to obtain a query field feature vector tree. Then, one-hot encoding is used to encode the query keyword tree to obtain a query keyword encoding tree. Finally, feature embedding is performed on the query keyword encoding tree to obtain a query keyword feature vector tree.
[0068] Sub-step 6, vectorize the structural information of the query field feature vector tree to obtain a query structural feature vector. The query structural feature vector can represent the structural feature information of the query field feature vector tree. In practice, the execution entity can use GCN (Graph Convolutional Networks) to vectorize the structural information of the query field feature vector tree to obtain a query structural feature vector.
[0069] Sub-step 7, performing feature joint embedding processing on the query structure feature vector, the query field feature vector tree and the query keyword feature vector tree to obtain a query feature vector. The query feature vector may be a feature vector obtained by performing dot multiplication and addition processing on the query field feature vector tree and the query keyword feature vector tree and then concatenating the query structure feature vector.
[0070] Step 106 , performing query statement clustering processing on the target query statement set according to the query feature vector set to obtain a query statement class cluster set.
[0071] In some embodiments, the execution subject may perform query statement clustering processing on the target query statement set according to the query feature vector set to obtain a query statement cluster set, wherein the query statement clusters in the query statement cluster set may be a structured query statement set consisting of structured query statements that perform the same type of query or modification on a data table in the same database.
[0072] As an example, the execution subject may first determine the feature similarity value of any query feature vector pair in the query feature vector set to obtain a feature similarity value group set. The query feature vector pair may be a feature vector pair consisting of any two query feature vector groups. The feature similarity value group in the feature similarity value group set may be a feature similarity value between a target query statement and each target query statement other than the target query statement. Then, for each feature similarity value group in the feature similarity value group set, at least one feature similarity value greater than or equal to a preset feature similarity threshold is screened out, and the target query statement corresponding to the at least one feature similarity value is determined as a query statement cluster.
[0073] In some optional implementations of some embodiments, performing query statement clustering processing on the target query statement set according to the query feature vector set to obtain a query statement cluster set may include the following steps:
[0074] In the first step, for each query feature vector in the query feature vector set, the following sorting steps are performed:
[0075] Sub-step 1, extracting query feature vector items representing keywords, identifiers, expressions and subqueries in the above query feature vector group as keyword feature vector item group, identifier feature vector item group, expression feature vector item group and subquery feature vector item group. Wherein, the above expression may include arithmetic expression and logical operation expression. The above query feature vector may be E={e1, e2, e3, e4, e5, e6}. The above query feature vector item may be a feature item of the above query feature vector. For example, the above query feature vector item may be e1.
[0076] Sub-step 2, sorting the keyword feature vector group, the identifier feature vector group, the expression feature vector group and the sub-query feature vector group to obtain a query feature vector item sequence. The query feature vector item sequence can be obtained by sorting in the order of keywords, identifiers, expressions and sub-queries.
[0077] In the second step, by using a preset query synonym set, a common feature vector item subsequence of any query feature vector item sequence pair in the obtained query feature vector item sequence set is determined to obtain a common feature vector item subsequence set. Among them, the above-mentioned preset query synonym set can be a pre-set synonym set with the same meaning in the structured query statement. The above-mentioned query feature vector sequence pair can be a sequence pair composed of any two query feature vector item sequences. The common feature vector subsequence in the above-mentioned common feature vector subsequence set can be a subsequence composed of feature vector items included in both query feature vector item sequences in the query feature vector item sequence pair. In practice, the above-mentioned execution subject can use the LCS (Longest Common Subsequence) algorithm to determine the common feature vector item subsequence of any query feature vector item sequence pair in the obtained query feature vector item sequence set by using a preset query synonym set to obtain a common feature vector item subsequence set.
[0078] The third step is to determine the similarity value of any query feature vector pair in the query feature vector set based on the common feature vector item subsequence set to obtain a query similarity value group set. The query similarity value group in the query similarity value group set can be the similarity between the query feature vector and each query feature vector other than the query feature vector.
[0079] As an example, the execution subject may perform the following similarity value determination steps for each query similarity value in the query similarity value group set: first, determine the query feature vector pair corresponding to the query similarity value. Secondly, determine the common feature vector item subsequence of the query feature vector pair. Thirdly, determine the number of keyword feature vector item groups, identifier feature vector item groups, expression feature vector item groups, and sub-query feature vector item groups included in the common feature vector item subsequence, and obtain the number of common keyword items, the number of common identifier items, the number of common expression items, and the number of common sub-query items. Subsequently, determine the number of keyword feature vector item groups, identifier feature vector item groups, expression feature vector item groups, and sub-query feature vector item groups included in each query feature vector in the query feature vector pair, and obtain the number of first keyword items, the number of first identifier items, the number of first expression items, the number of first sub-query items, the number of second keyword items, the number of second identifier items, the number of second expression items, and the number of second sub-query items. Then, the sum of the ratio of the number of first keyword items to the number of common keyword items and the product of the first preset weight coefficient, the ratio of the number of first identifier items to the number of common identifier items and the product of the second preset weight coefficient, the ratio of the number of first expression items to the number of common expression items and the product of the third preset weight coefficient, the ratio of the number of first sub-query items to the number of common sub-query items and the product of the fourth preset weight coefficient is determined as the first value, and the sum of the ratio of the number of second keyword items to the number of common keyword items and the product of the first preset weight coefficient, the ratio of the number of second identifier items to the number of common identifier items and the product of the second preset weight coefficient, the ratio of the number of second expression items to the number of common expression items and the product of the third preset weight coefficient, the ratio of the number of second sub-query items to the number of common sub-query items and the product of the fourth preset weight coefficient is determined as the second value. Among them, the sum of the first preset weight coefficient, the second preset weight coefficient, the third preset weight coefficient and the fourth preset weight coefficient is 1. The first preset weight coefficient is the smallest and the fourth preset weight coefficient is the largest. Finally, the query similarity value is determined by taking the average value of the above-mentioned first value and the above-mentioned second value.
[0080] Step 4: for each query similarity value group in the query similarity value group set, perform the following determination steps:
[0081] Sub-step 1: Filter out at least one query similarity value greater than or equal to a preset similarity threshold from the query similarity value group as a target query similarity value group. The preset similarity threshold may be a maximum value of a preset query similarity value. For example, the preset similarity threshold may be determined according to specific circumstances.
[0082] Sub-step 2: determining the target query statement group corresponding to the target query similarity value group as a query statement cluster.
[0083] Step 107: determine the query execution logic and query result group of each query statement cluster in the query statement cluster set to obtain a query execution logic set and a query result group set.
[0084] In some embodiments, the execution subject may determine the query execution logic and query result group of each query statement cluster in the query statement cluster set to obtain a query execution logic set and a query result group set. The query execution logic may be the execution logic of the execution step of acquiring data in the data warehouse generated by the query optimizer of the data warehouse through the structured query statement received by the target terminal. The query result in the query result group set may be the to-be-queried data corresponding to the target query statement in the query cluster.
[0085] As an example, the execution subject may use a query optimizer of a data warehouse to determine the query execution logic and query result group of each query statement cluster in the query statement cluster set to obtain a query execution logic set and a query result group set.
[0086] Step 108, hash storage of the query execution logic set and the query result set, and in response to detecting a set of structured query statements to be executed sent by the client, multiplexing the query execution logic set and the query result set to obtain the query results to be executed of each structured query statement to be executed in the set of structured query statements to be executed.
[0087] In some embodiments, the execution subject may perform hash storage on the query execution logic set and the query result set, and in response to detecting the set of structured query statements to be executed sent by the client, reuse the query execution logic set and the query result set to obtain the query results to be executed of each structured query statement to be executed in the set of structured query statements to be executed. Among them, the structured query statements to be executed in the set of structured query statements to be executed may be the SQL statements sent by the client at the current time. The query results to be executed may be the query data corresponding to the structured query statements to be executed. The reuse may include at least one of the following: reuse of views or intermediate tables, reuse of merged query logic, and materialized views.
[0088] In some optional implementations of some embodiments, in response to detecting the set of structured query statements to be executed sent by the client, multiplexing the query execution logic set and the query result group set to obtain the query result to be executed of each structured query statement to be executed in the set of structured query statements to be executed, may include the following steps:
[0089] For each structured query statement to be executed in the above structured query statement set to be executed, perform the following reuse steps:
[0090] Sub-step 1, determining the sentence similarity value between the structured query to be executed and each query sentence cluster in the query sentence cluster set, and obtaining a sentence similarity value group. The sentence similarity value may be the average value of the query similarity values between the structured query to be executed and each target query sentence included in the query sentence cluster.
[0091] Sub-step 2: determining the sentence similarity value with the largest sentence similarity value in the above sentence similarity value group as the target sentence similarity value.
[0092] Sub-step 3: determining the query result group and query execution logic corresponding to the target sentence similarity value as the target query result group and target query execution logic.
[0093] Sub-step 4, in response to determining that the to-be-queried data corresponding to the above target query result group has not changed, and the above target query result group contains the to-be-queried results corresponding to the above to-be-executable structured query statement, combining the above target query result group to obtain the to-be-executable query results of the above to-be-executable structured query statement. The above combination processing may be splicing or cutting the above target query result group.
[0094] Sub-step 5, in response to determining that the above-mentioned query result to be executed does not exist in the above-mentioned target query result group, the above-mentioned structured query statement to be executed is executed using the above-mentioned target query execution logic to obtain the query result to be executed of the above-mentioned structured query statement to be executed, so as to reuse the structured query statement.
[0095] In some optional implementations of some embodiments, in response to determining that the to-be-queried data corresponding to the query result group has not changed, and there is a to-be-executed query result corresponding to the to-be-executed structured query statement in the target query result group, combining the target query result group to obtain the to-be-executed query result of the to-be-executed structured query statement may include the following steps:
[0096] The first step is to determine the association information between the query result to be executed and each target query result in the target query result group to obtain an association information group. The association information may be the fields and corresponding data of each target query result in the target query result group that are the same as the query result to be executed.
[0097] The second step is to determine at least one target query result associated with the query result to be executed as a related query result group according to the related information group. The related query results in the related query result group may be a result group consisting of target query results having the same fields and data corresponding to the fields as the query result to be executed.
[0098] As an example, the execution subject may use the associated information group to select at least one target query result associated with the query result to be executed from the target query result group as the associated query result group.
[0099] The third step is to generate an associated cost generation function, wherein the associated cost generation function may be a function that uses the least associated query result groups and the least number of combinations to obtain the query result to be executed.
[0100] In the fourth step, according to the above-mentioned association cost generation function, the above-mentioned association query result group is dynamically programmed to obtain the association combination information of the above-mentioned association query result group. The above-mentioned association combination information can be the information of the minimum number of combinations of the association query result subgroups in the above-mentioned association query result group. The above-mentioned association query result subgroups can be the number of association query result groups that obtain the least query results to be executed.
[0101] As an example, the execution subject may use a heuristic algorithm to perform dynamic programming on the associated query result group according to the associated cost generation function to obtain the associated combination information of the associated query result group. The heuristic algorithm may be one of the following: population algorithm, greedy algorithm, genetic algorithm.
[0102] The fifth step is to combine the above-mentioned associated combination information to process the above-mentioned associated query result group, and obtain the query result to be executed of the above-mentioned structured query statement to be executed.
[0103] Optionally, in response to determining that the query result to be executed does not exist in the target query result, after executing the structured query statement to be executed by using the target query execution logic to obtain the query result to be executed of the structured query statement to be executed, the method may further include the following steps:
[0104] In the first step, in response to determining that the to-be-queried data corresponding to the target query result group has changed, a query log information group in which the to-be-queried data has changed is obtained. The query log information in the query log information group may be log information recording the modification, addition or deletion of the query result group.
[0105] The second step is to parse the query log information group to obtain a changed field group and a change type group. The changed field in the changed field group may be a field whose corresponding data has changed. The change type in the change type group may be a type of modification, addition or deletion of the data.
[0106] The third step is to determine at least one query result in which data in the target query result group has been changed according to the changed field group as the changed query result group, wherein the changed query result in the changed query result group may be the target query result in which data corresponding to the field has been changed.
[0107] As an example, the execution subject may first use a naive matching algorithm to match the change field group with the target query result group to obtain a matching result group. Then, at least one target query result corresponding to at least one matching result in the matching result group that represents a successful match is determined as the change query result group. The successful match may mean that the target query result in the target query result group includes at least one change field in the change field group.
[0108] In the fourth step, the changed query result group is updated according to the change type group to obtain an updated query result group, wherein the updated query result in the updated query result group may be a query result obtained after a change operation is performed in response to the changed query result.
[0109] As an example, the execution subject may first determine the change type corresponding to each change query result in the change query result group as the change type query result to obtain the change type query result group. Then, the change type query result group is subjected to corresponding change processing to obtain a more detailed query result group.
[0110] In a fifth step, in response to determining that the query result to be executed exists in the updated query result group, the updated query result group is combined to obtain the query result to be executed of the structured query statement to be executed.
[0111] In the sixth step, in response to determining that the query result to be executed does not exist in the updated query result group, the target query execution logic is used to execute the structured query statement to be executed, and the query result to be executed corresponding to the structured query statement to be executed is obtained to reuse the structured query statement.
[0112] The above-mentioned embodiments of the present disclosure have the following beneficial effects: the structured query statement reuse method of some embodiments of the present disclosure can reduce the repeated execution of similar query operations in the data warehouse, improve query efficiency and accuracy, shorten query time, and reduce load. Specifically, the reasons for the reduction of the execution efficiency of the relevant data warehouse and the increase of the load of the data warehouse resources are: the reuse of SQL statements through SQL templates will increase the complexity of the query and the additional parsing steps, and because the SQL model is an SQL statement containing placeholders, the scope of the SQL statements involved is relatively single. If all SQL statements are to be covered, the waste of storage resources of the data warehouse will be increased, resulting in the reduction of the execution efficiency of the data warehouse and the increase of the load of the data warehouse resources. Based on this, the structured query statement reuse method of some embodiments of the present disclosure can first obtain a structured query statement set. Here, the structured query statement set is used to subsequently determine the target structured query statement set for repeated execution. Secondly, at least one structured query statement that meets the preset condition is selected from the above structured query statement set to obtain the target structured query statement set, wherein the above preset condition is the condition that the number of executions of the structured query statement within the preset time is greater than or equal to the preset execution threshold. Here, the target structured query statement set is used for the reuse of subsequent query execution logic and query result group. Again, determine whether the target structured query statement set meets the conditions for statement optimization. Here, it is used to judge the execution efficiency of the target structured query statement so as to improve the performance of the target structured query statement and reduce the query execution time and data warehouse resource consumption. Then, in response to determining that there is at least one target structured query statement that meets the conditions for statement optimization in the target structured query statement set, perform statement optimization processing on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set. Here, the optimization processing can improve the execution efficiency and query performance of the structured query statement and reduce the load of the data warehouse. Subsequently, each target query statement in the target query statement set is vectorized to generate a query feature vector to obtain a query feature vector set, wherein the target query statement set is a query statement set composed of the optimized query statement set and the remaining structured query statement set, and the remaining structured query statement set is a query statement set after the optimized query statement set is removed from the target structured query statement set. Here, the vectorized representation of the target query statement can determine the similarity between each target query statement, so as to reduce the repeated execution of repeated structured query statements in the data warehouse, reduce the load and resource consumption of the data warehouse. Afterwards, based on the above query feature vector set, the above target query statement set is clustered to obtain a query statement class cluster set.Here, the query statement clustering process can directly reuse the query results or query execution logic in the cache when the data warehouse executes similar structured query statements again, without re-execution, reducing resource waste. Then, the query execution logic and query result group of each query statement cluster in the above query statement cluster set are determined to obtain a query execution logic set and a query result group set. Here, it is convenient for the subsequent data warehouse to execute similar structured query data and perform reuse, shorten the query time, and improve the query efficiency and the reuse rate of structured query statements. Finally, the query execution logic set and the query result group set are hashed and stored, and in response to detecting the structured query statement set to be executed sent by the client, the query execution logic set and the query result group set are reused to obtain the query results to be executed of each structured query statement to be executed in the structured query statement set to be executed. Here, the hash cache can be directly reused when a similar structured query statement is executed next time, reducing the execution of structured query statements by the data warehouse and improving query efficiency and accuracy. It can be concluded that the structured query statement reuse method can improve the query performance of structured query statements by optimizing and clustering structured query statements to achieve the reuse of structured query statements with high similarity. To a certain extent, it can reduce the repeated execution of similar query operations in the data warehouse, improve query efficiency and accuracy, shorten query time, and reduce the load on the data warehouse.
[0113] Further references Figure 2 As an implementation of the methods shown in the above figures, the present disclosure provides some embodiments of a structured query statement reuse device. These device embodiments are similar to Figure 1 Corresponding to the method embodiments shown, the structured query statement multiplexing device can be specifically applied to various electronic devices.
[0114] like Figure 2As shown, a structured query statement reuse device 200 includes: an acquisition unit 201, a screening unit 202, a first determination unit 203, a statement optimization unit 204, a vectorized representation unit 205, a query statement clustering unit 206, a second determination unit 207 and a reuse unit 208. Among them, the acquisition unit 201 is configured to: acquire a structured query statement set. The screening unit 202 is configured to: filter out at least one structured query statement that meets a preset condition from the above structured query statement set to obtain a target structured query statement set, wherein the above preset condition is a condition that the number of executions within a preset time is greater than or equal to a preset execution threshold. The first determination unit 203 is configured to: determine whether the above target structured query statement set meets the statement optimization condition. The statement optimization unit 204 is configured to: in response to determining that there is at least one target structured query statement that meets the statement optimization condition in the above target structured query statement set, perform statement optimization processing on each target structured query statement in the above at least one target structured query statement to obtain an optimized query statement set. The vectorization representation unit 205 is configured to: vectorize each target query statement in the target query statement set to generate a query feature vector and obtain a query feature vector set, wherein the target query statement set is a query statement set consisting of the optimized query statement set and the remaining structured query statement set, and the remaining structured query statement set is a query statement set after the optimized query statement set is removed from the structured query statement set. The query statement clustering unit 206 is configured to: perform query statement clustering processing on the target query statement set according to the query feature vector set to obtain a query statement cluster set. The second determination unit 207 is configured to: determine the query execution logic and query result group of each query statement cluster in the query statement cluster set to obtain a query execution logic set and a query result group set. The multiplexing unit 208 is configured to: hash and store the above-mentioned query execution logic set and the above-mentioned query result group set, and in response to detecting the set of structured query statements to be executed sent by the client, multiplex the above-mentioned query execution logic set and the above-mentioned query result group set to obtain the query results to be executed of each structured query statement to be executed in the above-mentioned set of structured query statements to be executed.
[0115] It can be understood that the units recorded in the structured query statement reuse device 200 and the reference Figure 1 Therefore, the operations, features and beneficial effects described above for the method are also applicable to the structured query statement reuse device 200 and the units included therein, and will not be described in detail here.
[0116] Reference below Figure 3 , which shows a structural schematic diagram of an electronic device (eg, an electronic device) 300 suitable for implementing some embodiments of the present disclosure. Figure 3 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0117] like Figure 3 As shown, the electronic device 300 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 into a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the electronic device 300 are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0118] Typically, the following devices may be connected to the I / O interface 305: input devices 306 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 308 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 309. The communication devices 309 may allow the electronic device 300 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 3 The electronic device 300 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 3 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0119] In particular, according to some embodiments of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, some embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In some such embodiments, the computer program can be downloaded and installed from the network through the communication device 309, or installed from the storage device 308, or installed from the ROM 302. When the computer program is executed by the processing device 301, the above-mentioned functions defined in the method of some embodiments of the present disclosure are executed.
[0120] It should be noted that the computer-readable medium in some embodiments of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In some embodiments of the present disclosure, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In some embodiments of the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0121] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (Hyper Text Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0122] The above-mentioned computer-readable medium may be included in the above-mentioned electronic device; or it may exist independently without being assembled into the electronic device. The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: obtains a set of structured query statements; filters out at least one structured query statement that meets a preset condition from the above-mentioned structured query statement set to obtain a target structured query statement set, wherein the above-mentioned preset condition is that the number of executions of the structured query statement within a preset time length is greater than or equal to a preset execution threshold; determines whether the above-mentioned target structured query statement set meets the condition for statement optimization; in response to determining that there is at least one target structured query statement that meets the condition for statement optimization in the above-mentioned target structured query statement set, performs statement optimization processing on each target structured query statement in the above-mentioned at least one target structured query statement to obtain an optimized query statement set; vectorizes each target query statement in the target query statement set to generate a query feature vector to obtain to a query feature vector set, wherein the target query statement set is a query statement set consisting of the optimized query statement set and the remaining structured query statement set, and the remaining structured query statement set is a query statement set after the optimized query statement set is removed from the target structured query statement set; query statement clustering is performed on the target query statement set according to the query feature vector set to obtain a query statement class cluster set; query execution logic and query result group of each query statement class cluster in the query statement class cluster set are determined to obtain a query execution logic set and a query result group set; the query execution logic set and the query result group set are hashed and stored; and in response to detecting a to-be-executed structured query statement set sent by a client, the query execution logic set and the query result group set are reused to obtain a to-be-executed query result of each to-be-executed structured query statement in the to-be-executed structured query statement set.
[0123] Computer program code for performing the operations of some embodiments of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0124] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0125] The units described in some embodiments of the present disclosure may be implemented by software or by hardware. The described units may also be provided in a processor, for example, may be described as: a processor including an acquisition unit, a screening unit, a first determination unit, a statement optimization unit, a vectorized representation unit, a query statement clustering unit, a second determination unit, and a multiplexing unit. Among them, the names of these units do not constitute a limitation on the units themselves in certain cases, for example, the acquisition unit may also be described as a "unit for acquiring a set of structured query statements".
[0126] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0127] The above descriptions are only some preferred embodiments of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) and the technical solutions formed.
Claims
1. A structured query statement reuse method, comprising: Get a set of structured query statements; At least one structured query statement that meets a preset condition is selected from the structured query statement set to obtain a target structured query statement set, wherein the preset condition is that the number of executions of the structured query statement within a preset time period is greater than or equal to a preset execution threshold; Determining whether the target structured query statement set meets the statement optimization condition; In response to determining that there is at least one target structured query statement satisfying a statement optimization condition in the target structured query statement set, performing statement optimization processing on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set; Vectorizing each target query statement in the target query statement set to generate a query feature vector, thereby obtaining a query feature vector set, wherein the target query statement set is a query statement set consisting of the optimized query statement set and a remaining structured query statement set, and the remaining structured query statement set is a query statement set obtained by removing the optimized query statement set from the target structured query statement set; According to the query feature vector set, query statement clustering processing is performed on the target query statement set to obtain a query statement class cluster set; Determine the query execution logic and query result group of each query statement cluster in the query statement cluster set to obtain a query execution logic set and a query result group set; The query execution logic set and the query result set are hashed and stored, and in response to detecting a set of structured query statements to be executed sent by a client, the query execution logic set and the query result set are reused to obtain the query result to be executed of each structured query statement to be executed in the set of structured query statements to be executed, wherein in response to detecting a set of structured query statements to be executed sent by a client, the query execution logic set and the query result set are reused to obtain the query result to be executed of each structured query statement to be executed in the set of structured query statements to be executed, including: For each structured query statement to be executed in the set of structured query statements to be executed, the following multiplexing steps are performed: Determine a sentence similarity value between the structured query sentence to be executed and each query sentence cluster in the query sentence cluster set to obtain a sentence similarity value group; Determine a sentence similarity value with the largest sentence similarity value in the sentence similarity value group as a target sentence similarity value; Determine a query result group and a query execution logic corresponding to the target sentence similarity value as a target query result group and a target query execution logic; In response to determining that the to-be-queried data corresponding to the target query result group has not changed, and the to-be-queried result corresponding to the to-be-executed structured query statement exists in the target query result group, combining the target query result group to obtain the to-be-executed query result of the to-be-executed structured query statement; In response to determining that the query result to be executed does not exist in the target query result group, the target query execution logic is used to execute the structured query statement to be executed, and the query result to be executed of the structured query statement to be executed is obtained to reuse the structured query statement.
2. The method according to claim 1, wherein: In response to determining that the to-be-queried data corresponding to the target query result group has not changed, and the to-be-queried result corresponding to the to-be-executed structured query statement exists in the target query result group, combining the target query result group to obtain the to-be-executed query result of the to-be-executed structured query statement, including: Determine association information between the query result to be executed and each target query result in the target query result group to obtain an association information group; According to the associated information group, determining at least one target query result associated with the query result to be executed as an associated query result group; Generate an associated cost generation function; According to the association cost generation function, performing dynamic programming processing on the association query result group to obtain association combination information of the association query result group; The associated query result group is combined and processed by using the associated combination information to obtain the query result to be executed of the structured query statement to be executed.
3. The method according to claim 1, wherein: After, in response to determining that the query result to be executed does not exist in the target query result group, executing the structured query statement to be executed by using the target query execution logic to obtain the query result to be executed of the structured query statement to be executed, the method further includes: In response to determining that the to-be-queried data corresponding to the target query result group has changed, obtaining a query log information group in which the to-be-queried data has changed; Parsing the query log information group to obtain a changed field group and a changed type group; According to the changed field group, determining at least one query result in which data in the target query result group is changed as the changed query result group; According to the change type group, update the data of the change query result group to obtain an updated query result group; In response to determining that the query result to be executed exists in the updated query result group, combining the updated query result group to obtain the query result to be executed of the structured query statement to be executed; In response to determining that the query result to be executed does not exist in the updated query result group, the target query execution logic is used to execute the structured query statement to be executed, and the query result to be executed corresponding to the structured query statement to be executed is obtained to reuse the structured query statement.
4. The method according to claim 1, wherein: The vectorization of each target query statement in the target query statement set to generate a query feature vector to obtain a query feature vector set includes: Preprocessing the target query statement set to obtain a preprocessed target query statement set; For each preprocessed target query statement in the preprocessed target query statement set, the following vectorization steps are performed: Performing lexical analysis on the preprocessed target query sentence to obtain a query phrase; Removing stop words from the query phrase to obtain a query phrase after the removal of stop words; Performing grammatical analysis on the removed query phrase to obtain a query grammar abstract tree; Classify and split the query syntax abstract tree to obtain a query keyword tree and a query field tree; Performing semantic vectorization on the query field tree and the query keyword tree to obtain a query field feature vector tree and a query keyword feature vector tree; Vectorizing the structure information of the query field feature vector tree to obtain a query structure feature vector; The query structure feature vector, the query field feature vector tree and the query keyword feature vector tree are subjected to feature joint embedding processing to obtain a query feature joint embedding tree as a query feature vector.
5. The method according to claim 1, wherein: The query statement clustering process is performed on the target query statement set according to the query feature vector set to obtain a query statement class cluster set, including: For each query feature vector in the query feature vector set, the following sorting steps are performed: Extracting query feature vector items representing keywords, identifiers, expressions and subqueries in the query feature vector as keyword feature vector items, identifier feature vector items, expression feature vector items and subquery feature vector items; performing feature vector sorting on the keyword feature vector item, the identifier feature vector item, the expression feature vector item, and the sub-query feature vector item to obtain a query feature vector item sequence; By presetting a query synonym set, determining a common feature vector item subsequence of any query feature vector item sequence pair in the obtained query feature vector item sequence set, and obtaining a common feature vector item subsequence set; Determine, based on the common feature vector item subsequence set, a similarity value of any query feature vector pair in the query feature vector set to obtain a query similarity value group set; For each query similarity value group in the query similarity value group set, the following determination steps are performed: Filtering at least one query similarity value greater than or equal to a preset similarity threshold from the query similarity value group as a target query similarity value group; The target query statement group corresponding to the target query similarity value group is determined as a query statement cluster.
6. A structured query statement reuse device, comprising: An acquisition unit is configured to acquire a structured query statement set; A screening unit is configured to screen out at least one structured query statement that meets a preset condition from the structured query statement set to obtain a target structured query statement set, wherein the preset condition is that the number of executions of the structured query statement within a preset time period is greater than or equal to a preset execution threshold; A first determining unit is configured to determine whether the target structured query statement set meets a statement optimization condition; A statement optimization unit is configured to, in response to determining that there is at least one target structured query statement in the target structured query statement set that meets the statement optimization condition, perform statement optimization processing on each target structured query statement in the at least one target structured query statement to obtain an optimized query statement set; A vectorization representation unit is configured to perform vectorization representation on each target query statement in a target query statement set to generate a query feature vector and obtain a query feature vector set, wherein the target query statement set is a query statement set consisting of the optimized query statement set and a remaining structured query statement set, and the remaining structured query statement set is a query statement set obtained by removing the optimized query statement set from the target structured query statement set; A query statement clustering unit is configured to perform query statement clustering processing on the target query statement set according to the query feature vector set to obtain a query statement class cluster set; A second determining unit is configured to determine the query execution logic and query result group of each query statement cluster in the query statement cluster set to obtain a query execution logic set and a query result group set; A multiplexing unit is configured to perform hash storage on the query execution logic set and the query result set, and in response to detecting a set of structured query statements to be executed sent by a client, multiplex the query execution logic set and the query result set to obtain a query result to be executed for each structured query statement to be executed in the set of structured query statements to be executed, wherein in response to detecting a set of structured query statements to be executed sent by a client, multiplex the query execution logic set and the query result set to obtain a query result to be executed for each structured query statement to be executed in the set of structured query statements to be executed, including: for each structured query statement to be executed in the set of structured query statements to be executed, perform the following multiplexing steps: determine a statement similarity value between the structured query statement to be executed and each query statement cluster in the set of query statement clusters, A statement similarity value group is obtained; a statement similarity value with the largest statement similarity value in the statement similarity value group is determined as a target statement similarity value; a query result group and a query execution logic corresponding to the target statement similarity value are determined as a target query result group and a target query execution logic; in response to determining that the to-be-queried data corresponding to the target query result group has not changed, and that the to-be-executed query results corresponding to the to-be-executed structured query statement exist in the target query result group, the target query result group is combined to obtain the to-be-executed query results of the to-be-executed structured query statement; in response to determining that the to-be-executed query results do not exist in the target query result group, the to-be-executed structured query statement is executed using the target query execution logic to obtain the to-be-executed query results of the to-be-executed structured query statement, so as to reuse the structured query statement.
7. An electronic device comprising: one or more processors; a storage device having one or more programs stored thereon, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
8. A computer readable medium having a computer program stored thereon, wherein: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
