A method for determining query statement similarity, an execution method and a device

By parsing the query statement into an abstract syntax tree and forming an operation vector, and calculating the similarity using the vector database, the data processing pressure problem caused by text string calculation is solved, and the efficiency of query statement similarity determination and the processing ability of the terminal device are improved.

CN117539895BActive Publication Date: 2025-08-26BEIJING PACTERA JINXIN TECH LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311520084.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-14
Publication Date
2025-08-26
Estimated Expiration
2043-11-14

AI Technical Summary

Technical Problem

In the prior art, the similarity calculation using text strings of SQL query statements results in a large amount of data processing of terminal equipment, which increases the data processing pressure of the equipment.

Method used

By analyzing the query statement as an abstract syntax tree, the operation data is extracted and the operation vector is formed. The vector database is used to calculate the query statement similarity to reduce the data processing amount.

Benefits of technology

It reduces the data processing pressure during the similarity determination process of query statements, improves the similarity determination efficiency, and reduces the calculation complexity of terminal devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117539895B_ABST
    Figure CN117539895B_ABST
Patent Text Reader

Abstract

The present application provides a method, execution method, and device for determining query statement similarity, which obtains the data query requirements of the query project; based on the data query requirements, generates a project query statement by calling the data interface of the query statement generation framework; extracts operation data from the project query statement by parsing the project query statement, and determines the operation vector of the project query statement; based on the operation vector, determines a target query statement that matches the project query statement from multiple candidate query statements; and determines the similarity score between the project query statement and the target query statement based on the operation vector and the target operation vector of the target query statement. In this way, the query statement similarity score can be determined with the help of the operation data involved in the query statement, which can reduce the amount of data processing involved in the similarity determination process, improve the efficiency of determining the similarity score, and reduce the data processing pressure of the terminal device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a method for determining query statement similarity, an execution method, and a device. Background Art

[0002] With the growing demand for data storage and processing, database management and optimization are becoming increasingly important. Similarity determination is a crucial issue in database management and optimization. For example, in areas such as data integration, data cleaning, and data analysis, data similarity matching is necessary to facilitate better integration, cleaning, and analysis. Similarly, similarity determination is also crucial in database query optimization. By leveraging the similarity between different SQL query statements, we can better query and optimize the database.

[0003] At present, text matching is usually adopted to use the text strings of SQL query statements to realize the similarity calculation between different SQL query statements. However, the text matching method has a large amount of calculation, which invisibly increases the data processing volume of the terminal device and brings greater data processing pressure to the terminal device. Summary of the Invention

[0004] In view of this, the purpose of this application is to provide a method, an execution method and an apparatus for determining query statement similarity, which can solve the problem of high data processing volume and data processing pressure of terminal devices during the query statement similarity calculation process.

[0005] The present invention provides a method for determining query sentence similarity, the method comprising:

[0006] Get the data query requirements of the query project;

[0007] Based on the data query requirements, a project query statement is generated by calling a data interface of a query statement generation framework; wherein the project query statement is used to obtain the query results required by the query project;

[0008] By parsing the project query statement, extracting operation data from the project query statement, and determining the operation vector of the project query statement;

[0009] Determining a target query statement matching the item query statement from a plurality of candidate query statements based on the operation vector;

[0010] A similarity score between the item query statement and the target query statement is determined based on the operation vector of the item query statement and the target operation vector of the target query statement.

[0011] In a possible implementation mode, parsing the item query statement, extracting operation data from the item query statement, and determining the operation vector of the item query statement includes:

[0012] Parsing the project query statement into an abstract syntax tree;

[0013] Performing a depth-first traversal on the abstract syntax tree, extracting operation data from the abstract syntax tree, and recording the operation data as a one-dimensional vector; wherein the one-dimensional vector records the operators and / or column operation values ​​involved in the item query statement; the one-dimensional vector is used to reflect the complexity of the item query statement;

[0014] After the depth-first traversal process is completed, the one-dimensional vector is determined as the operation vector of the item query statement.

[0015] In a possible implementation manner, performing a depth-first traversal on the abstract syntax tree to extract operation data from the abstract syntax tree includes:

[0016] Determining the operators and column operation values ​​involved in the project query statement by performing a depth-first traversal on the abstract syntax tree;

[0017] The operator and the column operation value are determined as operation data, and the operator and the column operation value are extracted.

[0018] In a possible implementation manner, determining a target query statement matching the item query statement from a plurality of candidate query statements based on the operation vector includes:

[0019] Determining, based on the operation vector, a similarity between the project query statement and each candidate query statement in a vector database;

[0020] The plurality of candidate query statements are sorted according to the similarity, and a candidate query statement at a front preset position is determined as a target query statement that matches the item query statement.

[0021] In a possible implementation manner, determining the similarity between the item query statement and each candidate query statement in the vector database based on the operation vector includes:

[0022] The search interface of the vector database is called to determine the similarity between the project query statement and each candidate query statement by comparing the operation vector with the candidate operation vector of each candidate query statement.

[0023] In one possible implementation, determining a similarity score between the project query and the target query based on the operation vector of the project query and the target operation vector of the target query includes:

[0024] Using preset algorithm parameters, a vector distance between the operation vector and the target operation vector of the target query statement is determined, and the vector distance is determined as a similarity score between the item query statement and the target query statement.

[0025] The embodiment of the present application further provides a method for executing a query statement based on similarity, the method comprising: determining the complexity of the project query statement based on a similarity score between the project query statement and the target query statement and the complexity of the target query statement; wherein the similarity score is obtained by the above-mentioned method for determining query statement similarity;

[0026] Determining the statement type of the project query statement based on the complexity of the project query statement;

[0027] Determining an execution mode of the project query statement based on the statement type;

[0028] Execute the project query statement according to the execution method.

[0029] In a possible implementation manner, determining the execution mode of the project query statement based on the statement type includes:

[0030] If the statement type is a simple query statement, determining that the execution mode of the project query statement is real-time execution;

[0031] If the statement type is a complex query statement, it is determined that the execution mode of the project query statement is delayed execution.

[0032] In a possible facility mode, when the execution mode is delayed execution, the execution method further includes:

[0033] In response to the thread configuration operation, configuring an execution thread for executing the project query statement and an execution time of the execution thread;

[0034] Executing the project query statement according to the execution mode includes:

[0035] According to the execution time, the execution thread is called to execute the project query statement.

[0036] The embodiment of the present application further provides a device for determining query sentence similarity, the device comprising:

[0037] Data acquisition module, used to obtain data query requirements of query projects;

[0038] A statement generation module is used to generate a project query statement based on the data query requirement by calling the data interface of the query statement generation framework; wherein the project query statement is used to obtain the query result required by the query project;

[0039] a data extraction module, configured to extract operation data from the project query statement by parsing the project query statement, and determine the operation vector of the project query statement;

[0040] a statement search module, configured to determine, based on the operation vector, a target query statement that matches the project query statement from a plurality of candidate query statements;

[0041] The similarity determination module is configured to determine a similarity score between the project query statement and the target query statement based on the operation vector of the project query statement and the target operation vector of the target query statement.

[0042] In a possible implementation, the data extraction module is configured to parse the project query statement, extract operation data from the project query statement, and determine the operation vector of the project query statement. The data extraction module is configured to:

[0043] Parsing the project query statement into an abstract syntax tree;

[0044] Performing a depth-first traversal on the abstract syntax tree, extracting operation data from the abstract syntax tree, and recording the operation data as a one-dimensional vector; wherein the one-dimensional vector records the operators and / or column operation values ​​involved in the item query statement; the one-dimensional vector is used to reflect the complexity of the item query statement;

[0045] After the depth-first traversal process is completed, the one-dimensional vector is determined as the operation vector of the item query statement.

[0046] In a possible implementation, when the data extraction module is used to perform a depth-first traversal on the abstract syntax tree and extract operation data from the abstract syntax tree, the data extraction module is used to:

[0047] Determining the operators and column operation values ​​involved in the project query statement by performing a depth-first traversal on the abstract syntax tree;

[0048] The operator and the column operation value are determined as operation data, and the operator and the column operation value are extracted.

[0049] In a possible implementation, when the statement search module is used to determine a target query statement matching the item query statement from multiple candidate query statements based on the operation vector, the statement search module is used to:

[0050] Determining, based on the operation vector, a similarity between the project query statement and each candidate query statement in a vector database;

[0051] The plurality of candidate query statements are sorted according to the similarity, and a candidate query statement at a front preset position is determined as a target query statement that matches the item query statement.

[0052] In a possible implementation, when the statement search module is used to determine the similarity between the item query statement and each candidate query statement in the vector database based on the operation vector, the statement search module is used to:

[0053] The search interface of the vector database is called to determine the similarity between the project query statement and each candidate query statement by comparing the operation vector with the candidate operation vector of each candidate query statement.

[0054] In one possible implementation, when the similarity determination module is configured to determine a similarity score between the item query and the target query based on the operation vector and the target operation vector of the target query, the similarity determination module is configured to:

[0055] Using preset algorithm parameters, a vector distance between the operation vector and the target operation vector of the target query statement is determined, and the vector distance is determined as a similarity score between the item query statement and the target query statement.

[0056] The embodiment of the present application further provides a device for executing a query statement based on similarity, the device comprising:

[0057] a complexity determination module, configured to determine the complexity of the project query statement based on the similarity score between the project query statement and the target query statement and the complexity of the target query statement; wherein the similarity score is obtained by the query statement similarity determination device according to claim 10;

[0058] A statement type determination module, configured to determine the statement type of the project query statement based on the complexity of the project query statement;

[0059] An execution mode determination module, configured to determine an execution mode of the project query statement based on the statement type;

[0060] The statement execution module is used to execute the project query statement according to the execution mode.

[0061] In a possible implementation, when the execution mode determination module is used to determine the execution mode of the project query statement based on the statement type, the execution mode determination module is used to:

[0062] If the statement type is a simple query statement, determining that the execution mode of the project query statement is real-time execution;

[0063] If the statement type is a complex query statement, it is determined that the execution mode of the project query statement is delayed execution.

[0064] In a possible implementation manner, when the execution mode is delayed execution, the determining device further includes a configuration module, and the configuration module is configured to:

[0065] In response to the thread configuration operation, configuring an execution thread for executing the project query statement and an execution time of the execution thread;

[0066] When the statement execution module is used to execute the project query statement according to the execution mode, the statement execution module is used to:

[0067] According to the execution time, the execution thread is called to execute the project query statement.

[0068] An embodiment of the present application also provides an electronic device, comprising: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the above-mentioned method for determining the similarity of query statements and / or the above-mentioned method for executing query statements based on similarity are performed.

[0069] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program executes the steps of the above-mentioned method for determining the similarity of query statements and / or the above-mentioned method for executing query statements based on similarity.

[0070] The embodiments of the present application provide a method, an execution method, and an apparatus for determining the similarity of query statements, which obtain data query requirements for a query project; based on the data query requirements, generate a project query statement by calling a data interface of a query statement generation framework; wherein the project query statement is used to obtain the query result required by the query project; by parsing the project query statement, operation data is extracted from the project query statement, and an operation vector of the project query statement is determined; based on the operation vector, a target query statement that matches the project query statement is determined from multiple candidate query statements; based on the operation vector of the project query statement and the target operation vector of the target query statement, a similarity score between the project query statement and the target query statement is determined. In this way, the similarity score of the query statement can be determined with the help of the calculation operation data involved in the query statement. Compared with using the text string of the query statement to calculate the similarity, the amount of data processing involved in the similarity determination process can be reduced, which helps to improve the efficiency of determining the similarity score and reduce the data processing pressure of the terminal device; and, in the process of forming the calculation operation vector of the project query statement, by mapping the calculation operation data of the project query statement into the form of a one-dimensional vector, the complexity of the calculation can be further reduced and the calculation efficiency can be improved through dimensionality reduction.

[0071] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.

[0073] Figure 1 A flowchart of a method for determining query sentence similarity provided in an embodiment of the present application;

[0074] Figure 2 A flowchart of a method for executing a query statement based on similarity provided in an embodiment of the present application;

[0075] Figure 3 A schematic diagram of the structure of a device for determining query sentence similarity provided in an embodiment of the present application;

[0076] Figure 4 A schematic diagram of the structure of a similarity-based query statement execution device provided in an embodiment of the present application;

[0077] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0078] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application for which protection is claimed, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, each other embodiment obtained by those skilled in the art without making creative work falls within the scope of protection of the present application.

[0079] Research has found that at present, text matching is usually adopted to use the text strings of SQL query statements to realize the similarity calculation between different SQL query statements. However, the text matching method has a large amount of calculation, which invisibly increases the data processing volume of the terminal device and brings greater data processing pressure to the terminal device.

[0080] Based on this, an embodiment of the present application provides a method for determining the similarity of query statements, which can use the calculation operation data involved in the query statement to determine the similarity score of the query statement. Compared with using the text string of the query statement for similarity calculation, it can reduce the amount of data processing involved in the similarity determination process, help improve the efficiency of determining the similarity score, and also reduce the data processing pressure of the terminal device.

[0081] See also Figure 1 , Figure 1 This is a flow chart of a method for determining query sentence similarity provided by an embodiment of the present application. Figure 1 As shown in , the method for determining query sentence similarity provided by the embodiment of the present application includes:

[0082] S101. Obtain data query requirements for the query project.

[0083] S102: Based on the data query requirement, generate a project query statement by calling the data interface of the query statement generation framework.

[0084] S103: parse the item query statement, extract operation data from the item query statement, and determine an operation vector of the item query statement.

[0085] S104: Determine a target query statement that matches the item query statement from multiple candidate query statements based on the calculation operation vector.

[0086] S105 : Determine a similarity score between the project query statement and the target query statement based on the operation vector of the project query statement and the target operation vector of the target query statement.

[0087] The embodiment of the present application provides a method for determining the similarity of query statements. By utilizing the data query requirements of the query project and calling the data interface of the query statement generation framework, a project query statement is generated to obtain the query result expected by the query project. In this way, the query statement is automatically generated, which assists developers and reduces the developer's code writing process. At the same time, with the help of the operation vectors involved in the project query statement, the target query statement that is most similar to the project query statement is searched from the vector database, and the similarity between the project query statement and the target query statement is determined. In this way, the similarity between query statements can be determined without converting the project query statement into a text string. The determination of similarity can be completed by only using the operation data involved in the project query statement. The data processing amount of the terminal device during the similarity determination process can also be reduced, reducing the data processing pressure of the terminal device.

[0088] In step S102, the data query requirements of the query project are provided to the query statement generation framework by calling the data interface of the query statement generation framework, so that the query statement generation framework can be combined with the data query requirements of the query project to generate a project query statement for obtaining the query results required by the query project.

[0089] Here, the called data interface can be an interface specially set up in the query statement generation framework for receiving required data; or it can be a data interface determined from multiple interfaces of the query statement generation framework and suitable for receiving data query requirements of the query project.

[0090] The data interface suitable for receiving the data query requirement of the query item may refer to the interface with the lowest load among multiple interfaces; or may refer to the data interface indicated in the data query requirement, etc.

[0091] The data interface indicated in the data query requirement may be determined by analyzing the data query requirement and based on the interface number carried in the data query requirement.

[0092] In step S103 , the generated item query statement is parsed to extract the operation data involved in the process of executing the item query statement from the item query statement, so as to determine the operation vector of the item query statement for subsequent similarity calculation.

[0093] Here, the calculation operation data can represent the semantic information and complexity of the project query statement; and for the query statement, its complexity can be reflected by the operators and column operation values ​​involved in the execution process; for example, if the project query statement involves more operators, it can be considered that the project query statement is more complex; for another example, if the project query statement involves more selection columns, it can be considered that the project query statement is more complex.

[0094] In one embodiment, step S103 includes:

[0095] S1031. Parse the project query statement into an abstract syntax tree.

[0096] In this step, the Apache Calcite algorithm is used to parse the project query statement into an Abstract Syntax Tree (AST).

[0097] S1032: Perform a depth-first traversal on the abstract syntax tree, extract operation data from the abstract syntax tree, and record the operation data as a one-dimensional vector.

[0098] In this step, the abstract syntax tree of the project query statement is traversed in depth first. During the depth first traversal, the operation data involved in the project query statement is extracted from the abstract syntax tree.

[0099] In order to facilitate the calculation of the similarity score between the project query statement and the target query statement, the similarity score between the project query statement and the target query statement can be determined by vectorizing the operation data of the project query statement and then calculating the similarity between vectors. That is, in the deep traversal process, the operation data is preferentially recorded as a one-dimensional vector.

[0100] Here, since the transportation operation data is the operator and / or column operation value extracted from the project query statement, the one-dimensional vector records the operator and / or column operation value involved in the project query statement; and since the number of operators and / or column operation values ​​reflects the complexity of the project query statement, the one-dimensional vector can reflect the complexity of the project query statement.

[0101] In this way, by mapping the calculation operation data of the project query statement into the form of a one-dimensional vector, the data dimension of the calculation operation data is reduced, and the complexity of the calculation is further reduced by dimensionality reduction, thereby improving the calculation efficiency of the similarity score in the subsequent process.

[0102] At the same time, in order to facilitate the matching of candidate operation vectors in the Zilliz vector database, the operation vectors of the project query statement are stored in the Zilliz vector database.

[0103] In one embodiment, step S1032 includes:

[0104] S10321. Determine the operators and column operation values ​​involved in the item query statement by performing a depth-first traversal on the abstract syntax tree.

[0105] The calculation operation data can be divided into two parts: one is the operator, such as the aggregation operator (AggregateOperator), the filter operator (Filter Operator), the group aggregation operator (Group By Operator) and the order operator (Order Operator); the other is the column operation value, such as the select column (SelectColumn) value, the function column (FunctionColumn) value, etc.

[0106] S10322. Determine the operator and the column operation value as operation data, and extract the operator and the column operation value.

[0107] In this step, both operators and column operation values ​​can be used to characterize the semantic information and complexity of the project query statement; therefore, the operators and column operation values ​​in the project query statement are determined as the calculation operation data of the project query statement, and the determined operators and column operation values ​​are extracted to complete the extraction of the calculation operation data.

[0108] S1033. After the depth-first traversal process is completed, the one-dimensional vector is determined as the operation vector of the item query statement.

[0109] In step S104, the operation vector obtained by parsing the project query statement is used to search among the candidate query statements in the vector database to determine the target query statement that is most similar to and matches the project query statement.

[0110] Here, the target query statement that is most similar to the project query statement may be selected by determining the similarity between the project query statement and each candidate query statement.

[0111] In one embodiment, step S104 includes:

[0112] S1041. Determine the similarity between the item query statement and each candidate query statement in the vector database based on the operation vector.

[0113] In this step, the similarity between the project query statement and each candidate query statement in the vector database can be determined by comparing the operation data of the project query statement with the operation data involved in each candidate query statement.

[0114] In one embodiment, step S1041 includes: calling a search interface of the vector database, and determining the similarity between the project query statement and each candidate query statement by comparing the operation vector with the candidate operation vector of each candidate query statement.

[0115] In this step, the search interface of the vector database is called to determine the similarity between the project query statement and each candidate query statement by comparing the operation vector of the project query statement with the candidate operation vector of each candidate query statement one by one.

[0116] Here, the search interface called may be an interface specially set in the vector database for performing search operations; or may be a search interface determined from multiple interfaces in the vector database and suitable for performing search operations.

[0117] The search interface suitable for performing the search operation may refer to the interface with the lowest load among multiple interfaces of the vector database; or may refer to the search interface indicated in the data query requirement, etc.

[0118] The search interface indicated in the data query requirement may be determined by analyzing the data query requirement and based on the interface number carried in the data query requirement.

[0119] S1042: Sort the multiple candidate query statements according to the similarity, and determine the candidate query statement at a front preset position as a target query statement matching the item query statement.

[0120] In this step, multiple candidate query statements are sorted according to the determined similarities, and the candidate query statement at the front preset position is determined as the target query statement that matches the project query statement; here, the candidate query statement with the highest similarity to the project query statement in the vector database can be determined as the target query statement that matches the project query statement; wherein, the vector database can be a Zilliz vector database, and the Zilliz vector database can be used to store the calculation operation data of the project query statement, and to execute the matching process of the target query statement.

[0121] In step S105, for the determined target query statement, the similarity score between the project query statement and the target query statement is determined again with the help of the calculation operation vector of the project query statement and the target operation vector of the target query statement, so that the complexity of the project query statement can be further determined based on the similarity score between the two and combined with the complexity of the target query statement.

[0122] In one embodiment, step S105 includes: using preset algorithm parameters, determining a vector distance between the operation vector and a target operation vector of the target query statement, and determining the vector distance as a similarity score between the item query statement and the target query statement.

[0123] In this step, by utilizing preset algorithm parameters and combining the operation vector of the project query vector and the target operation vector of the target query statement, the similarity score between the project query statement and the target query statement can be determined by calculating the vector distance between the vectors, etc.; wherein, the vector distance is negatively correlated with the similarity score.

[0124] Here, the Approximate Nearest Neighbor (ANN) algorithm can be used to calculate the similarity between two sets of vectors, and the algorithm toolkit used is: Annoy (Approximate Nearest Neighbors OhYeah).

[0125] The method for determining the similarity of query statements provided in the embodiment of the present application comprises the following steps: obtaining a data query requirement for a query project; generating a project query statement based on the data query requirement by calling a data interface of a query statement generation framework; wherein the project query statement is used to obtain the query result required by the query project; extracting operation data from the project query statement by parsing the project query statement, and determining an operation vector of the project query statement; determining a target query statement that matches the project query statement from a plurality of candidate query statements based on the operation vector; and determining a similarity score between the project query statement and the target query statement based on the operation vector of the project query statement and the target operation vector of the target query statement. In this way, the determination of the query statement similarity score can be achieved with the help of the operation data involved in the query statement. Compared with similarity calculation based on the text string of the query statement, the amount of data processing involved in the similarity determination process can be reduced, which helps to improve the efficiency of determining the similarity score and reduce the data processing pressure of the terminal device.

[0126] Here, after determining the similarity score between the project query statement and the target query statement, the complexity of the project query statement can be further determined in combination with the similarity score; on this basis, considering that executing complex query statements will consume more computing resources of the terminal device, in order to avoid delaying the query time of other projects, the execution method of the project query statement can be reasonably planned according to the complexity of the project query statement to realize the planning of the execution time and execution thread of the project query statement.

[0127] For example, if the project query statement has a high similarity score with a candidate query statement of extremely high complexity, then the project query statement can be considered a complex query statement; however, for complex query statements, if a real-time execution method is adopted, it will occupy a large amount of computing resources of the terminal device for a long time, reduce the response frequency of the terminal device, and also reduce the feedback efficiency of other query items;

[0128] On the contrary, if the project query statement has a higher similarity score with a candidate query statement with a lower degree of complexity, then the project query statement can be considered as a simple query statement; and for simple query statements, since they have a lower occupancy rate of the terminal device computing resources, in order to be able to provide timely feedback to the query personnel, a real-time execution method can be adopted.

[0129] See also Figure 2 , Figure 2 This is a flowchart of a method for executing a query statement based on similarity provided in an embodiment of the present application. Figure 2 As shown in , the query statement execution method provided in the embodiment of the present application includes:

[0130] S201: Determine the complexity of the project query statement based on a similarity score between the project query statement and the target query statement and in combination with the complexity of the target query statement.

[0131] In this step, based on the similarity score between the project query statement and the target query statement, combined with the complexity of the target query statement, the similarity score can be used as a proportional coefficient to determine the complexity of the project query statement; for example, if the similarity score between the project query statement and the target query statement is 0.9 and the complexity of the target query statement is 10′, then the complexity of the project query statement can be calculated to be 9′.

[0132] S202: Determine the statement type of the project query statement based on the complexity of the project query statement.

[0133] In this step, the statement type of the project query statement is determined in combination with the complexity of the project query statement and with reference to the complexity range corresponding to each statement type; corresponding to the above embodiment, taking the statement type including complex query statements and simple query statements as an example, the complexity range of simple query statements is [1~5] and the complexity range of complex query statements is [6~10]; then, if the complexity of the project query statement is 9′, it can be determined that the project query statement is a complex query statement.

[0134] Here, for a project query statement whose statement type is a complex query statement, if the project query statement is executed in real time, it will consume a large amount of computing resources of the terminal device. Therefore, it is also necessary to refer to the statement type of the project query statement to further determine the execution method of the project query statement.

[0135] S203: Determine an execution mode of the project query statement based on the statement type.

[0136] In this step, the execution time and execution mode of the project query statement are planned in combination with the statement type of the project query statement, and the execution mode of the project query statement is determined; wherein the execution mode includes at least real-time execution and delayed execution.

[0137] S204: Execute the project query statement according to the execution method.

[0138] In this step, the project query statement is executed according to the determined execution mode.

[0139] In one embodiment, step S203 includes:

[0140] S2031. If the statement type is a simple query statement, determine that the execution mode of the project query statement is real-time execution.

[0141] In this step, if it is determined that the project query statement is a simple query statement, it is considered that the project query statement can be executed in real time, and then the execution mode of the project query statement can be determined to be real-time execution.

[0142] S2032: If the statement type is a complex query statement, determine that the execution mode of the project query statement is delayed execution.

[0143] In this step, if the project query statement is determined to be a complex query statement, if the project query statement is executed immediately, it will occupy a large amount of computing resources of the terminal device. Therefore, it is necessary to select another appropriate time to execute the project query statement. Then, the execution mode of the project query statement can be determined as delayed execution.

[0144] When the execution mode of a project query statement is delayed execution, business personnel can independently trigger the execution time of the project query statement and the planning of the execution thread through thread configuration operations.

[0145] In one embodiment, when the execution mode is delayed execution, the determination method further includes: configuring an execution thread for executing the item query statement and an execution time of the execution thread in response to a thread configuration operation.

[0146] In this step, the business personnel can configure the corresponding execution thread and execution time for the project query statement through thread configuration operation; specifically, in response to the thread configuration operation applied by the business personnel, the corresponding execution thread and execution time are configured for the project query statement.

[0147] Here, business personnel can complete the configuration of execution threads and execution time by touching the thread configuration control displayed in the thread configuration operation graphical user interface; specifically, business personnel can touch the thread configuration control with their fingers, mouse, and / or preset combination keys; for example: the ctrl key, alt key, a key, etc. on the keyboard. The preset keys can be manually set according to the needs of business personnel.

[0148] The thread configuration operation may include a sliding operation, a clicking operation, an input operation, etc., which may be determined according to actual conditions.

[0149] Step S204 includes: calling the execution thread according to the execution time, and executing the project query statement.

[0150] In this step, the query statement for the project may be executed in a timely manner by calling the execution thread configured for the query statement for the project according to the configured execution time.

[0151] The similarity-based query execution method provided in an embodiment of the present application determines the complexity of the project query based on the similarity score between the project query and the target query, as well as the complexity of the target query; determines the statement type of the project query in combination with the complexity of the project query; determines the execution mode of the project query based on the statement type; and executes the project query according to the execution mode. In this way, the execution mode of the project query can be reasonably planned based on the complexity of the project query, thereby realizing the planning of the execution time and execution thread of the project query.

[0152] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of a device for determining query sentence similarity provided by an embodiment of the present application. Figure 3 As shown in , the determining device 300 includes:

[0153] The data acquisition module 310 is used to obtain the data query requirements of the query project;

[0154] The statement generation module 320 is used to generate a project query statement based on the data query requirement by calling the data interface of the query statement generation framework; wherein the project query statement is used to obtain the query result required by the query project;

[0155] A data extraction module 330 is configured to extract operation data from the project query statement by parsing the project query statement, and determine an operation vector of the project query statement;

[0156] A statement search module 340 is configured to determine a target query statement that matches the item query statement from a plurality of candidate query statements based on the operation vector;

[0157] The similarity determination module 350 is configured to determine a similarity score between the project query statement and the target query statement based on the operation vector of the project query statement and the target operation vector of the target query statement.

[0158] Furthermore, when the data extraction module 330 is used to parse the item query statement, extract the operation data from the item query statement, and determine the operation vector of the item query statement, the data extraction module 330 is used to:

[0159] Parsing the project query statement into an abstract syntax tree;

[0160] Performing a depth-first traversal on the abstract syntax tree, extracting operation data from the abstract syntax tree, and recording the operation data as a one-dimensional vector; wherein the one-dimensional vector records the operators and / or column operation values ​​involved in the item query statement; the one-dimensional vector is used to reflect the complexity of the item query statement;

[0161] After the depth-first traversal process is completed, the one-dimensional vector is determined as the operation vector of the item query statement.

[0162] Furthermore, when the data extraction module 330 is used to perform a depth-first traversal on the abstract syntax tree and extract operation data from the abstract syntax tree, the data extraction module 330 is used to:

[0163] Determining the operators and column operation values ​​involved in the project query statement by performing a depth-first traversal on the abstract syntax tree;

[0164] The operator and the column operation value are determined as operation data, and the operator and the column operation value are extracted.

[0165] Furthermore, when the statement search module 340 is used to determine a target query statement matching the item query statement from multiple candidate query statements based on the operation vector, the statement search module 340 is used to:

[0166] Determining, based on the operation vector, a similarity between the project query statement and each candidate query statement in a vector database;

[0167] The plurality of candidate query statements are sorted according to the similarity, and a candidate query statement at a front preset position is determined as a target query statement that matches the item query statement.

[0168] Furthermore, when the statement search module 340 is used to determine the similarity between the item query statement and each candidate query statement in the vector database based on the operation vector, the statement search module 340 is used to:

[0169] The search interface of the vector database is called to determine the similarity between the project query statement and each candidate query statement by comparing the operation vector with the candidate operation vector of each candidate query statement.

[0170] Furthermore, when the similarity determination module 350 is used to determine the similarity score between the item query and the target query based on the operation vector and the target operation vector of the target query, the similarity determination module 350 is used to:

[0171] Using preset algorithm parameters, a vector distance between the operation vector and the target operation vector of the target query statement is determined, and the vector distance is determined as a similarity score between the item query statement and the target query statement.

[0172] The embodiment of the present application provides a device for determining the similarity of query statements, which obtains a data query requirement for a query project; based on the data query requirement, generates a project query statement by calling a data interface of a query statement generation framework; wherein the project query statement is used to obtain the query result required by the query project; extracts operation data from the project query statement by parsing the project query statement, and determines an operation vector of the project query statement; based on the operation vector, determines a target query statement that matches the project query statement from multiple candidate query statements; and determines a similarity score between the project query statement and the target query statement based on the operation vector of the project query statement and the target operation vector of the target query statement. In this way, the query statement similarity score can be determined with the help of the operation data involved in the query statement. Compared with similarity calculation based on the text string of the query statement, the amount of data processing involved in the similarity determination process can be reduced, which helps to improve the efficiency of determining the similarity score and reduce the data processing pressure of the terminal device.

[0173] See also Figure 4 , Figure 4 This is a schematic diagram of the structure of a similarity-based query statement execution device provided in an embodiment of the present application. Figure 4 As shown in , the execution device 400 includes:

[0174] A complexity determination module 410 is configured to determine the complexity of the project query based on the similarity score between the project query and the target query and the complexity of the target query; wherein the similarity score is obtained by the query similarity determination device described above;

[0175] A statement type determination module 420 is configured to determine the statement type of the project query statement based on the complexity of the project query statement;

[0176] An execution mode determination module 430 is configured to determine an execution mode of the project query statement based on the statement type;

[0177] The statement execution module 440 is used to execute the project query statement according to the execution mode.

[0178] Furthermore, when the execution mode determination module 430 is used to determine the execution mode of the project query statement based on the statement type, the execution mode determination module 430 is used to:

[0179] If the statement type is a simple query statement, determining that the execution mode of the project query statement is real-time execution;

[0180] If the statement type is a complex query statement, it is determined that the execution mode of the project query statement is delayed execution.

[0181] Furthermore, when the execution mode is delayed execution, the execution device 400 further includes a configuration module 450 (not shown in the figure), and the configuration module 450 is used to:

[0182] In response to the thread configuration operation, configuring an execution thread for executing the project query statement and an execution time of the execution thread;

[0183] When the statement execution module 440 is used to execute the project query statement according to the execution mode, the statement execution module 440 is used to:

[0184] According to the execution time, the execution thread is called to execute the project query statement.

[0185] The similarity-based query statement execution device provided in an embodiment of the present application determines the complexity of the project query statement based on the similarity score between the project query statement and the target query statement and the complexity of the target query statement; determines the statement type of the project query statement in combination with the complexity of the project query statement; determines the execution mode of the project query statement based on the statement type; and executes the project query statement according to the execution mode. In this way, the execution mode of the project query statement can be reasonably planned based on the complexity of the project query statement, thereby realizing the planning of the execution time and execution thread of the project query statement.

[0186] See also Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 5 As shown in FIG, the electronic device 500 includes a processor 510, a memory 520 and a bus 530.

[0187] The memory 520 stores machine-readable instructions executable by the processor 510. When the electronic device 500 is running, the processor 510 communicates with the memory 520 via the bus 530. When the machine-readable instructions are executed by the processor 510, the above-mentioned Figure 1 The steps of the method for determining the similarity of query statements in the embodiment of the method shown and Figure 2 The specific implementation of the steps of the method for executing the query statement based on similarity in the method embodiment shown can be found in the method embodiment, and will not be repeated here.

[0188] The embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer program can execute the above-mentioned Figure 1 The steps of the method for determining the similarity of query statements in the embodiment of the method shown and Figure 2 The specific implementation of the steps of the method for executing the query statement based on similarity in the method embodiment shown can be found in the method embodiment, and will not be repeated here.

[0189] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0190] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. There may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be through some communication interface, indirect coupling or communication connection of devices or units, which may be electrical, mechanical or other forms.

[0191] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0192] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0193] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0194] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The scope of protection of the present application is not limited thereto. Although the present application has been described in detail with reference to the above-mentioned embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-mentioned embodiments within the technical scope disclosed in the present application, or perform equivalent replacements for some of the technical features thereof. These modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A method for determining query sentence similarity, characterized in that: The determination method includes: Get the data query requirements of the query project; Based on the data query requirements, a project query statement is generated by calling a data interface of a query statement generation framework; wherein the project query statement is used to obtain the query results required by the query project; Parsing the project query statement into an abstract syntax tree, extracting operation data from the project query statement based on the abstract syntax tree, and determining an operation vector for the project query statement; wherein the operation data includes operators and / or column operation values ​​involved in the project query statement; Determining a target query statement matching the item query statement from a plurality of candidate query statements based on the operation vector; determining a similarity score between the project query and the target query based on the operation vector of the project query and the target operation vector of the target query; The step of parsing the query statement into an abstract syntax tree, extracting operation data from the query statement based on the abstract syntax tree, and determining an operation vector for the query statement includes: Performing a depth-first traversal on the abstract syntax tree, extracting operation data from the abstract syntax tree, and recording the operation data as a one-dimensional vector; wherein the one-dimensional vector records the operators and / or column operation values ​​involved in the item query statement; the one-dimensional vector is used to reflect the complexity of the item query statement; After the depth-first traversal process is completed, the one-dimensional vector is determined as the operation vector of the item query statement.

2. The determination method according to claim 1, characterized in that The performing a depth-first traversal on the abstract syntax tree to extract operation data from the abstract syntax tree includes: Determining the operators and column operation values ​​involved in the project query statement by performing a depth-first traversal on the abstract syntax tree; The operator and the column operation value are determined as operation data, and the operator and the column operation value are extracted.

3. The determination method according to claim 1, characterized in that Determining a target query statement matching the item query statement from a plurality of candidate query statements based on the operation vector includes: Determining, based on the operation vector, a similarity between the project query statement and each candidate query statement in a vector database; The plurality of candidate query statements are sorted according to the similarity, and a candidate query statement at a front preset position is determined as a target query statement that matches the item query statement.

4. The determination method according to claim 3, characterized in that: Determining the similarity between the item query statement and each candidate query statement in a vector database based on the operation vector includes: The search interface of the vector database is called to determine the similarity between the project query statement and each candidate query statement by comparing the operation vector with the candidate operation vector of each candidate query statement.

5. The determination method according to claim 1, characterized in that: The determining of a similarity score between the project query and the target query based on the operation vector of the project query and the target operation vector of the target query includes: Using preset algorithm parameters, a vector distance between the operation vector and the target operation vector of the target query statement is determined, and the vector distance is determined as a similarity score between the item query statement and the target query statement.

6. A method for executing a query statement based on similarity, characterized in that: The execution method includes: Obtaining a similarity score based on the method for determining query sentence similarity according to any one of claims 1 to 5; Determining the complexity of the project query statement based on a similarity score between the project query statement and the target query statement and the complexity of the target query statement; Determining the statement type of the project query statement based on the complexity of the project query statement; Determining an execution mode of the project query statement based on the statement type; Execute the project query statement according to the execution method.

7. The execution method according to claim 6, characterized in that: The determining, based on the statement type, how to execute the project query statement includes: If the statement type is a simple query statement, determining that the execution mode of the project query statement is real-time execution; If the statement type is a complex query statement, it is determined that the execution mode of the project query statement is delayed execution.

8. The execution method according to claim 7, characterized in that: When the execution mode is delayed execution, the execution method further includes: In response to the thread configuration operation, configuring an execution thread for executing the project query statement and an execution time of the execution thread; Executing the project query statement according to the execution mode includes: According to the execution time, the execution thread is called to execute the project query statement.

9. A device for determining query sentence similarity, characterized in that: The determining device comprises: Data acquisition module, used to obtain data query requirements of query projects; A statement generation module is used to generate a project query statement based on the data query requirement by calling the data interface of the query statement generation framework; wherein the project query statement is used to obtain the query result required by the query project; a data extraction module, configured to parse the project query statement into an abstract syntax tree, extract operation data from the project query statement based on the abstract syntax tree, and determine an operation vector for the project query statement; wherein the operation data includes operators and / or column operation values ​​involved in the project query statement; a statement search module, configured to determine, based on the operation vector, a target query statement that matches the project query statement from a plurality of candidate query statements; a similarity determination module, configured to determine a similarity score between the project query statement and the target query statement based on the operation vector of the project query statement and the target operation vector of the target query statement; The data extraction module determines the operation vector of the project query statement through the following steps: Performing a depth-first traversal on the abstract syntax tree, extracting operation data from the abstract syntax tree, and recording the operation data as a one-dimensional vector; wherein the one-dimensional vector records the operators and / or column operation values ​​involved in the item query statement; the one-dimensional vector is used to reflect the complexity of the item query statement; After the depth-first traversal process is completed, the one-dimensional vector is determined as the operation vector of the item query statement.

10. A device for executing query statements based on similarity, characterized in that: The execution device includes: a similarity score determination module, configured to obtain a similarity score based on the query statement similarity determination device according to claim 9; a complexity determination module, configured to determine the complexity of the project query statement based on the similarity score between the project query statement and the target query statement and the complexity of the target query statement; A statement type determination module, configured to determine the statement type of the project query statement based on the complexity of the project query statement; An execution mode determination module, configured to determine an execution mode of the project query statement based on the statement type; The statement execution module is used to execute the project query statement according to the execution mode.

Citation Information

Patent Citations

  • Method and device for generating SQL statements according to natural languages

    CN110888897A

  • Query statement generation method and device based on grammar parse tree, equipment and medium

    CN116304231A