A database query method, device, medium and computer program product

By converting the database into a graph model and converting the query statement into a graph query, determining the optimal query path to optimize database queries, the problem of inefficient database query optimization in the existing technology is solved, and efficient query processing and system performance improvement is achieved.

CN118885507BActive Publication Date: 2025-02-07INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411366415.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2025-02-07
Estimated Expiration
2044-09-29

AI Technical Summary

Technical Problem

Existing database query optimization methods are inefficient when processing complex queries and large-scale data, and the optimization steps are single, so they cannot adapt to different types of databases and query scenarios.

Method used

Convert the database to a graph model, and convert the structured query statement into a graph query. By determining the optimal query path, the graph query is optimized, thereby generating the optimized structured query statement for execution.

Benefits of technology

It improves the execution efficiency of database queries, reduces resource consumption, enhances the adaptability of the system, and can handle complex queries and large-scale data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118885507B_ABST
    Figure CN118885507B_ABST
Patent Text Reader

Abstract

The present invention discloses a database query method, device, medium and computer program product, which relates to the field of database technology. The database is converted into a graph model, the corresponding query statement is converted into a graph query, and the graph query is optimized by determining the optimal query path of the current query process, thereby optimizing the structured query statement by utilizing the process of optimizing the graph query, and finally using the optimized structured query statement to execute the query, thereby improving the execution efficiency of the entire query process, achieving efficient query processing, reducing the resource consumption of query execution, and improving the overall performance of the database system. The entire process does not rely on predefined rules or fixed cost models, but achieves query optimization by real-time analysis and optimization of query paths. The present invention can handle complex queries and large-scale data and has stronger adaptability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a database query method, device, medium and computer program product. Background Art

[0002] The optimization of database query process plays an important role in database system. Its purpose is to reduce query response time and improve system performance by selecting the best query execution plan. At present, query optimization methods mainly rely on optimizers based on rules and costs. However, with the advent of the big data era, as the amount of data and query complexity increase dramatically, these methods have shown certain limitations in processing complex queries and large-scale data, with a single optimization step and low efficiency.

[0003] It can be seen that how to provide an efficient database query optimization method is a problem that technical personnel in this field need to solve. Summary of the invention

[0004] The purpose of the embodiments of the present invention is to provide a database query method, device, medium and computer program product, which can solve the problem of optimizing database query.

[0005] To solve the above technical problems, an embodiment of the present invention provides a database query method, including: converting a database into a graph model; when receiving a structured query statement for querying the database, converting the structured query statement into a graph query; determining an optimal query path for the graph query in the graph model, and adding query constraints to the graph query based on the optimal query path; generating an optimized structured query statement based on the graph query after adding the query constraints; and submitting the optimized structured query statement to the database for execution.

[0006] On the one hand, the conversion of a database into a graph model includes: extracting data table information and foreign key constraint information in the database; determining each data table in the database based on the data table information; determining the foreign key relationship between each data table based on the foreign key constraint information; mapping the data tables into nodes and mapping the foreign key relationships into edges to convert the database into a graph model.

[0007] On the one hand, after extracting the data table information and foreign key constraint information from the database, the method further includes: using the data table information or the foreign key constraint information extracted from the database as data to be cleaned; and performing data cleaning on the data to be cleaned.

[0008] On the one hand, the data cleaning of the data to be cleaned includes: performing outlier detection on the data to be cleaned using a standard deviation; and removing the detected outliers from the data to be cleaned.

[0009] On the one hand, the data cleaning of the data to be cleaned includes: determining whether all data in the data to be cleaned are in the same data format; if not, converting all data in the data to be cleaned into the same data format.

[0010] On the one hand, after converting all the data in the data to be cleaned into the same data format, it also includes: judging whether there are missing values ​​in the converted data to be cleaned; if so, filling the missing values ​​by using mean filling or interpolation method.

[0011] On the one hand, the data cleaning of the data to be cleaned includes: scaling all data in the data to be cleaned to a preset interval.

[0012] On the one hand, after mapping the data table to nodes and mapping the foreign key relationships to edges, the method further includes: merging similar nodes among the nodes into one node and / or removing redundant edges among the edges.

[0013] On the one hand, converting the structured query statement into a graph query includes: extracting query information in the structured query statement, the query information including tables, fields and conditions; mapping the query information to the graph model to generate a graph query corresponding to the structured query statement.

[0014] On the one hand, before submitting the optimized structured query statement to the database for execution, the method further includes: performing a grammar check on the optimized structured query statement; if the optimized structured query statement conforms to a preset grammar rule, the method jumps to the step of submitting the optimized structured query statement to the database for execution.

[0015] On the one hand, before submitting the optimized structured query statement to the database for execution, the method further includes: submitting the optimized structured query statement to an execution plan generator of the database for execution plan verification.

[0016] On the one hand, determining the optimal query path of the graph query in the graph model includes: determining a subgraph pattern in the graph query; determining a graph algorithm corresponding to the subgraph pattern; performing subgraph matching on the graph model using the graph algorithm and the subgraph pattern in the graph query; and using the path with the smallest query cost in the subgraph matching process as the optimal query path of the graph query in the graph model.

[0017] To solve the above technical problem, an embodiment of the present invention further provides an electronic device, comprising: a memory for storing a computer program; and a processor for executing the computer program to implement the steps of the aforementioned database query method.

[0018] To solve the above technical problem, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the aforementioned database query method are implemented.

[0019] To solve the above technical problem, an embodiment of the present invention further provides a computer program product, including a computer program / instruction, which implements the steps of the aforementioned database query method when executed by a processor.

[0020] It can be seen from the above technical solution that by converting the database into a graph model, converting the corresponding query statement into a graph query, and optimizing the graph query by determining the optimal query path of the current query process, the structured query statement is optimized by utilizing the process of optimizing the graph query, and finally the optimized structured query statement is used to execute the query, thereby improving the execution efficiency of the entire query process, achieving efficient query processing, reducing the resource consumption of query execution, and improving the overall performance of the database system. The beneficial effect of the present invention is that the entire process does not rely on predefined rules or fixed cost models, but achieves query optimization by real-time analysis and optimization of query paths. The present invention can handle complex queries and large-scale data and is more adaptable. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0022] Figure 1 A schematic diagram of a flow chart of a database query method provided by an embodiment of the present invention;

[0023] Figure 2 A schematic diagram of a flow chart of another database query method provided by an embodiment of the present invention;

[0024] Figure 3 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0025] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0026] The terms "including" and "having" in the specification of the present invention and the above-mentioned drawings, as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including a series of steps or units is not limited to the listed steps or units, but may include steps or units that are not listed.

[0027] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0028] Next, a database query method provided by an embodiment of the present invention is described in detail. Figure 1 As shown, Figure 1 A flowchart of a database query method provided by an embodiment of the present invention, the database query method includes:

[0029] S11: Convert the database into a graph model.

[0030] It is understandable that the data in the database needs to be preprocessed first to facilitate the subsequent optimization process, and the data preprocessing module is used to convert the database into a graph model. The data preprocessing module is responsible for converting the tables and their relationships in the database into a graph model. The nodes in the graph model represent data records, and the edges represent the relationships between data records. A data record refers to a complete set of related information corresponding to a row of information in a data source. For example, all the information about a certain customer in a customer mailing list is a data record. For a database, a data record generally refers to a data table in the database. By converting the database into a graph model, graph query and the optimization process of graph query can be used to simplify the query path when querying, optimize the SQL (Structured Query Language) statement for querying the database, and improve query efficiency.

[0031] S12: When a structured query statement for querying a database is received, the structured query statement is converted into a graph query.

[0032] It is not difficult to understand that when a user needs to query a database, he or she will enter a structured query statement into the database according to the query requirements. At this time, the query parsing module is responsible for converting the user's SQL query statement into a graph query, thereby mapping the user's query operation into the graph model. In this way, the user's query operation is converted into a query process in the graph model obtained by database conversion using the graph query language.

[0033] S13: Determine the optimal query path of the graph query in the graph model, and add query constraints to the graph query based on the optimal query path.

[0034] It is understandable that on the basis of converting the database into a graph model and converting the structured query statement into a graph query, a graph query optimization module can be used to optimize the graph query using a graph algorithm. There are many ways to query in a database, and accordingly, there are also multiple choices for the way graph queries are queried in a graph model. Specifically, when querying in a graph model, due to the different associations between nodes, the query path will have many branches. Therefore, when querying, there are many different query paths to find the final query result, but different query paths are of different lengths, and the query cost and query time required are also different. Therefore, optimizing the graph query specifically refers to finding the optimal query path in the graph model. The optimal query path refers to the path with the lowest query cost, which can also be called the path with the shortest query path. Using this optimal query path in the graph model can obtain the query result corresponding to the graph query at the lowest cost in the shortest time, thereby effectively improving the query efficiency. By determining the optimal query path, some additional query conditions or execution conditions can be obtained so that when executing this graph query, the query results can only be obtained through the optimal query path. These additional query conditions or execution conditions are added to the graph query as new query constraints, thereby realizing the optimization process of the graph query.

[0035] It should be noted that graph algorithms specifically include shortest path algorithms, maximum flow algorithms, and graph traversal algorithms, etc. For graph models of different modes, the most preferred graph algorithms may also be different. Therefore, the process of determining the optimal query path of the graph query in the graph model specifically includes pattern matching the graph model, identifying common structural patterns, determining the selected graph algorithm based on the structural pattern corresponding to the graph model, and then using the selected graph algorithm to determine the optimal query path. For example, a graph traversal algorithm is used to optimize the graph query path and reduce the number of graph traversals required for the query. A heuristic algorithm is used to select the query path, giving priority to paths with lower costs.

[0036] S14: Generate an optimized structured query statement based on the graph query after adding query constraints.

[0037] It is not difficult to understand that the process of converting a database into a graph model is just that the underlying data of the database may be conceptualized or abstracted into a graph model for query optimization. The process of converting to a graph model is to add a layer of optimization module in the middle of the database query process, but the actual physical storage and query execution are usually still carried out in the form of a traditional relational database, and it is still necessary to query in the database to obtain the query results required by the end user. Therefore, after optimizing the graph query using the optimal query path, it is still necessary to convert the process of optimizing the graph query into the process of optimizing the structured query statement. Therefore, it is necessary to convert the graph query after adding query constraints, that is, the optimized graph query, back into the form of SQL query. At this time, the query rewrite module is used to regenerate the optimized SQL query based on the optimized graph query.

[0038] Specifically, after the optimized graph query is converted into an equivalent SQL query, the SQL query can be further optimized according to the execution plan generator of the database. The regenerated optimized SQL query can also be syntax checked and the execution plan verified to ensure the normal implementation of the optimized structured query statement. After the query path is optimized using the graph algorithm, it is converted back to an SQL query to be executed using the existing database system, which ensures that while the query process is optimized, the query statement finally executed is compatible with the existing database execution environment.

[0039] It is understandable that in actual SQL statement writing, operators will also pre-prepare some sorting conditions to speed up the query. The role of graph query optimization is similar to this operation. It can add some query conditions by determining the optimal query path. Graph query optimization can determine the shortest path between nodes. For example, it can be found that the order date path can more effectively cache and access continuous data blocks. Then, adding date sorting to the SQL statement can effectively locate the entire block of data, and naturally the query will succeed more quickly. Therefore, the query rewrite module is mainly responsible for regenerating optimized SQL queries from optimized graph queries, thereby improving the execution efficiency of queries.

[0040] It should be noted that graph query conversion is the process of converting an optimized graph query into an equivalent SQL query. There are many options for generating optimized structured query statements based on the optimized graph query, and this application does not make any special limitations here. As a specific embodiment, the optimized graph query can be parsed first to extract the node and edge information. The node information includes the node attributes and the data records corresponding to the node, that is, the table corresponding to the node. The edge information includes the conditions corresponding to the edge; then, according to the nodes and edges in the graph query, the corresponding SQL query statement is generated; the specific mapping relationship between the nodes and edges during conversion is ; Where V represents the node set and E represents the edge set.

[0041] S15: Submit the optimized structured query statement to the database for execution.

[0042] It is not difficult to understand that the query execution module finally submits the optimized SQL query to the database for execution. During the query execution process, the performance indicators of the query execution process can be further monitored, including execution time, memory usage, CPU occupancy, etc., and feedback information of the query execution can be collected. The feedback information can be used to update the graph model and the optimization strategy of the graph query later. The specific process of updating the graph model and the optimization strategy of the graph query using feedback information needs to be selected and adjusted according to the actual application situation, and this application does not make any special restrictions here.

[0043] Furthermore, after the query process is completed, the result return module can be used to return the query results to the user, and the graph model and query optimization strategy can be further optimized based on the feedback information of the query execution. When returning the query results to the user, it is best to format the query results into a user-friendly data format. The user-friendly data format refers to a data format that can be directly used or edited by the user. At the same time, the performance indicators of the monitored query execution process can also be displayed, so that the user can determine the direction of improvement based on the performance indicators and generate corresponding feedback information, thereby further optimizing the subsequent query processing flow.

[0044] It should be noted that the graph query itself is also a graph model, so the entire database query process involves two different graph models, namely, a graph model corresponding to the database obtained by database conversion and a graph query corresponding to the structured query statement. The nodes in the graph query represent the tables and fields to be queried, and the edges in the graph query usually represent the query conditions. These edges can represent the relationship between tables (such as the JOIN operation of the structured query statement) or the logical conditions within the table (such as the conditions in the WHERE clause of the structured query statement). Fields refer to the fields specified in the SQL query, which determine the data columns that need to be displayed in the query results.

[0045] As a specific embodiment, see Figure 2 As shown, Figure 2A flow chart of another database query method provided for an embodiment of the present invention; the specific flow of the entire database query method includes data preprocessing to query parsing, graph query optimization to query rewriting, and query execution to result return. First, after the data preprocessing module converts the tables and their relationships in the database into a graph model, the query parsing module converts the user's SQL query into a graph query. Secondly, after the graph query optimization module optimizes the graph query, the query rewriting module generates an optimized SQL query based on the optimized graph query. Finally, the query execution module submits the optimized SQL query to the database for execution, and passes the query results to the result return module through the internal API (Application Programming Interface). The result return module converts the results into a predefined report format and returns it to the user.

[0046] It is not difficult to understand that the present invention improves the query execution efficiency and realizes efficient query processing by converting database queries into graph models and optimizing queries using graph algorithms. It can not only process complex predicates and realize the processing and simplification of complex SQL statements, but also introduces graph models and graph algorithms to optimize the overall query path, providing a more comprehensive query optimization solution and realizing a method for intelligent server database query optimization based on graph models. Directly optimizing query paths through graph models and graph algorithms does not rely on predefined rules, has stronger adaptability and more significant optimization effects.

[0047] It is understandable that the present invention will perform corresponding graph query optimization according to the actual situation of the received structured query statement each time the query is queried. It does not rely on predefined rules or fixed cost models, but realizes query optimization by real-time analysis and optimization of query paths. Therefore, it can adapt to different types of databases and query scenarios, enhance the adaptability of the entire database system, and through pattern matching and dynamic optimization, the query method provided by the present invention can handle complex queries and large-scale data, and has stronger adaptability. At the same time, when optimizing the query path, the present invention can adopt graph algorithms such as graph traversal algorithms and heuristic algorithms, thereby significantly reducing the time cost of query optimization by reducing unnecessary traversal and calculation. By intelligently selecting the query path and execution plan with the lowest cost, the resource consumption of query execution is reduced, the overall performance of the system is improved, and the time cost of query optimization is reduced. The entire query method covers a comprehensive process from data preprocessing, query parsing, graph query optimization, query rewriting to query execution and result return, and provides a comprehensive query optimization solution. Through the organic combination and mutual optimization of each module, the system can be adjusted and optimized at different stages to ensure the efficiency and accuracy of query processing. Finally, by formatting the query results into user-friendly forms, such as JSON (JavaScript Object Notation) format or text summary, it is convenient for users to view and analyze the query results. The query processing process can also be further optimized based on user feedback information, continuously improving the execution efficiency and accuracy of the query, and providing a better user experience.

[0048] On the one hand, converting a database into a graph model includes: extracting data table information and foreign key constraint information in the database; determining each data table in the database based on the data table information; determining the foreign key relationship between each data table based on the foreign key constraint information; mapping the data tables into nodes and mapping the foreign key relationships into edges to convert the database into a graph model.

[0049] It is understandable that when storing data tables, the database will also use foreign key constraint information to establish links between the data in two tables. The main function of foreign key constraints is to enable data between tables to establish associations, making the data more complete and more relevant, and accurately characterizing the associations between various data tables. Therefore, by extracting the foreign key constraint information between the tables in the database, it is possible to accurately determine the foreign key relationships between the various data tables, that is, the foreign key relationships between the various nodes after mapping, and determine the associations between the nodes, thereby realizing the construction of the edges of the graph model. The data table itself, as a data record, is the data stored in the database, which also needs to be reflected in the graph model for subsequent queries. Therefore, the data table information and foreign key constraint information in the database can be extracted to map them to nodes and edges in the graph model respectively, mapping the table to a node and the foreign key relationship to an edge, thereby realizing the construction process of the graph model corresponding to the database. There are many ways to implement the extraction of data table information and foreign key constraint information, which can be implemented by extracting database metadata, and this application does not make any special restrictions here.

[0050] It is not difficult to understand that the data preprocessing module is mainly responsible for extracting data from the database and converting it into a graph model for processing. The specific steps and calculation process are as follows: The data preprocessing module first extracts data from the database, extracting information such as table structure, indexed data table information, and foreign key constraints. Specifically, you can use SQL query statements to extract table structure information, such as table name, field name, data type, etc. Extract index information, including primary key indexes and ordinary indexes. Extract foreign key constraint information, including tables and fields associated with foreign keys. The extracted data is then converted into a graph model, in which nodes represent data records and edges represent the relationships between data records to construct a graph model and obtain a node set. ,in Represents a table. Edge set ,in Representation table and table The foreign key relationship between them. Tables are mapped as nodes, for example, "user", "order", and "product" are nodes. Foreign key relationships are mapped as edges, for example, "user" and "order" are associated through foreign keys.

[0051] Specifically, the construction process of the graph model corresponding to the database can be realized by directly mapping the information in the database into nodes or edges in the graph model, so that the tables in the database, that is, data records, are effectively represented by nodes, and the relationships between tables are represented by edges, thereby completing the database conversion process.

[0052] On the one hand, after extracting the data table information and foreign key constraint information from the database, the method further includes: taking the data table information or foreign key constraint information extracted from the database as data to be cleaned; and performing data cleaning on the data to be cleaned.

[0053] It is understandable that in the process of converting the database to a graphical model, it is necessary to extract information such as data table information and foreign key constraint information in the database. At this time, in order to further ensure the accuracy and reliability of the graphical model obtained by the subsequent conversion, it is also necessary to perform data cleaning on the information extracted from the database. Both data table information and foreign key constraint information can be used as independent data to be cleaned, and the data cleaning process can be performed separately. Data cleaning can help clean and standardize data to ensure that the information used subsequently is accurate and consistent, thereby improving the accuracy and reliability of the final graphical model. This application does not make any special restrictions on the specific implementation methods of data cleaning, etc., which specifically include data processing operations such as removing noise and outliers, data format conversion, missing value processing, and data normalization.

[0054] Specifically, the graph model is constructed after the extracted data table information and foreign key constraint information are cleaned, so that the accuracy of the information used in constructing the graph model is greatly improved. By adding a data cleaning process after extracting the data table information and foreign key constraint information in the database, the accuracy and reliability of the converted graph model are effectively improved, further ensuring the accuracy and reliability of the final query results.

[0055] On the one hand, data cleaning is performed on the data to be cleaned, including: using standard deviation to detect outliers on the data to be cleaned; and removing the detected outliers from the data to be cleaned.

[0056] It is not difficult to understand that the process of data cleaning can include the processing of noise and outliers. Various statistical methods can be used to identify and remove noise and outliers in the data to be cleaned. For example, standard deviation can be used to detect outliers: ,in, is a piece of data to be cleaned. is the mean of the data to be cleaned, is the standard deviation of the data to be cleaned. For each data in the data to be cleaned, the above formula is used to determine whether it is an outlier. If so, it is directly removed, and if not, the data is retained. Other methods can also be used to detect noise and outliers, not limited to the method provided in this embodiment using the standard deviation.

[0057] Specifically, the standard deviation can be used to detect outliers in the cleaned data. It has low complexity, fast calculation speed, good interpretability, and can effectively detect possible data outliers through the mean and standard deviation. It is simple, effective, and easy to implement.

[0058] On the one hand, data cleaning is performed on the data to be cleaned, including: determining whether each data in the data to be cleaned is in the same data format; if not, converting all the data in the data to be cleaned into the same data format.

[0059] It is understandable that the process of data cleaning may include a process of data format conversion, which converts the data formats of different data sources into a unified format. Therefore, the data formats of all data in the data to be cleaned can be scanned to determine whether all the data therein are in the same data format, and / or determine whether all the data therein are in the target data format that is convenient for subsequent processing based on subsequent application requirements such as building a graph model. If all the data are in the same data format and / or all the data are in the target data format, there is no need to perform data format conversion; otherwise, it is necessary to perform data format conversion on the data that is different from most data formats or different from the target data format. The specific type of the target data format that is finally converted is not particularly limited in this application. It can be set in advance and then judged in turn whether each data in the data to be cleaned is in the target data format, or after scanning all the data, the majority of data formats can be used as the target data format.

[0060] Specifically, in order to facilitate subsequent processing and maintain the accuracy and integrity of data when it flows between different modules, it is best to unify the data format extracted from the database before proceeding to subsequent steps, thereby improving the accuracy and reliability of the entire query method.

[0061] On the one hand, after all the data in the data to be cleaned are converted into the same data format, it also includes: judging whether there are missing values ​​in the data to be cleaned after the conversion; if so, filling the missing values ​​by using mean filling or interpolation method.

[0062] It is not difficult to understand that in the case of hardware failure or missing data in the database, or after data format conversion and other data cleaning operations, there may be some missing data in the cleaned data. At this time, the missing values ​​need to be processed, and it is best to fill the missing values ​​to restore the real data. Specifically, mean filling or interpolation can be used to fill the missing values. Take mean filling as an example: ;in, is the filling data calculated for missing values, N is the number of non-missing values, The present application does not make any special restrictions on the specific method of determining whether there are missing values. The missing values ​​of data are generally reflected in the form of null values. Therefore, it is possible to directly determine whether there are missing values ​​by determining whether there are null values ​​in the data to be cleaned, that is, by traversing each data in the data to be cleaned, determining whether each data is a null value. If there is data with a null value in the data to be cleaned, it means that the data is a missing value, and then a corresponding filling operation is performed on it.

[0063] Specifically, when there are missing data in the data to be cleaned, data filling methods such as mean filling or interpolation can be further used to fill in the missing data, thereby avoiding the existence of null values ​​in the data to be cleaned and improving data quality.

[0064] On the one hand, data cleaning is performed on the data to be cleaned, including: scaling all data in the data to be cleaned to a preset range.

[0065] It is understandable that, considering that the graph model needs to be subjected to model feature extraction and calculation processes in the future, in the process of generating the graph model using the data to be cleaned, the data to be cleaned is preferably normalized data with a unified interval standard. And in the conversion and subsequent calculation process, the data to be cleaned will also be passed as an input parameter, and the input parameter must be standard data between 0 and 1 that conforms to the training, so it is necessary to normalize the data to be cleaned. Normalization refers to the process of scaling the data to the interval [0, 1] or [-1, 1]. Therefore, the preset interval can be [0, 1] or [-1, 1], and it can also be adjusted according to the actual application situation. The specific value of the preset interval is not particularly limited in this application. The specific minimum-maximum normalization process can be processed using the formula: To achieve, is the original data, is the minimum value of the data, is the maximum value of the data, The final data is obtained after normalization of the original data.

[0066] Specifically, the data to be cleaned is normalized to avoid adverse effects caused by singular sample data and simplify calculations. The original data for constructing the graph model is preprocessed through different multiple data cleaning processes to improve the accuracy of the converted graph model. The various data cleaning processes in the above embodiments can effectively help clean and standardize data and ensure the accuracy and consistency of the data used.

[0067] On the one hand, after mapping the data table to nodes and mapping the foreign key relationship to edges, the method further includes: merging similar nodes in the nodes into one node and / or removing redundant edges in the edges.

[0068] It is not difficult to understand that after mapping to obtain a preliminary graph model, the graph model can be further optimized. The optimization process of the graph model specifically includes merging similar nodes and simplifying redundant edges. Merging similar nodes means merging nodes with the same attributes and similar structures into one node. Specifically: ,in, and For two similar nodes, is the similarity threshold, is the node after the two are merged. The process of merging similar nodes specifically includes determining whether the similarity between any two nodes is greater than the similarity threshold. If so, the two nodes are merged. If not, the similarity between the other two nodes is determined. Simplifying redundant edges means removing redundant edges and retaining only key relationships. For example, when the relationship represented by two edges is the same, only one of the edges can be retained. Specifically: Among them, E is the edge before graph model optimization, Edges after graph model optimization.

[0069] It should be noted that the optimization process of the graph model is not limited to the merging of similar nodes and simplifying redundant edges in this embodiment, and can also be implemented in other ways. This application does not make any special restrictions here. The basis for judging similar nodes and redundant edges needs to be determined based on the data in actual applications and the relationship between data. This application does not make any special restrictions here. Optimizing the graph model by merging similar nodes and simplifying redundant edges can effectively reduce the complexity of the graph model, improve the efficiency of subsequent query processing, reduce unnecessary calculations, and ensure that the optimization of the query path is more efficient.

[0070] Furthermore, the judgment of similar nodes can be specifically made through the attribute dimension and structural dimension of the nodes. Judging from the attribute dimension means that if two or more nodes have high similarity in certain key attributes, they can be merged. For example, if the "age" or "date of birth" attributes in the user nodes are very similar, two or more user nodes can be merged. Judging from the structural dimension means that if the structural positions or connection patterns of two nodes in the graph are very similar, that is, they are connected to the same or similar sets of other nodes, these nodes can be regarded as candidates for merging. For example, in a graph model of a recommendation system, if two users evaluate the same batch of products, but the evaluation content is different, then the two user nodes are similar in structure. Therefore, by predetermining the key attributes and connection structure of each node, and then comparing the key attributes or connection structures between each node in the initially generated graph model, if the similarity of the key attributes or connection structures between two or more nodes is greater than a preset threshold, the two nodes or more nodes are merged.

[0071] Specifically, the graph model optimization process and the data cleaning process can be carried out simultaneously or one by one. Through data cleaning, normalization and graph model optimization, the quality of input data can be ensured, the query process can be simplified, and the accuracy and stability of the query processing process and the final query results can be improved.

[0072] On the one hand, the structured query statement is converted into a graph query, including: extracting the query information in the structured query statement, the query information includes tables, fields and conditions; mapping the query information to the graph model, and generating a graph query corresponding to the structured query statement.

[0073] It is understandable that when a structured query statement initiated by a user is received, the user's SQL query can be parsed to extract information such as tables, fields, conditions, etc. in the SQL query. The extracted information is then mapped to the graph model to generate the corresponding graph query. The graph query is essentially a graph model including nodes and edges, which can generate a corresponding graph representation based on the tables, fields, conditions, etc. extracted from the user's SQL query.

[0074] Specifically, after converting the database into a graph model, the structured query statements also need to be converted into graph queries to facilitate the subsequent use of graph queries to traverse the graph model to obtain the optimal query path, thereby using the graph model to optimize the structured query statements and the entire query process, effectively improving query efficiency.

[0075] On the one hand, before submitting the optimized structured query statement to the database for execution, the method also includes: performing a syntax check on the optimized structured query statement; if the optimized structured query statement conforms to the preset syntax rules, the method jumps to the step of submitting the optimized structured query statement to the database for execution.

[0076] It is not difficult to understand that the optimized structured query statement is directly converted from the optimized graph query. Therefore, it is also necessary to perform syntax check on the regenerated optimized SQL query. Specifically, the SQL parser can be used to perform syntax check on the generated SQL query. The SQL query syntax rules are as follows: , where Q represents the generated optimized SQL query statement. The specific content and implementation of the grammatical rules of the optimized structured query statement are not particularly limited in this application, and can be defined according to the specific type of structured query statements initiated by users in actual applications.

[0077] Specifically, by performing syntax checking on the optimized structured query statements and detecting and verifying errors in the optimized structured query statements, the correctness of the query statements ultimately submitted to the database for execution is ensured, and the failure of the query process due to the optimized structured query statements not complying with grammatical rules is avoided, thereby improving the accuracy and reliability of the entire query process.

[0078] On the one hand, before submitting the optimized structured query statement to the database for execution, the method further includes: submitting the optimized structured query statement to an execution plan generator of the database for execution plan verification.

[0079] It is understandable that the generated optimized SQL query can also be verified by the execution plan. The generated SQL query is submitted to the execution plan generator of the database, the execution plan corresponding to the optimized structured query statement generated by the database is obtained, and the execution plan is analyzed and optimized, so as to further optimize the generated SQL query according to the execution plan generator of the database. The execution plan cost function is: ,in, Represents the total cost of executing the plan, represents the weight of the i-th step, represents the execution cost of the i-th step, and n is the number of steps in the optimized structured query statement. The execution plan and its cost function corresponding to the optimized structured query statement are determined by the execution plan generator, and the optimized structured query statement is determined to be an execution plan that can minimize the execution plan cost function, thereby verifying that the optimized structured query statement can achieve the most efficient query process. An execution plan generator is generally set in the database, so the execution plan verification process can directly reuse the execution plan generator set in the database management system itself without additional settings.

[0080] Furthermore, if the syntax check of the optimized structured query statement has errors and / or the result of the execution plan verification shows that it is not the optimal query statement, the optimized SQL query can be further optimized and rewritten based on the results of the execution plan and syntax check. By analyzing the key steps in the execution plan, identifying the bottlenecks and optimization points of the query, rewriting the SQL query, and optimizing the query structure and execution order. The query rewrite optimization formula is: ,in, It indicates the further optimized SQL query, that is, the result of optimizing and rewriting the optimized structured query statement. Write an optimization function. This is an optimized structured query statement.

[0081] Specifically, the generated SQL query is submitted to the database for execution plan verification to ensure that the query statement can be executed efficiently. By combining with the execution plan generator, the SQL query can be further optimized. At the same time, it can also be combined with the syntax checking process of the query statement to ensure the correctness and efficient execution of the query statement, further improving the query accuracy.

[0082] On the one hand, determining the optimal query path of the graph query in the graph model includes: determining the subgraph pattern in the graph query; determining the graph algorithm corresponding to the subgraph pattern; performing subgraph matching on the graph model using the graph algorithm and the subgraph pattern in the graph query; and taking the path with the minimum query cost in the subgraph matching process as the optimal query path of the graph query in the graph model.

[0083] It is not difficult to understand that the graph query optimization module mainly optimizes graph queries by using graph algorithms to improve query execution efficiency. The graph query optimization module first performs pattern matching on graph queries to identify common query patterns. First, it is necessary to perform pattern matching on graph queries to find structural patterns that match graph queries. Structural patterns specifically include path patterns, star patterns, and ring patterns, etc. Then, according to the matched structural patterns, the corresponding graph algorithm is selected to optimize the query process. Pattern matching can identify common structural patterns in graph queries, and select corresponding graph traversal algorithms according to the matched structural patterns to optimize queries to improve query efficiency, so that the query optimization module can effectively apply the corresponding graph algorithms, thereby improving the efficiency and accuracy of query processing.

[0084] Furthermore, this embodiment implements the query process using graph query by subgraph matching. In the subgraph matching process, a corresponding graph algorithm is used to improve the efficiency of subgraph matching, so as to find a subgraph matching the graph query in the graph model, and find the optimal query path corresponding to the fastest matching process in the matching process. Extract the subgraph pattern in the graph query, and then perform subgraph matching on the graph model to find the matching subgraph pattern. That is, , where graph G is a given graph model and subgraph P is a reference subgraph extracted from a graph query. The subgraph matching process is to find a subset G′ of G so that G′ is isomorphic to P. The specific process and method of subgraph matching are not particularly limited in this application. By combining subgraph matching and graph algorithms to determine the optimal query path in the query process of the graph query, the path with the lowest query cost, that is, the shortest path, the most efficient query process can be achieved.

[0085] It should be noted that the specific ways to optimize the query process using graph algorithms include graph traversal algorithm optimization, shortest path algorithm optimization, and heuristic algorithm optimization. Using graph traversal algorithms to optimize graph query paths can reduce the number of graph traversals required for queries. Choosing appropriate graph traversal algorithms, such as depth-first search (DFS) and breadth-first search (BFS) to optimize graph query paths can ensure that the number of traversed nodes and edges is minimal. The specific search method is: ; ; Where DFS stands for depth-first search, BFS stands for breadth-first search, v is the current search point, u is the next search point corresponding to v in the search process, and u is the adjacent node of v. The shortest path algorithm is used to optimize the graph query path, and the query path with the lowest cost can be selected by calculating the shortest path between the nodes in the graph. Specifically, the Dijkstra algorithm can be used to calculate the shortest path: ;in, Representation Node The shortest distance to the source node, Represents edge The weight of u is the source node. The source node refers to the node where the query starts, and the shortest path to other nodes in the graph is calculated from this node. The heuristic algorithm is used to select the query path, which can give priority to the path with lower cost. The heuristic function is defined as , estimated from the node The cost to the target node is calculated by using the A* algorithm to select the path to minimize the total path cost. The calculation formula of the A* algorithm is: ;in, From the starting point to the node The actual cost, Represents a slave node The estimated cost to reach the target node.

[0086] As a specific embodiment, Figure 2 As shown in the figure, the database query system specifically includes a data preprocessing module, a query parsing module, a graph query optimization module, a query rewriting module, a query execution module and a result return module. First, the data preprocessing module plays a role. The data preprocessing module extracts metadata from the relational database. Assume that the database contains three tables: "user", "order" and "product". The data preprocessing module first extracts the database metadata and extracts the structural information of the "user", "order" and "product" tables, including field names, data types and index information. Foreign key relationships are also extracted. For example, there is a foreign key relationship between the user ID in the "user" table and the user ID in the "order" table. Then a graph model is constructed to convert the extracted data into a graph model. "User", "order" and "product" are used as nodes in the graph, and the foreign key relationship between the user ID and the order ID is used as the edge between the nodes. After that, the data cleaning process can be carried out to clean the extracted raw data. Remove noise and outliers, convert the data formats of different data sources into a unified format, use the mean to fill missing values, and normalize the data to the interval of 0 to 1. You can also optimize the graph model by merging similar nodes and simplifying redundant edges to optimize the graph model. Nodes with similar attributes and structures are merged and unnecessary redundant edges are deleted to reduce the complexity of the graph.

[0087] When the user submits the following SQL query:

[0088] SELECT user.name, order.date

[0089] FROM user

[0090] INNER JOIN orders ON user.id = orders.user_id

[0091] WHERE orders.amount > 1000;

[0092] The query parsing module parses the SQL query and extracts the tables (user, order), fields (user.name, order.date) and conditions (order.amount > 1000) in the query. Among them, FROM user means that the SQL query is to retrieve data from the "user" table in the database. This is the starting point of the query, that is, which table the data will be selected from. In this example, the fields include: user.name and order.date. INNER JOIN order ON user.id = order.user_id means to join the "user" table and the "order" table based on the condition user.id = order.user_id. This means that the system will find the records in the "user" table and the "order" table whose user ID matches the user ID in the order, and combine these records to form the query result. This type of connection ensures that only matching records will be included in the final query result.

[0093] After the query parsing module completes the parsing, it converts the SQL query into a graph query, maps the parsed SQL query into the graph model, and generates the corresponding graph query. At this point, the relationship between the "user" node and the "order" node is represented by an edge. INNERJOIN order ON user.id = order.user_id This part of the code represents the relationship between the "user" node and the "order" node. In the graph model, this SQL join operation is mapped to an edge between two nodes. Specifically: "user" node: represents the data in the "user" table. "order" node: represents the data in the "order" table. Edge: connects these two nodes, indicating the association between the id field of the "user" table and the user_id field of the "order" table.

[0094] After the graph query is generated, the graph query optimization module performs pattern matching to identify the subgraph pattern in the graph query. This query is a typical path pattern: from the "user" node to the "order" node, and the condition is that the order amount is greater than 1000. Then the graph traversal optimization is performed, for example, the query path can be optimized using breadth-first search (BFS). The breadth-first search starts from the "user" node and visits the adjacent "order" nodes in turn to find orders that meet the conditions. The shortest path algorithm can also be used, using the Dijkstra algorithm to calculate the shortest path from the "user" node to the "order" node, and select the path with the lowest cost for query. A heuristic algorithm can also be used: the A* algorithm is used to select the query path, and the path with the lowest total path cost is selected by combining the actual cost and the estimated cost.

[0095] After the graph query optimization is completed, the query rewrite module converts the optimized graph query back into a SQL query:

[0096] SELECT u.name, o.date

[0097] FROM useru

[0098] INNER JOIN orderso ON u.id = o.user_id

[0099] WHERE o.amount > 1000

[0100] ORDER BY o.date DESC;

[0101] The optimized SQL query includes a sort operation ORDER BY o.date DESC to ensure that the results are sorted in descending order by order date. This optimization can help improve the efficiency of queries in some cases. Among them, u represents the "user" table (users) and o represents the "order" table (orders). Then the query rewrite module can further generate an execution plan, submit the generated SQL query to the database execution plan generator, obtain the optimized execution plan, and analyze and optimize the execution plan. You can also further perform syntax checking: use the SQL parser to perform syntax checking on the generated SQL query to ensure that the query statement is correct, and submit it to the database for execution plan verification to ensure that the query can be executed efficiently. Finally, based on the results of the execution plan and syntax checking, the SQL query is further optimized and rewritten to optimize the query structure and execution order.

[0102] Finally, the query execution module submits the query execution, submits the optimized SQL query to the database for execution, and can monitor the performance indicators of the query execution process in real time, including execution time, memory usage, and CPU occupancy. It can also collect feedback information on query execution, including query execution time and resource consumption. The graph model and query strategy can be further optimized based on the collected execution feedback. In order to facilitate users to obtain query results, the result return module can format the query results into a user-friendly form, such as JSON format or text summary. The query results are then returned to the user, and the performance indicators of the query execution are displayed. Finally, the query processing process can be further optimized based on user feedback information to continuously improve the execution efficiency and accuracy of the query.

[0103] As a specific embodiment, this embodiment uses simulation data to demonstrate the effects before and after optimization. The simulation data includes detailed input data, intermediate operations and operation results of each step, and specifically analyzes the beneficial effects brought by the invention.

[0104] Enter the data of the following three tables as the database:

[0105] Table 1 Input information table

[0106]

[0107] Order table:

[0108] Table 2 Input order table

[0109]

[0110] Product Table:

[0111] Table 3 Input product table

[0112]

[0113] The orders and products corresponding to the user Zhang San in the input data are queried, and the query process is performed using the query method before optimization, that is, the database query method provided by the present application is not used for querying, and the query process is performed using the query method after optimization, that is, the database query method provided by the present application is used for querying.

[0114] The parameters of the query process before optimization are: query time: 350ms, memory usage: 50MB, CPU usage: 25%; the query return results are:

[0115] Table 4 Query results table

[0116]

[0117] The parameters of the optimized query process are: query time: 120ms, memory usage: 30MB, CPU usage: 15%; the query return results are:

[0118] Table 5 Query result table

[0119]

[0120] Through the above detailed steps and simulation data, this embodiment demonstrates how to effectively improve the query execution efficiency and provide efficient and accurate query results through the intelligent server database query optimization method based on the graph model. The comparison before and after optimization shows that the query time is reduced by 65.7%, the memory usage is reduced by 40%, and the CPU occupancy is reduced by 40%, which significantly improves the system performance. The query results returned before and after optimization are consistent, which not only shortens the query time, but also effectively reduces the memory usage of the query process. Therefore, the present invention converts the database query into a graph model and optimizes it using the shortest path algorithm, graph traversal algorithm and heuristic algorithm, which greatly reduces the number of traversals of the query path. It can not only achieve accurate and reliable database query operations, but also significantly improve the query execution efficiency by selecting the query path with the lowest cost.

[0121] Specifically, the present invention uses graph algorithms and heuristic algorithms to optimize query paths in real time, which does not rely on the prediction of future queries and has a more direct optimization effect. Through simulation data verification, the database query method provided by the present invention can significantly and effectively improve the query execution efficiency.

[0122] To solve the above technical problems, an embodiment of the present invention also provides a database query device, including: a database conversion unit, used to convert a database into a graph model; a query statement conversion unit, used to convert the structured query statement into a graph query when receiving a structured query statement for querying the database; an optimization unit, used to determine the optimal query path of the graph query in the graph model, and add query constraints to the graph query based on the optimal query path; a query statement recovery unit, used to generate an optimized structured query statement based on the graph query after adding query constraints; and an execution unit, used to submit the optimized structured query statement to the database for execution.

[0123] For the description of the features in the database query device provided in the embodiment of the present invention, reference can be made to the relevant description of the embodiment of the database query method, which will not be described in detail here.

[0124] See also Figure 3 As shown, Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present invention, the electronic device comprises: a memory 60 for storing a computer program; a processor 61 for implementing the steps of the database query method in the above embodiment when executing the computer program.

[0125] The electronic device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer.

[0126] Among them, the processor 61 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 61 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 61 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. On the one hand, the processor 61 can be integrated with a graphics processing unit (GPU), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 61 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.

[0127] The memory 60 may include one or more computer-readable storage media, which may be non-transitory. The memory 60 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 60 is at least used to store the following computer program 601, wherein, after the computer program is loaded and executed by the processor 61, the relevant steps of the database query method disclosed in any of the aforementioned embodiments can be implemented. In addition, the resources stored in the memory 60 may also include an operating system 602 and data 603, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 602 may include Windows, Unix, Linux, etc. Data 603 may include, but is not limited to, data in the database query method, etc.

[0128] On the one hand, the electronic device may also include a display screen 62 , an input / output interface 63 , a communication interface 64 , a power supply 65 and a communication bus 66 .

[0129] Those skilled in the art will understand that Figure 3 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure.

[0130] For the description of the features in the electronic device provided by the embodiment of the present invention, reference may be made to the relevant description of the embodiment of the database query method, which will not be described in detail here.

[0131] It is understandable that if the database query method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the current technology or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk or optical disk and other media that can store program codes.

[0132] Based on this, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned database query method are implemented.

[0133] For the description of the features in the computer-readable storage medium provided in the embodiment of the present invention, reference can be made to the relevant description of the embodiment of the database query method, which will not be described in detail here.

[0134] An embodiment of the present invention further provides a computer program product, including a computer program / instruction, which implements the steps of the database query method described in the above embodiment when executed by a processor.

[0135] For descriptions of features in the computer program product provided by the embodiments of the present invention, reference may be made to the relevant descriptions of the embodiments of the database query method, which will not be described in detail here.

[0136] The above is a detailed introduction to a database query method provided by an embodiment of the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0137] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0138] The above is a detailed introduction to a database query method, device, medium and computer program product provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, the present invention can also be improved and modified, and these improvements and modifications also fall within the scope of protection of the present invention.

Claims

1. A database query method, characterized in that: include: Converting the database into a graph model and optimizing the graph model; wherein the optimization process of the graph model includes merging similar nodes and simplifying redundant edges; When receiving a structured query statement for querying the database, converting the structured query statement into a graph query; Determine the optimal query path of the graph query in the graph model by using subgraph matching combined with a graph algorithm, and add query constraints to the graph query based on the optimal query path; Generate optimized structured query statements based on the graph query after adding query constraints; Submitting the optimized structured query statement to the database for execution; Also includes: Similar nodes in the graph model are determined based on the attribute dimensions and structure dimensions of the nodes in the graph model.

2. The database query method according to claim 1, characterized in that: The step of converting the database into a graph model includes: Extract data table information and foreign key constraint information from the database; Determine each data table in the database based on the data table information; Determine the foreign key relationship between each of the data tables based on the foreign key constraint information; The data tables are mapped as nodes, and the foreign key relationships are mapped as edges, so as to convert the database into a graph model.

3. The database query method according to claim 2, characterized in that: After extracting the data table information and foreign key constraint information from the database, the method further includes: Using the data table information or the foreign key constraint information extracted from the database as data to be cleaned; Perform data cleaning on the data to be cleaned.

4. The database query method according to claim 3, characterized in that: The step of performing data cleaning on the data to be cleaned includes: Using standard deviation to perform outlier detection on the data to be cleaned; The detected outliers are removed from the data to be cleaned.

5. The database query method according to claim 3, characterized in that: The step of performing data cleaning on the data to be cleaned includes: Determine whether each data in the data to be cleaned is in the same data format; If not, all the data in the data to be cleaned are converted into the same data format.

6. The database query method according to claim 5, characterized in that: After converting all the data to be cleaned into the same data format, the method further includes: Determine whether there are missing values ​​in the data to be cleaned after conversion; If so, the missing values ​​are filled using mean filling or interpolation.

7. The database query method according to claim 3, characterized in that: The step of performing data cleaning on the data to be cleaned includes: All data in the data to be cleaned are scaled to a preset range.

8. The database query method according to claim 1, characterized in that: The converting the structured query statement into a graph query includes: Extracting query information from the structured query statement, the query information including tables, fields and conditions; The query information is mapped into the graph model to generate a graph query corresponding to the structured query statement.

9. The database query method according to claim 1, characterized in that: Before submitting the optimized structured query statement to the database for execution, the method further includes: Performing a syntax check on the optimized structured query statement; If the optimized structured query statement conforms to the preset grammatical rules, the process jumps to the step of submitting the optimized structured query statement to the database for execution.

10. The database query method according to claim 1, characterized in that: Before submitting the optimized structured query statement to the database for execution, the method further includes: The optimized structured query statement is submitted to the execution plan generator of the database for execution plan verification.

11. The database query method according to any one of claims 1 to 10, characterized in that: Determining the optimal query path of the graph query in the graph model by using a subgraph matching method includes: determining a subgraph pattern in the graph query; Determining a graph algorithm corresponding to the subgraph pattern; Performing subgraph matching on the graph model using the graph algorithm and the subgraph pattern in the graph query; The path with the smallest query cost in the subgraph matching process is used as the optimal query path of the graph query in the graph model.

12. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the database query method according to any one of claims 1 to 11.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the database query method according to any one of claims 1 to 11 are implemented.

14. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the database query method according to any one of claims 1 to 11 are implemented.

Citation Information

Patent Citations

  • SQL statement generation method and system oriented to medical data and medium

    CN117609277A