Learning-based sub-graph query optimization method and system

By employing a learning-based subgraph query optimization method, which utilizes graph neural networks and deep models to generate efficient matching sequences, this approach addresses the issues of high runtime overhead, insufficient versatility, and limited model expressive power in existing technologies. It achieves low latency and efficient execution plan optimization on large-scale graph data.

CN121579527APending Publication Date: 2026-02-27PEKING UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202511770385.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-28
Publication Date
2026-02-27

AI Technical Summary

Technical Problem

Existing subgraph query optimization techniques suffer from high runtime overhead, complex structure and insufficient versatility, insufficient consideration of relationships between subqueries and limited model expressive power, making it difficult to achieve low-latency and efficient execution plan optimization on large-scale graph data.

Method used

We employ a learning-based subgraph query optimization method. By using a query graph encoder, cardinality and cost estimators, and a top-down plan enumerator, we utilize graph neural networks and deep models to predict the cardinality and execution cost of subqueries, generate efficient matching orders, reduce computational costs, and improve the accuracy of cardinality estimation and the robustness of the model.

Benefits of technology

It achieves low-latency execution plan optimization on large-scale graph data, improves overall query efficiency, has good versatility and applicability, can be ported to different graph database systems, and improves the accuracy of cardinality estimation and the stability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121579527A_ABST
    Figure CN121579527A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of graph database and graph query optimization, and relates to a learning-based sub-graph query optimization method and system. The method comprises the steps of receiving a query graph, and filtering a data graph according to the query graph; encoding the query graph by using a query graph encoder, and calculating vector representations of each sub-query graph and the complete query graph; estimating the sub-query cardinal number and the cost of the connection operation according to the vector representation of the sub-query graph and the complete query graph by using a cardinal number and cost estimator; generating a matching sequence by using a top-down plan enumerator according to the estimated sub-query cardinal number and the cost of the connection operation; and performing recursive enumeration according to the matching sequence to obtain a subgraph query result. According to the method, data graph distribution and query structure features can be accurately captured on the premise of keeping low online prediction overhead, and refined cardinality estimation and execution cost estimation are provided on a sub-query level, so that the quality of an execution plan and the overall query efficiency are improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of graph database and graph query optimization, and particularly relates to the optimization of execution plan and cardinality estimation for subgraph query on large-scale graph data. BACKGROUND

[0002] Subgraph query is a basic capability in graph database, which aims to find all matching results in the data graph that satisfy the vertex label constraints and edge topology constraints defined by the query graph. There are many query semantics for the implementation of subgraph query, which refine the conditions under which the matching requirements are met, such as subgraph isomorphism and subgraph homomorphism. The execution process of subgraph query is usually divided into three stages of filtering, planning and enumeration in actual systems, where the filtering stage constructs a candidate set for each query vertex, the planning stage generates a matching order for the query graph nodes, and the enumeration stage outputs the result set according to the matching order. The selection of the matching order has a significant impact on the overall efficiency, and there is often a performance difference of several orders of magnitude, so generating a good matching order is crucial for the efficient execution of subgraph query.

[0003] Existing works mainly generate matching order by the following two methods: one is the greedy heuristic method, including the structure-based heuristic method and the rule-based heuristic method, which preferentially match vertices with large degree or small candidate set, thereby reducing the initial search space. However, this method ignores the distribution difference of data graph and more fine-grained cost factors, and in some cases the generated matching order has poor execution efficiency. The other is the dynamic programming method, which exhaustively searches the plan space to find the optimal order. However, when facing large query graphs, the plan space expands rapidly, and the dynamic programming method is computationally expensive and even inapplicable in practical scale. In practical system applications, modern graph databases such as Neo4j, GraphFlow and Kùzu often use dynamic programming to obtain a better execution plan, and in complex queries, they are supplemented with greedy search.

[0004] With the development of machine learning, various learning-based optimizers have emerged in the field of relational databases, typical paradigms include learning-based cardinality estimation combined with traditional cost model and dynamic programming, learning-based cost estimation combined with traditional enumeration, and directly using learning model to generate execution plan. However, this kind of method is generally built on fixed table mode and relatively stable join structure, and it is difficult to directly migrate to the scenario of heterogeneous and flexible pattern graph data and subgraph query with a large number of joins.

[0005] There are very limited works on learning-based optimization for graph data. Only one work models the match order selection as a Markov Decision Process, but it fails to fully exploit the global structure information of subqueries and thus gives suboptimal orders on some queries. Besides, another line of thought is to use learning-based methods to estimate the cardinality of subquery graphs and combine with hand-crafted cost models, but it has not been practically applied due to some drawbacks in real systems. Therefore, how to use deep learning to help generate good execution plans for subgraph queries is a problem worth studying.

[0006] The existing subgraph query optimization techniques still have the following deficiencies: 1) Large running overhead. Dynamic programming and other optimization methods need to exhaust the huge plan space, and the computational overhead increases exponentially with the query size. In large-scale graph data and complex queries, the planning time is too long to meet the low-latency requirements of online systems for subgraph queries.

[0007] 2) Complex structure and lack of universality. Some systems rely on hand-designed operator cost models or specific execution frameworks, resulting in high coupling degree of methods, making it difficult to migrate to different types of graph databases and operator implementations, lacking universality and flexibility 3) The relationship between subqueries is not fully considered. Existing learning-based subgraph query cardinality estimation methods only estimate for complete queries and fail to make joint predictions at the subquery level, resulting in insufficient consideration of the relationship between subqueries, making it difficult to provide sufficient fine-grained guidance information for dynamic programming or greedy search, thereby affecting the generated match order.

[0008] 4) The model used has limited expressive ability. Existing learning-based subgraph methods are generally based on message passing graph neural networks, but the expressive ability of message passing graph neural networks is limited and cannot distinguish between different query graphs. This leads to large estimation errors and unstable plans when facing these different query graphs, thereby affecting the overall optimization effect. SUMMARY

[0009] In view of the deficiencies of the prior art, the purpose of the present application is to provide an efficient, universal and extensible subgraph query optimization method, which can accurately capture the data graph distribution and query structure characteristics while maintaining low online prediction overhead, and provide fine-grained cardinality estimation and execution cost estimation at the subquery level, thereby improving the quality of the execution plan and the overall efficiency of the query.

[0010] The technical problems to be solved by this invention include: 1) how to achieve low-latency execution plan optimization on large-scale graph data; 2) how to provide optimization methods that are highly portable and have low dependence on specific operators and database systems; 3) how to simultaneously take into account the global structure of the query and the local features of the subquery to improve the accuracy of cardinality estimation and cost estimation; and 4) how to improve the model's expressive power and robustness to complex query structures, thereby improving optimization performance.

[0011] The technical solution adopted in this invention is as follows: A learning-based subgraph query optimization method includes the following steps: Receive the query graph and filter the data graph based on the query graph; The query graph is encoded using a query graph encoder, and vector representations of each subquery graph and the complete query graph are computed. Using cardinality and cost estimators, the cardinality of subqueries and the cost of join operations are estimated based on the vector representations of the subquery graph and the full query graph; Based on the estimated cardinality of subqueries and the cost of join operations, a matching order is generated using a top-down plan enumerator; The subgraph query results are obtained by recursively enumerating based on the matching order.

[0012] Furthermore, the encoding of the query graph using the query graph encoder includes: In the data chart The data graph is constructed by extending the label. In the data graph of tag expansion Run the embedding algorithm to obtain each tag node. Embedded representation , as a tag The encoding; After obtaining each query graph node from the filtering operation Corresponding candidate set And calculate each query edge candidate set Finally, query each node in the graph. and edge The initial characteristics are: Based on the initial features, the query graph encoder runs a graph neural network on the query graph for several rounds to obtain each final query graph node. The representation of ; Based on query graph nodes The representation of This yields a representation of any subquery graph.

[0013] Furthermore, the graph neural network includes message passing between neighboring edges, through an update function. Update node The expression, The previous round The representation of Summing the information from neighbors and between neighbors, and then activating it with the ReLU nonlinear function to obtain the first... Wheel representation .

[0014] Furthermore, the aforementioned Calculate using the following formula: in, k Indicates the number of iterations. express Neighbors express The edges connecting the neighbors, This represents the learnable coefficient matrix when updating the edge representation. and For the aggregation function, a self-attention aggregation method is used to improve the expressive power of the model.

[0015] Furthermore, the cardinality and cost estimator are based on the representation of each subquery graph. The cardinality and execution cost are predicted using deep learning models: in, Subquery The base estimate, Indicates from The results of the subquery are enumerated. The estimated execution cost of the result, Indicates that the execution was successful. The execution cost of the plan with the lowest execution cost among all plans is determined; the prediction model consists of three multilayer perceptrons. , and , respectively corresponding , , Three estimates.

[0016] Furthermore, the top-down plan enumerator generates the matching order through the following steps: The matching order of the subgraph query is modeled as a path on a subquery graph lattice, each node in the subquery graph lattice represents a connected subquery graph of the complete query graph, and each edge in the subquery graph lattice connects two nodes and more than one node of the subquery ; The matching order is generated in a top-down reverse order: if a subquery graph is enumerated , then the in-neighbors of the node represented in all subquery graph lattice graphs are checked, and the in-neighbor with the minimum value is selected . The node more than is the node in the matching order.

[0017] Further, in the training process, four sub-models are trained in a supervised learning manner: a query graph encoder, a cardinality estimation model, a cost estimation model, and a cost estimation model.

[0018] A learning-based subgraph query optimization system comprises: A filtering unit configured to receive a query graph and filter a data graph according to the query graph; A planning unit comprising a query graph encoder, a cardinality and cost estimator, and a top-down planning enumerator, wherein the query graph encoder is configured to encode the query graph and calculate a vector representation of each subquery graph and the complete query graph, the cardinality and cost estimator is configured to estimate a subquery cardinality and a cost of a join operation according to the vector representation of the subquery graph and the complete query graph, and the top-down planning enumerator is configured to generate a matching order according to the estimated subquery cardinality and the cost of the join operation; An enumeration unit configured to recursively enumerate according to the matching order to obtain a subgraph query result.

[0019] Compared with the prior art, the present application has the following advantages: 1) Small running overhead. The traditional dynamic programming method requires a large amount of calculation when the query size is large, while the present application greatly reduces the calculation cost by performing top-down planning enumeration guided by cost estimation. Even for large query graphs, high efficiency can be maintained.

[0020] 2) Better versatility. Unlike existing solutions that rely on specific operator models, the present application is decoupled from the underlying execution engine and can be easily ported to different graph database systems, with strong scalability and applicability.

[0021] ​​3) The cardinality estimation is more accurate, and the execution plan is better. Unlike existing methods that only use complete query information, the present application provides estimation information at the subquery level, making the cardinality estimation more accurate and the plan generation closer to optimal.

[0022] 4) The model is more robust. With the improved subquery encoder, the present application has stronger discrimination ability for complex structure patterns, ensuring stable performance on different sizes and types of graph data. BRIEF DESCRIPTION OF DRAWINGS

[0023] Figure 1 is a workflow diagram of the learning-based subgraph query optimization method of the present application.

[0024] Figure 2 is an example graph of a graph neural network enhanced with triangle information.

[0025] Figure 3 is a schematic diagram of modeling the execution plan of a subgraph query as a path on a subquery graph lattice.

[0026] Figure 4 is a comparison of the average running time of the present application and existing methods on the test set. DETAILED DESCRIPTION

[0027] In order to make the above-mentioned purposes, features and advantages of the present application more apparent and easy to understand, the present application will be further described in detail below with specific examples and drawings.

[0028] First, the problem definition is explained, and the symbols needed are introduced.

[0029] Given a data graph and a query graph , the goal of a subgraph query is to find all matching subgraphs of the query graph in the data graph. Specifically, using an undirected graph model, the data graph is where and represent the point set and edge set, respectively, is a label function that assigns a label set to each point in the graph: Without causing ambiguity, the graph is sometimes simply denoted as Similarly, the query graph can be defined as A one-to-one mapping from to is called a match in if and only if it satisfies the following two conditions: 1) Pointwise restrictions: .

[0030] 2) Edge-wise restrictions: , and similarly .

[0031] Here we use the homomorphic semantics for matching, because subgraph homomorphism is widely applied, for example, in some RDF graph database systems SPARQL queries are subgraph homomorphism matching. There are other matching semantics, for example, subgraph isomorphism, which additionally requires that the mapping is injective, i.e. it is required that nodes in the query graph are matched to different data graph nodes. However, the method in the present invention is also applicable to these matching semantics of subgraph isomorphism.

[0032] The execution flow of a subgraph query is mainly composed of three phases: "filter-plan-enumerate": 1. The filter phase quickly excludes nodes and edges in the data graph that are irrelevant to the query graph according to some rules, and generates a candidate set for each query node , a data node not in the candidate set cannot form a match.

[0033] 2. The plan phase generates an execution plan. For a subgraph query, the main difference between different execution plans is the matching order (also called join order) of the query graph nodes. In the present invention, matching order and execution plan are used interchangeably because they are essentially the same. For a query graph (i.e. is all nodes), a matching order of is a permutation of . For convenience in the following introduction, we also define the node set consisting of the first nodes in the matching order as , and the sub-query graph of induced by as . Usually, the matching order is required to guarantee the connectivity of the sub-query graph, i.e. are all connected, . We also define the backward neighbor of a query graph node as , i.e. the neighbor before in the matching order; similarly, the forward neighbor is defined.

[0034] 3. The enumerate phase recursively enumerates according to the matching order. The recursion depth is​ When, i.e. need to match When, The backward neighbors of i, i.e. have already matched results, so The matching candidate points of i can be obtained by intersecting the adjacency lists of the matching results of .

[0035] For the planning phase in subgraph query, the present application proposes a learning-based subgraph query optimization method. The workflow thereof is shown in Figure 1 , which mainly consists of (1) query graph encoder, (2) cardinality and cost estimator, (3) top-down plan enumerator. After receiving the query graph and filtering the data graph according to the query graph, the query graph encoder encodes the query graph according to the filtered statistical information, so as to calculate the vector representation of each subquery graph and the complete query graph. The cardinality estimation and cost estimator estimate the subquery cardinality and the cost of the connection operation according to the vector representation of the subquery graph and the complete query graph. The top-down plan enumerator greedily generates the matching order according to the estimation of the cost of the connection operation.

[0036] The above three parts and the training method of the model are introduced respectively as follows.

[0037] (1) Query graph encoder The label of the query graph node is important information. In order to encode the label of each query graph node, first, a label-extended data graph is constructed on the data graph . The specific method is to add a label node (all label nodes constitute ) for each label in the label set in the data graph , and connect the node in the original data graph with its label node (the edges thus newly added constitute ). On the label-extended data graph , run the embedding algorithm, such as ProNE, so as to take the embedding representation of each label node as the encoding of the label .

[0038] In order to add encoding information related to the query graph, the filtered statistical information can also be used to enrich the query graph encoding. After the filtering operation, each query graph node corresponds to its candidate set . Further, the candidate set of each query edge can also be calculated, which is defined as Thus the initial features of each node and edge of the final query graph are: , . Based on the initial features, the query graph encoder runs several rounds of graph neural networks on the query graph to obtain the representation of each node of the final query graph. In order to solve the problem of insufficient expression ability of existing graph neural networks, a graph neural network enhanced by triangle information is proposed in the present application, as shown in the example of Figure 2 .

[0039] As shown in Figure 2 , the existing message passing based graph neural network only receives the information of its neighbors and the edges connected to the neighbors when calculating the representation of each node at each iteration (in Figure 2 , the solid arrow pointing to represents the message flow direction of the message passing based graph neural network), and the present application additionally adds message passing between the edges of the neighbors (in Figure 2 , the dashed arrow pointing to , and its two connected neighbors form a triangle). The formal expression is as follows: wherein k represents the number of iterations, represents the neighbor of , represents the edge between the neighbors of . represents the learnable coefficient matrix when updating the edge representation. and are aggregation functions, which can be implemented by using self-attention type aggregation method to improve the expression ability of the model, and the specific expression is as shown below.

[0040] wherein and are learnable coefficient matrices, and are attention coefficients, and the calculation method is as follows: in and is a learnable coefficient vector. and is a learnable coefficient matrix, corresponding to nodes and edges respectively. It is the LeakyReLU nonlinear activation function.

[0041] Finally, the update function is used. Update node The indication here The previous round The representation of Information from neighbors and between neighbors ( The results of the aggregation function are summed, and then activated by the ReLU nonlinear function to obtain the first... Wheel representation .

[0042] Finally, based on the query graph Each node The representation of This allows us to obtain any subquery graph. The representation of: , Where the coefficient , and These are also two learnable coefficient matrices. This represents the dot product of vectors.

[0043] (2) Cardinality and Cost Estimator Based on the representation of each subquery graph This invention proposes a method for predicting cardinality and execution cost using deep learning models: , , . in, Subquery cardinality (subquery) Estimate the size of intermediate results. Indicates from The results of the subquery are enumerated. (here That is, only compared to The estimated execution cost of the result of a larger subquery with one more node. Indicates that the execution was successful. The result is the execution cost of the plan with the lowest execution cost among all plans. The prediction model consists of three multilayer perceptrons: , and , respectively, correspond to , , three estimated values.

[0044] (3) Top-down plan enumerator According to the cardinality and cost estimation, the present application proposes a top-down plan enumeration method. In the present application, the execution plan (match order) of a subquery graph is modeled as a path on a subquery graph lattice. As shown in FIG. 3, each node in the right subquery graph lattice represents a connected subquery graph of the complete query graph shown in the left, containing the nodes shown in the side. Each edge in the subquery lattice connects a subquery Figure 3 with exactly one more node than . The path represented by the bold dashed arrow ( ) in the lattice indicates that the match order is .

[0045] Under this path modeling, the present application generates match orders from top to bottom in reverse order: if the subquery graph is enumerated, check all the in-neighbors of the node represented by in the subquery graph lattice, and select the in-neighbor with the smallest value . The node that is more than is the node in the match order. Here is actually estimating the best plan execution cost of reaching the subquery graph through .

[0046] Still using the example in Figure 3 , the plan enumeration algorithm in the present application first checks the four in-neighbors of the subquery represented by (the subquery is actually the complete query graph): and If the value of when is brought in is the smallest, it means that the node is the last node in the match order. Then enumerate the three in-neighbors of : and If the value of when is brought in is the smallest, it means that the second last node in the match order is .

[0047] (4) Training method In the present application, there are four sub-models that need to be trained: a query graph encoder and three depth estimation models (one cardinality estimation model and two cost estimation models). The present application uses supervised learning to train these models.

[0048] First, some training query graphs need to be collected, which can be obtained from query logs or generated according to templates. Then, according to the subquery graph of each query graph, the matching operation represented by each edge in the subquery graph is actually executed, so as to obtain the execution cost and cardinality (result size during execution). Finally, by using these supervised information, the four sub-models can be trained end-to-end.

[0049] The key points of the present application are: 1) Efficient query graph encoding method: combine offline features of data graphs and online information related to query graphs, use graph neural networks to encode query graphs, and enhance the encoding ability of query graphs by using the graph neural network with stronger expression ability proposed in the present application.

[0050] 2) Cardinality estimation and cost estimation at the subquery level: the present application not only estimates the cardinality of the complete query graph, but also quickly predicts the cardinality of any subquery and the execution cost of the join operation, providing fine-grained information for execution plan generation. By having the model learn both cardinality and execution cost, the accuracy and robustness of the model are improved.

[0051] 3) Plan generation framework using cost estimation: using cost estimation, the execution plan is enumerated from top to bottom. It is more efficient than the traditional dynamic programming method, and the execution plan obtained is better than that obtained by the traditional rule-based greedy method.

[0052] 4) Decoupling of graph database system: the technical solution does not depend on the implementation of specific operators, has strong portability, and is suitable for various graph databases and execution engines.

[0053] Other embodiments of the present application: 1) The above introduction limits the scenario of undirected graph and point label, but in the scenario of undirected graph or point and edge with label, the technology in the present application is also applicable.

[0054] 2) Other regression prediction models (such as support vector regression, random forest, etc.) can also be used instead of the multilayer perceptron method used in the cardinality estimation and cost estimation in the present application.

[0055] 3) The query graph initial feature encoding method in the present application can also use other feature encoding methods instead.

[0056] Six public datasets (HPRD, Yeast, DBLP, EU2005, YouTube, Patents) are selected to demonstrate the effectiveness of the present application. For each dataset, 1800 query graphs are generated by random walks, with the number of nodes ranging from 4 to 32. 80% of them are used for training and the remaining 20% are used for testing. The filtering and enumeration methods in the execution process are fixed unchanged, and only the optimization method is changed to generate different execution plans. Compared with some classic subgraph query optimization methods: QSI, GQL, RI, RM, DPiso and a method of using reinforcement learning to get execution plan RLQVO, the average running time on the test set is compared as Figure 4 It is shown that the method in the present application is recorded as NeuSO. It can be found that the execution plan generated by NeuSO is 1.63 to 47.93 times more efficient than other comparison methods, which shows the effectiveness of the present method in subgraph query optimization.

[0057] The technical achievements of the present application can be applied to any application scenario that needs to analyze and mine complex structures in graph data, including graph databases, social networks, e-commerce, intelligent recommendation, biochemistry, financial risk control, knowledge graph, network security and other fields. It can support intelligent analysis, prediction and decision-making under big data, and has broad industrial application prospects.

[0058] For example, in a social network scenario, the attention and interaction relationship between users can be modeled as a data graph, where the nodes in the graph represent different users and the edges represent the attention, comment or forwarding behavior between users. The platform needs to continuously identify abnormal propagation structures that may affect content security or community stability, such as suspicious diffusion patterns driven by multiple low-quality accounts in a short period of time. After representing these abnormal propagation structures as query graphs, the present application can generate more optimal execution plans for query tasks, thereby completing matching in large-scale social network data more quickly. This can significantly shorten the analysis time of suspicious propagation paths and improve the monitoring efficiency of abnormal behavior by the platform.

[0059] For example, in an e-commerce scenario, information such as goods, user browsing behavior, transaction records, etc. can be organized into a data graph, where the nodes in the graph can be users or goods, and the edges can represent browsing, collecting, joint purchasing, etc. In the process of recommendation or risk control, e-commerce platforms often need to identify specific behavior patterns, such as users accessing multiple goods in an abnormal path in a short period of time or suspicious transaction chains formed between multiple accounts in a specific order. After representing these patterns as query graphs, the present application can generate efficient matching plans, reduce resource consumption when executing queries on large-scale behavior graphs, and speed up the positioning speed of suspicious patterns, thereby improving the recommendation effect or improving the risk identification ability.

[0060] For example, for a graph database scenario, the method of the present application can be directly used to generate a good execution plan for an input subgraph query, thereby speeding up the execution of the query.

[0061] For another example, for a financial risk control scenario, the transfer behavior between accounts can be modeled as a data graph, with nodes representing different accounts and edges representing the transfers between accounts. In the risk control scenario, it is necessary to continuously detect some transfer patterns with suspicious characteristics. These transfer patterns can be used as a query graph to match the overall transfer data graph. Using the method of the present application, an efficient execution plan can be obtained to speed up the search for matching, thereby quickly locating high-risk accounts and users.

[0062] Another embodiment of the present application provides a learning-based subgraph query optimization system, which comprises: A filtering unit for receiving a query graph and filtering a data graph according to the query graph; A planning unit comprising a query graph encoder, a cardinality and cost estimator, and a top-down plan enumerator, wherein the query graph encoder is used to encode the query graph and calculate the vector representation of each subquery graph and the complete query graph; the cardinality and cost estimator is used to estimate the subquery cardinality and the cost of the join operation according to the vector representation of the subquery graph and the complete query graph; and the top-down plan enumerator is used to generate a matching order according to the estimated subquery cardinality and the cost of the join operation; An enumeration unit for recursively enumerating according to the matching order to obtain a subgraph query result.

[0063] The specific processing procedures of the query graph encoder, the cardinality and cost estimator, and the top-down plan enumerator described above can refer to the corresponding procedures in the foregoing method embodiments.

[0064] Another embodiment of the present application provides a computer device (computer, server, smart phone, etc.) comprising a memory and a processor, wherein the memory stores a computer program configured to be executed by the processor, and the computer program comprises instructions for executing the steps of the method of the present application.

[0065] Another embodiment of the present application provides a computer readable storage medium (such as ROM / RAM, magnetic disk, optical disk) storing a computer program, wherein the computer program is executed by a computer to implement the steps of the method of the present application.

[0066] Another embodiment of the present application provides a computer program product comprising a computer program, wherein the computer program is executed by a computer to implement the steps of the method of the present application.

[0067] While the foregoing detailed description has set forth various specific embodiments of the application, it is to be understood that the disclosure is not to be limited to the details of construction or the arrangement of parts as set forth in the foregoing description. The foregoing detailed description is to be considered in all respects only as illustrative and not as restrictive.

Claims

1. A learning-based subgraph query optimization method, characterized in that, Includes the following steps: Receive the query graph and filter the data graph based on the query graph; The query graph is encoded using a query graph encoder, and vector representations of each subquery graph and the complete query graph are computed. Using cardinality and cost estimators, the cardinality of subqueries and the cost of join operations are estimated based on the vector representations of the subquery graph and the full query graph; Based on the estimated cardinality of subqueries and the cost of join operations, a matching order is generated using a top-down plan enumerator; The subgraph query results are obtained by recursively enumerating based on the matching order.

2. The method according to claim 1, characterized in that, The process of encoding the query graph using a query graph encoder includes: In the data chart The data graph is constructed by extending the label. In the data graph of tag expansion Run the embedding algorithm to obtain each tag node. Embedded representation , as a tag The encoding; After obtaining each query graph node from the filtering operation Corresponding candidate set And calculate each query edge candidate set Finally, query each node in the graph. and edge The initial characteristics are: Based on the initial features, the query graph encoder runs a graph neural network on the query graph for several rounds to obtain each final query graph node. The representation of ; Based on query graph nodes The representation of This yields a representation of any subquery graph.

3. The method according to claim 2, characterized in that, The graph neural network includes message passing between neighboring edges, through an update function. Update node The expression, The previous round The representation of Summing the information from neighbors and between neighbors, and then activating it with the ReLU nonlinear function to obtain the first... Wheel representation .

4. The method according to claim 3, characterized in that, The Calculate using the following formula: in, k Indicates the number of iterations. express Neighbors express The edges connecting the neighbors, This represents the learnable coefficient matrix when updating the edge representation. and For the aggregation function, a self-attention aggregation method is used to improve the expressive power of the model.

5. The method according to claim 1, characterized in that, The cardinality and cost estimator is based on the representation of each subquery graph. The cardinality and execution cost are predicted using deep learning models: in, Subquery The base estimate, Indicates from The results of the subquery are enumerated. The estimated execution cost of the result, Indicates that the execution was successful. The execution cost of the plan with the lowest execution cost among all plans is determined; the prediction model consists of three multilayer perceptrons. , and , respectively corresponding , , Three estimates.

6. The method according to claim 5, characterized in that, The top-down plan enumerator generates the matching order through the following steps: The matching order of subgraph queries is modeled as a path on a subgraph grid, where each node in the subgraph grid represents a connected subgraph of the complete query graph, and each edge in the subgraph grid connects the subqueries. and ratio Subquery with one more node ; The matching order is generated in reverse order from top to bottom: if enumerating to the subquery graph Then check all subquery graphs. The representative node's incoming neighbors, from which to select The smallest incoming neighbor ,but Compare The extra nodes are the nodes in the matching order.

7. The method according to claim 6, characterized in that, During training, supervised learning was used to train four sub-models: the query graph encoder, the cardinality estimation model, and the cost model. Estimation model and cost The estimation model.

8. A learning-based subgraph query optimization system, characterized in that, include: The filtering unit is used to receive the query graph and filter the data graph according to the query graph. The planning unit includes a query graph encoder, a cardinality and cost estimator, and a top-down planning enumerator. The query graph encoder encodes the query graph and computes vector representations of each subquery graph and the complete query graph. The cardinality and cost estimator estimates the cardinality of subqueries and the cost of join operations based on the vector representations of the subquery graphs and the complete query graph. Based on the estimated cardinality of subqueries and the cost of join operations, the top-down planning enumerator generates a matching order. The enumeration unit is used to recursively enumerate according to the matching order to obtain the subgraph query results.

9. A computer device, characterized in that, It includes a memory and a processor, the memory storing a computer program configured to be executed by the processor, the computer program including instructions for performing the method of any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which, when executed by a computer, implements the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Database query optimization method based on embeddable subgraph

    CN117390064A