Parallel subgraph matching result cardinal number estimation method and device and medium

By employing parallel processing and adaptive granularity control, the computational inefficiency of subgraph matching cardinality estimation in large-scale graph data processing is resolved, enabling efficient index construction and query processing with a significant speedup.

CN121600378APending Publication Date: 2026-03-03NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511590906.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-03
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing subgraph matching cardinality estimation methods suffer from problems such as serial computation performance bottlenecks, unbalanced loads, excessive thread safety overhead, and excessive parallel overhead in large-scale graph data processing, resulting in low computational efficiency.

Method used

A parallel approach is adopted, which involves parallel construction of the Motif index, parallel refinement of the candidate space, and adaptive granularity control. Combined with a local buffer batch merging mechanism, the system dynamically selects between serial and parallel execution strategies, utilizes multi-core processor resources, reduces synchronization overhead, and solves the problem of load imbalance.

Benefits of technology

While maintaining the same estimation accuracy, it significantly improves the efficiency of index building and query processing, with index building speedup reaching 1.53 to 6.93 times and query processing speedup reaching 1.13 to 4.61 times.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121600378A_ABST
    Figure CN121600378A_ABST
Patent Text Reader

Abstract

The invention discloses a parallel sub-graph matching result cardinal number estimation method and device and a medium. The method comprises the steps that a data graph is preprocessed; a triangular index is constructed in a serial mode, and a parallel four-ring index with nested granularity division is constructed; constructing an initial candidate space of the query graph; refining the candidate space in parallel; sampling the spanning tree of the query graph, and evaluating the precision requirement of a sampling estimation value; when the estimation precision meets a preset requirement, returning an unbiased estimation value based on a sampling result, and directly outputting a cardinality estimation value; otherwise, carrying out parallel graph sampling. Through a parallelization method, the problem of long time consumption of index construction and result cardinal number estimation when an existing serial sub-graph matching cardinal number estimation algorithm processes a large-scale graph is solved; on the premise of keeping the estimation precision unchanged, compared with an existing serial method, the speed-up ratio of 1.53 times to 6.93 times can be obtained in the index construction stage, and the speed-up ratio of 1.13 times to 4.61 times can be obtained in the query processing stage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of graph data processing and analysis technology, specifically relating to a method, device and medium for cardinality estimation of parallel subgraph matching results. Background Technology

[0002] Subgraph matching cardinality estimation is a key technical problem in graph database query optimization. In a graph database system, given a large-scale data graph G and a small-scale query graph q, the goal of subgraph matching cardinality estimation is to quickly and accurately estimate the number of isomorphic embeddings of the query graph q in the data graph G without performing full subgraph matching computation. This technique has significant application value in fields such as bioinformatics, social network analysis, and knowledge graph querying.

[0003] Subgraph matching is an NP-hard problem, with its computational complexity increasing exponentially with graph size. Traditional precise calculation methods often require hours or even days of computation on large-scale graph data, failing to meet the demands of real-time query optimization. Therefore, significantly reducing computational overhead while maintaining estimation accuracy has become a core technical challenge in this field.

[0004] Existing subgraph matching cardinality estimation methods suffer from the following four main technical problems:

[0005] 1. Performance Bottlenecks Due to Serial Computation: Existing subgraph matching cardinality estimation methods with the best prediction accuracy primarily rely on serial computation during the index building and query processing stages, resulting in the following two performance issues: In the index building stage, it is necessary to enumerate all four-ring motif structures, leading to high computational complexity and long processing time. In the query processing stage, the candidate space refinement and graph sampling processes grow rapidly with the size of the query graph, resulting in long execution times. Serial computation cannot fully utilize the computing power of modern multi-core processors, leading to long index building times and long cardinality estimation times in large-scale graph data scenarios.

[0006] 2. Load Imbalance Issue: If simple parallelization optimization is used in the index building phase of existing methods, a load imbalance problem will occur. The edge-based task partitioning method of simple parallelization is prone to uneven distribution of computational tasks when processing real graph data with power-law degree distributions. The computational tasks associated with high-degree vertices are much greater than those for low-degree vertices, causing some threads to be overloaded while others are idle, resulting in low overall parallel efficiency.

[0007] 3. Thread safety overhead caused by index data structures: If the existing method's index building phase is simply parallelized, multiple threads need to concurrently write the index data for the same edge in the graph. To ensure data consistency during concurrent access, a thread-safe data structure is usually required to build the index; however, a thread-safe data structure still uses locking mechanisms during the query phase, causing additional synchronization overhead and reducing access efficiency during the query phase.

[0008] 4. Excessive Parallelism Overhead: Simple parallelization optimization of the existing query processing phase, due to its fine-grained approach, leads to frequent thread scheduling and context switching, resulting in significant overhead. When the candidate set is small, the overhead of parallelization may outweigh the computational gains, and in some scenarios, performance may even be worse than serial execution. Furthermore, concurrent access to the shared index structure during multi-threaded parallel computation relies on atomic operations and locking mechanisms, which also reduces overall efficiency.

[0009] In summary, existing subgraph matching cardinality estimation methods mainly rely on serial computation during the index building and query processing stages, which leads to performance issues when handling large-scale graph data. To address this problem, there is an urgent need to propose an efficient parallelization technique that can fully utilize multi-core processors and improve the efficiency of subgraph matching cardinality estimation. Summary of the Invention

[0010] Purpose of the invention: This invention proposes a method, apparatus, and medium for cardinality estimation of parallel subgraph matching results, aiming to solve the technical problem of low computational efficiency in subgraph matching cardinality estimation methods in graph databases.

[0011] Technical solution: The cardinality estimation method for parallel subgraph matching results described in this invention is implemented as follows:

[0012] (1) Data chart Preprocessing is required;

[0013] (2) Parallel construction of data graphs Motif index: Constructed serially as a triangular index, then using a nested, granular, parallel four-ring index; where the triangular index... Records and edges All vertices forming a triangle, four-ring index Records and edges All edge pairs that make up the four rings;

[0014] (3) Constructing a query graph The initial candidate space;

[0015] (4) Parallel refinement of the candidate space: Multiple vertices of the query graph are processed through multiple rounds of iterative computation; in each round of iteration, for the vertices of the query graph to be processed... , will candidate set Static division into Each subset is assigned to threads, of which Each thread performs a series of security checks in parallel to filter invalid candidates, and records the candidate vertices that fail the checks in a set to be deleted;

[0016] (5) Following the tree sampling process given by the FaSTest algorithm, the query graph is processed. Spanning tree Perform sampling and evaluate the accuracy requirements of the sampled estimate; when the estimation accuracy meets the preset requirements, return the unbiased estimate based on the sampling results and directly execute step (7); otherwise, execute step (6).

[0017] (6) Parallel graph sampling: Select the query graph vertex with the smallest candidate set. As the starting vertex for backtracking search; based on the size of the candidate set of starting vertices. With thread count Based on the relationship, different parallel granularity control strategies are set;

[0018] (7) Output cardinality estimate: Based on the global sampling statistics, the final cardinality estimate is calculated and output using the corresponding estimation formula in the FaSTest algorithm.

[0019] Furthermore, the implementation process of step (1) is as follows:

[0020] Data chart , Data chart The set of vertices; Data chart The set of edges; The vertex labeling function maps each vertex of the data graph to a finite set of labels. ; Calculate the degree of each vertex And label frequency distribution, for each edge Calculate processing cost:

[0021]

[0022] And calculate the average processing cost for all edges:

[0023]

[0024] Initialize the thread pool, setting the number of threads according to the user-provided parameters. This binds different threads to different CPU cores.

[0025] Furthermore, the implementation process of constructing the parallel four-ring index with nested granularity partitioning in step (2) is as follows:

[0026] For each edge Assuming It is the endpoint with the lower degree of the edge; for those satisfying the condition For ordinary edges, a coarse-grained index is used to construct a task partitioning scheme, where, Let $\frac{ ... For high-load edges, a fine-grained index building task partitioning scheme is adopted; for all four-ring index building tasks obtained by the above partitioning scheme, multiple threads are used to execute in parallel; during the execution of the task, each thread uses a thread-local buffer to collect the enumerated four-ring structures; after all threads have completed the calculation, the four-ring structures collected in the local buffer are batch merged into the global index through atomic operations.

[0027] Furthermore, the coarse-grained index building task partitioning scheme is as follows: All tasks that meet the conditions... The set of edges is divided into disjoint subsets, of which For each subset, create a four-ring index building task for each thread.

[0028] Furthermore, the fine-grained index building task partitioning scheme is as follows: for all conditions... edge , will set Divided into For each of the disjoint subsets, create a four-ring index building task.

[0029] Furthermore, the implementation process of step (3) is as follows:

[0030] For each query vertex Based on tag matching conditions Neighbor label counting constraint Construct a candidate vertex set ,in Represents a query graph A collection of tags, In the data chart Mid-vertex The neighbors are tagged as The number of vertices, Indicates querying the graph Mid-vertex The neighbors are tagged as The number of vertices; Indicates querying the vertex The candidate vertex set in the data graph; construct the corresponding candidate edge set for each query edge, forming the initial candidate space. , This is a combination of all candidate sets of query vertices and candidate sets of query edges.

[0031] Furthermore, in step (4), each thread employs a local buffering mechanism to batch delete invalid candidates, thus avoiding frequent modifications to the candidate space. Access to the corresponding global data structure; each thread creates a local deletion set before starting to process the allocated subset of candidate vertices. Used for temporary storage of invalid candidate vertices that need to be deleted; each thread independently performs a series of safety checks on the allocated candidate vertices, including neighbor safety, triangle safety, four-ring safety, and edge binary search safety checks; during the checks, the thread only checks the candidate space. Perform read-only access by querying a pre-built triangular index. and four-ring index To verify the validity of candidate vertices; when a thread finds a candidate vertex... If any security condition is violated, do not immediately remove from the global candidate set. Instead of deleting the vertex, add it to the local deletion set. In the middle; after all threads have completed their assigned candidate vertex checks, the system enters a synchronization point, where the main thread removes the local deletion sets of each thread. Merge into a global deletion set Then from the candidate set all at once Remove all marked invalid vertices, i.e., update. While deleting invalid vertices, the system simultaneously updates the vertices. The candidate set of all adjacent query edges ensures the consistency of the candidate space; for each edge From the candidate set Remove all candidate edges that contain deleted vertices.

[0032] Furthermore, the different parallel granularity control strategies described in step (6) are as follows:

[0033] when At that time, among them For the number of threads, the candidate set Divided into A disjoint subset; when At this time, parallelization is not triggered; all candidate vertices are processed sequentially in a serial manner; all subsets are assigned to Multiple threads process in parallel. Each thread independently performs subgraph matching sampling search based on the assigned subset of candidate vertices. The number of samples and successful matches obtained by each thread are recorded. The local statistical results of each thread are periodically merged into the global statistical variables through batch atomic operations to reduce the overhead of frequent synchronization.

[0034] An electronic device according to the present invention includes a memory and a processor, wherein:

[0035] Memory is used to store computer programs that can run on a processor;

[0036] A processor, configured to, while running the computer program, perform the steps of the parallel subgraph matching result cardinality estimation method as described above.

[0037] The present invention provides a storage medium storing a computer program, which, when executed by at least one processor, implements the steps of the parallel subgraph matching result cardinality estimation method as described above.

[0038] Beneficial Effects: Compared with existing technologies, the present invention offers the following advantages: It improves upon existing serial subgraph matching cardinality estimation algorithms by employing parallelization methods, addressing the time-consuming index construction and result cardinality estimation in processing large-scale graphs. For graph data with power-law distribution characteristics, it proposes a nested granular task partitioning strategy based on computational cost assessment, effectively resolving the load imbalance problem caused by the power-law distribution of graph data. The local buffer batch merging multi-threaded synchronization mechanism significantly reduces multi-threaded synchronization overhead. Dynamically selecting serial or parallel execution strategies based on the candidate set size avoids the additional overhead of fine-grained parallelism. Statically dividing the candidate set into fixed-size data blocks reduces dynamic scheduling overhead. Binding processing threads to specific CPU cores improves cache hit rate and reduces thread switching overhead. While maintaining the same estimation accuracy, the present invention achieves a speedup of 1.53 to 6.93 times compared to existing serial methods in the index construction stage and 1.13 to 4.61 times in the query processing stage. Attached Figure Description

[0039] Figure 1 A flowchart of a parallel subgraph matching cardinality estimation method;

[0040] Figure 2 This is a flowchart of the nested granularity partitioning strategy proposed in this invention;

[0041] Figure 3 This is a flowchart of the parallel candidate space refinement process proposed in this invention;

[0042] Figure 4 This is a flowchart of the parallel graph sampling process proposed in this invention;

[0043] Figure 5 Data diagram used in specific implementation methods and query graph A schematic diagram;

[0044] Figure 6 The acceleration effect of six different data graphs during the index building phase is shown in the graph.

[0045] Figure 7 The acceleration effect diagrams for six different query graphs in the query processing stage;

[0046] Figure 8 A comparison chart of estimation accuracy under different numbers of threads;

[0047] Figure 9 Given a query request, the resulting query subgraphs under two different vertex matching orders, and the cardinality of the matching results for each query subgraph. Detailed Implementation

[0048] The present invention will now be described in further detail with reference to the accompanying drawings.

[0049] like Figure 1 As shown, this invention proposes a method for cardinality estimation of parallel subgraph matching results, using data graphs stored in a graph database. and query graph As input, the number of threads As a method parameter. Data chart The set of vertices; Data chart The set of edges (when When it is an undirected graph, (The edges in the array are considered unordered pairs). The vertex labeling function maps each vertex of the data graph to a finite set of labels. For any vertex Let its neighbor set be . Vertex degree is ; Counting neighbors by label can be represented as ,in Query Image Symbol meanings and data charts The symbols correspond to each other. During the index building phase, steps (1) to (2) are performed on the input data graph G; during the query processing phase, steps (1) to (2) are performed on the input query graph G. The execution steps (3) to (6) are performed, and step (7) outputs the final result. The specific implementation process is as follows:

[0050] Step (1): Data Chart Preprocessing: Calculate the degree of each vertex. And label frequency distribution, for each edge Calculate processing cost:

[0051]

[0052] And calculate the average processing cost for all edges:

[0053]

[0054] Initialize the thread pool, setting the number of threads according to the user-provided parameters. This binds different threads to different CPU cores.

[0055] Step (2): As Figure 2 As shown, data graphs are constructed in parallel. Motif index: First, construct a triangular index sequentially. Then, construct the four-ring index in parallel. During the construction of the four-ring index, for each edge... Assuming It is the endpoint with the lower degree of the edge; for those satisfying the condition For ordinary edges, a coarse-grained index is used to construct a task partitioning scheme; for those satisfying the condition... For high-load edges under certain conditions, a fine-grained task partitioning scheme is adopted. For all four-ring index construction tasks obtained by the above partitioning scheme, multiple threads are used to execute them in parallel. During the execution of the task, each thread uses a thread-local buffer to collect the enumerated four-ring structures. After all threads have completed the calculation, the four-ring structures collected in the local buffer are merged into the global index in batches through atomic operations.

[0056] Triangle Index Records and edges All vertices forming a triangle, four-ring index Records and edges All edge pairs that make up the four rings.

[0057] The process of a coarse-grained task partitioning scheme is as follows: All tasks that meet the conditions... The set of edges is divided into 4 Disjoint subsets (where the parallel granularity expansion factor X = 4) (Number of threads), create a four-ring index building task for each subset.

[0058] The process of fine-grained task partitioning is as follows: for all conditions that are met... edge , will set Divided into For each of the disjoint subsets, create a four-ring index building task.

[0059] Step (3): Construct the query graph Initial candidate space: for each query vertex Based on tag matching conditions Neighbor label counting constraint Construct a candidate vertex set ,in Represents a query graph A collection of tags, In the data chart Mid-vertex The neighbors are tagged as The number of vertices, Indicates querying the graph Mid-vertex The neighbors are tagged as The number of vertices; Indicates querying the vertex The candidate vertex set in the data graph; construct the corresponding candidate edge set for each query edge, forming the initial candidate space. , This is a combination of all candidate sets of query vertices and candidate sets of query edges.

[0060] Step (4): As Figure 3 As shown, the candidate space is refined in parallel: multiple vertices of the query graph are processed through multiple rounds of iterative computation; in each round of iteration, for the vertices of the query graph to be processed... , will candidate set Static division into Each subset is assigned to a thread, and each thread performs neighbor safety checks, triangle safety checks, and four-ring safety checks in parallel. The neighbor safety check verifies whether each candidate edge can form a valid subgraph structure with the adjacent candidate sets, and further filters invalid candidates by combining triangle and four-ring indices. Each thread records the candidate vertices that fail the check in a set to be deleted.

[0061] Each thread uses a local buffering mechanism to delete invalid candidates in batches, avoiding frequent modifications to the candidate space. Corresponding global data structure access: Before starting to process the allocated subset of candidate vertices, each thread creates a local deletion set. This space is used for temporary storage of invalid candidate vertices that need to be deleted; each thread independently performs a series of safety checks on the allocated candidate vertices, including neighbor safety, triangle safety, four-ring safety, and edge binary search safety checks; during the checks, the thread only checks the candidate space. Perform read-only access by querying a pre-built triangular index. and four-ring index To verify the validity of candidate vertices; when a thread finds a candidate vertex... If any security condition is violated, do not immediately remove from the global candidate set. Instead of deleting the vertex, add it to the local deletion set. In the middle; after all threads have completed their assigned candidate vertex checks, the system enters a synchronization point, where the main thread retrieves the local deletion sets of each thread. Merge into a global deletion set Then from the candidate set all at once Remove all marked invalid vertices, i.e., update. While deleting invalid vertices, the system simultaneously updates the vertices. The candidate set of all adjacent query edges ensures the consistency of the candidate space; for each edge From the candidate set Remove all candidate edges that contain deleted vertices.

[0062] Step (5): Tree sampling: Following the tree sampling process given by the FaSTest algorithm, the query graph is processed. Spanning tree Perform sampling and evaluate the accuracy requirements of the sampled estimate. When the estimation accuracy meets the preset requirements, return the unbiased estimate based on the sampling results and directly execute step (7); otherwise, execute step (6).

[0063] Step (6): As Figure 4 As shown, parallel graph sampling involves selecting the query graph vertex with the smallest candidate set. As the starting vertex for backtracking search; based on the size of the candidate set of starting vertices. With thread count The relationship allows for setting different parallel granularity control strategies: When When (where the parallel granularity expansion factor X=4, (This refers to the number of threads), and the candidate set. Divided into A disjoint subset; when When (where the parallel granularity expansion factor X=4, (where the number of threads is the number of threads), then process the candidate set. Parallelization is not triggered at this time; all candidate vertices are processed sequentially in a serial manner to avoid parallel overhead; all subsets are assigned to Multiple threads process in parallel, with each thread independently performing subgraph matching sampling search based on its assigned subset of candidate vertices. Information such as the number of samples and successful matches obtained by each thread is periodically merged into global statistical variables through batch atomic operations, reducing the overhead of frequent synchronization.

[0064] Step (7): Output cardinality estimate: Based on the global sampling statistics, use the corresponding estimation formula in the FaSTest algorithm to calculate and output the final cardinality estimate.

[0065] The present invention also provides an electronic device, including a memory and a processor, wherein: the memory is used to store a computer program that can run on the processor; and the processor is used to execute, when running the computer program, the steps of the parallel subgraph matching result cardinality estimation method as described above.

[0066] The present invention also provides a storage medium storing a computer program, which, when executed by at least one processor, implements the steps of the parallel subgraph matching result cardinality estimation method as described above.

[0067] The following specific example illustrates the implementation process of this invention. Assume there is a data graph. The graph contains 50 vertices and 54 edges. It contains 4 vertices and 5 edges, and the number of threads is set. .

[0068] Figure 5 The image shown is a data chart used in this specific example. and query graph The diagram shows the vertex numbers next to the vertices, and the vertex labels inside the vertices. (Data graph) The ellipsis in the middle indicates from to Vertices, each only with Connected.

[0069] Data graph preprocessing stage: edges Connecting vertices with a degree of 46, the processing cost is... , side Connecting vertices with degrees of 46 and 1, the processing cost is... ; Calculate the average processing cost for all 54 edges. Initialize a thread pool for two threads and bind the threads to CPU core 0 and CPU core 1 respectively.

[0070] Triangle index construction: opposite sides Find the vertices that form a triangle with this side: [Found] and and They are all adjacent and form a triangle. and ,therefore The processing of other edges is similar.

[0071] Coarse-grained construction task partitioning scheme: meets the following conditions The set of edges is ; User-provided parameters , Divide these edges into disjoint subsets and Each subset corresponds to a four-ring index building task.

[0072] Fine-grained build task partitioning scheme: meets the following conditions The set of edges is ; User-provided parameters Divide these edges into disjoint subsets and Each subset corresponds to a four-ring index building task.

[0073] Parallel four-ring index construction: Thread 0 processes edges and The task is constructed; during task execution, the enumerated four-ring structures are collected using a thread-local buffer and temporarily stored in local_list_1; thread 1 processes the edges. and The task is built; the results are temporarily stored in local_list_2. After the task is completed, the local results are merged through atomic operations: first, local_list_1 is atomically appended to the global index, and then local_list_2 is atomically appended; finally, the result is obtained. Other aspects will not be discussed further here.

[0074] Constructing the initial candidate space:

[0075] For querying vertices (Label A, degree 3), check the data graph for labels A and degrees. The vertices of 3 are used to obtain the candidate set. ;

[0076] For querying vertices (Label B, degree 2), check the data graph where the label is B and the degree is 2. The vertex of 2 is used to obtain the candidate set. ;

[0077] For querying vertices (Label A, degree 3), check the data graph for labels A and degrees. The vertices of 3 are used to obtain the candidate set. ;

[0078] For querying vertices (Label C, Degree 2), check the data graph where the label is C and the degree is 2. The vertex of 2 is used to obtain the candidate set. .

[0079] Construct an edge candidate set, based on the edge For example,

[0080] Parallel refinement of the candidate space: First round of iteration selects vertices of the query graph Processing, will Based on the static block partitioning strategy: Thread 1 handles... Thread 2 processing .

[0081] Thread 1 checks Security: Residential security check, query vertex The neighbor is ,examine Neighbors Can it cover? All neighbor tag requirements, (Label B) can be derived from match, (Label A) can be derived from match, (Label C) can be derived from Matching and neighbor security are satisfied. Triangle security check, query triangle. ,Require It can form a triangle with its neighbors, the vertices labeled B and A. (Use triangle indexing.) ,Discover It does indeed form a triangle; query triangle. By index and Verification passed. Fourth Ring Road security check, query Fourth Ring Road. Corresponding data Figure 4 ring Through the four-ring index The existence of a complete four-ring structure has been verified, and the four-ring safety requirements are met. The local deletion set of thread 1 passes all security checks. .

[0082] Thread 2 check Security: Neighbor security check, query vertex The neighbor is ,examine Neighbors Can it cover? All neighbor tag requirements, (Label B) can be derived from match, (Label A) can be derived from match, (Label C) can be derived from Matching, neighbor security is satisfied; triangle security check, query triangle. ,Require It can form a triangle with its neighbors, the vertices labeled B and A; using triangle indexing. ,Discover It does indeed form a triangle; query triangle. By index Verification passed; Fourth Ring Road security check, query Fourth Ring Road. Corresponding data Figure 4 ring Through the four-ring index The existence of a complete four-ring structure has been verified, and the four-ring safety requirements are met. Thread 2's local deletion set passes all security checks. The main thread merges the local delete sets of each thread into a global delete set. .

[0083] Repeat the above steps. , and After processing , , , .

[0084] Select the spanning tree of the query graph ,by Construct a tree structure for the root node. First, calculate the total number of candidate trees: use a dynamic programming algorithm to calculate the number of candidate trees for each subtree from bottom to top. Let... Indicates querying vertices Root, mapped to data vertices The number of candidate trees for the subtree.

[0085] For leaf nodes : For nodes : (because ), (because ); for nodes : For the root node : , .

[0086] Total number of candidate trees:

[0087] .

[0088] Perform tree sampling process: starting from the root node Start by weight Candidate vertices are randomly selected. The following illustrates a typical sampling process:

[0089] (from According to probability (Selection); along the edge of the spanning tree ,choose Candidate vertices: ( (The only option); verify tree edges Corresponding data graph edge Verification passed; continue along the tree edge. ,choose Candidate vertices: (from Select by weight, excluding those already used. Later selection ); Verify tree edges Corresponding data graph edge Verification passed; finally, along the edge of the tree. ,choose Candidate vertices: (from Select); Validate tree edges Corresponding data graph edge Verification passed; non-tree edge verification. :verify The sample was found to be present, indicating that the sampling was successful.

[0090] Repeat the above random sampling and validation process for several candidate trees. Due to the randomness of the sampling process, the number of trials run each time... Number of successful verifications There will be differences. The unbiased estimate returned by tree sampling is:

[0091]

[0092] Following the FaSTest process, the Clopper-Pearson confidence interval is used to determine the tree sampling accuracy: when the number of successful attempts... At that time, the estimation accuracy usually does not meet the requirements. , ), graph sampling is required to improve estimation accuracy.

[0093] Select the query vertex with the smallest candidate set. As the starting vertex of the backtracking search ( According to the adaptive parallel granularity control strategy, due to (set up , ), adopting a lightweight parallel scheme, in actual use Each thread performs graph sampling.

[0094] Hierarchical sampling search process: A hierarchical backtracking framework is used, randomly selecting candidate branches at each level according to a set sampling ratio. The following illustrates a typical sampling process:

[0095] Layer 0: Fixed As the initial mapping.

[0096] Layer 1: Extension Neighbors ,from Medium sampling. Let the sampling ratio be... (i.e., sampling factor is) ), randomly selected Check the edge ,efficient.

[0097] Layer 2: Continue to expand From the candidate set after removing used vertices Select Check the edge and All are effective

[0098] Layer 3: Extension From the remaining candidate set Select ,examine and All are effective

[0099] Get a complete match: .

[0100] The backtracking process continues to explore other sampling branches. Due to the randomness of sampling, the number of complete matches found in each run will vary. Graph sampling estimates the total number of embeddings through sampling statistics.

[0101] Since both tree sampling and graph sampling are stochastic processes, each run will produce different statistical results. The following shows a possible execution example:

[0102] Tree sampling statistics: Total number of candidate trees After several random samplings, the number of successful verifications did not reach the threshold of 88, so the process switched to graph sampling.

[0103] Statistical information of the sampling diagram: After stratified random sampling and unbiased estimation by combining the sampling factor, the base estimate value of 2 is obtained.

[0104] Based on the unbiased estimation formula and random sampling statistics of the FaSTest algorithm, the final subgraph matching cardinality estimate is output. This estimate is a random variable, and its expected value approaches the true number of embeddings.

[0105] Verification: Exhaustive search reveals that the query graph... In the data chart There are indeed two isomorphic embeddings:

[0106]

[0107] and

[0108]

[0109] The effectiveness of the parallel estimation algorithm was verified.

[0110] To verify the effectiveness of this invention, comprehensive performance tests were conducted on six real-world graph datasets. The experimental environment used an Intel Xeon 8358 dual-processor server with Ubuntu 22.04 operating system and GCC 11.4 compiler with the highest (-Ofast) optimization level enabled.

[0111] Figure 6 The graph illustrates the speedup effect on six different datasets during the index building phase. The vertical axis represents the speedup ratio, and the horizontal axis represents the number of threads. Experimental results show that, in a 16-thread environment, the speedup ratio compared to the serial algorithm ranges from 1.53 to 6.93. Particularly on high-load datasets (such as YouTube and Human), the nested granularity partitioning strategy significantly improves parallel efficiency.

[0112] Figure 7 The speedup effect of six different query graphs in the query processing stage is shown on the vertical axis, representing the speedup ratio, and the horizontal axis, representing the number of threads. Experimental results show that, in a 16-thread environment, the speedup ratio compared to the serial algorithm ranges from 1.13 to 4.61. On larger query graphs, parallel candidate space refinement and parallel graph sampling techniques effectively improve query processing efficiency.

[0113] Figure 8 To illustrate the estimation accuracy under different thread counts, the vertical axis represents the relative value obtained by dividing the estimate obtained using parallel computation by the estimate obtained using serial computation, and the horizontal axis represents the query graph for different data graphs. Experimental results show that on any query graph, the estimation accuracy of the parallel algorithm remains consistent with that of the serial algorithm, with the relative error controlled within 0.52%. This ensures the correctness of the parallel algorithm.

[0114] The method described in this invention is a key technology in graph databases and one of the core technologies for graph database engines to optimize subgraph matching query plans. During graph database queries, after parsing the query request, the graph database query engine needs to generate an efficient vertex matching order for each vertex in the query to minimize the execution overhead of the query plan. The execution overhead of a subgraph matching query plan is typically positively correlated with the cardinality of the matching results in the query subgraph. Figure 9 This diagram illustrates the query subgraphs generated by the matching process for a query request under two different vertex matching orders, along with the cardinality of the matching results for each subgraph. The diagram shows that the sum of the cardinality of the matching results for each subgraph in matching order 1 is significantly higher than that in matching order 2. Therefore, matching order 2 has lower query execution overhead and should be chosen as the optimized vertex matching order for the query plan. Thus, accurately estimating the cardinality of the matching results for query subgraphs is crucial for obtaining a high-quality query plan.

[0115] Since the cardinality estimation operation for query subgraph matching results is frequently invoked during query plan optimization, its computation speed significantly impacts the execution time of the optimization process. For a query request with n vertices, there are n! possible vertex matching orders, and the number of query subgraphs and the number of cardinality estimation operations for subgraph matching results both increase exponentially with n. For complex query requests containing a large number of vertices, cardinality estimation for subgraph matching results becomes a major performance bottleneck in the query plan optimization process.

[0116] This invention overcomes the serial computation bottleneck of existing fast filtering and sampling algorithms by employing multi-threaded parallel computing technology. In the index construction phase, a nested granularity partitioning strategy addresses the performance bottleneck of building a four-ring index. In the query processing phase, parallel candidate space refinement and parallel graph sampling techniques fully utilize multi-core processor resources, significantly shortening the algorithm execution time. Addressing the power-law degree distribution characteristic commonly found in real graph data, the nested granularity partitioning mechanism proposed in this invention automatically identifies high-load computational tasks and performs secondary subdivision, effectively solving the load imbalance problem caused by high-height vertices in existing technologies. Through computational cost assessment and adaptive task partitioning, load balancing among multiple threads is achieved, improving parallel efficiency. This invention uses a local buffer batch merging mechanism to convert frequent atomic operations into batch operations, significantly reducing multi-threaded synchronization overhead. Simultaneously, through data structure conversion technology, lock overhead in the query phase is eliminated after index construction, avoiding the performance loss of thread-safe mechanisms in read-only scenarios in existing technologies. This invention designs an adaptive parallel granularity control mechanism that dynamically selects serial or parallel execution strategies based on the candidate set size, avoiding the additional overhead of fine-grained parallelism on small-scale tasks. This mechanism ensures that the benefits of parallelization always outweigh the introduced overhead, achieving a true performance improvement. This invention fully maintains the estimation accuracy of the original algorithm while achieving parallel acceleration. Through a carefully designed parallelization strategy and synchronization mechanism, it ensures that the computational results of the parallel algorithm are consistent with those of the serial algorithm, with the relative error controlled within 0.52%, meeting the accuracy requirements of practical applications.

[0117] The above are merely preferred embodiments of the present invention. The scope of protection of the present invention is not limited to the above embodiments. All technical solutions falling within the scope of the present invention's concept are within the scope of protection of the present invention. It should be noted that for those skilled in the art, any improvements and modifications made without departing from the principles of the present invention should be considered within the scope of protection of the present invention.

Claims

1. A method for cardinality estimation of parallel subgraph matching results, characterized in that, Includes the following steps: (1) Data chart Preprocessing is required; (2) Parallel construction of data graphs Motif index: Constructed serially as a triangular index, then using a nested, granular, parallel four-ring index; where the triangular index... Records and edges All vertices forming a triangle, four-ring index Records and edges All edge pairs that make up the four rings; (3) Constructing a query graph The initial candidate space; (4) Parallel refinement of the candidate space: Multiple vertices of the query graph are processed through multiple rounds of iterative computation; in each round of iteration, for the vertices of the query graph to be processed... , will candidate set Static division into Each subset is assigned to threads, of which Each thread performs a series of security checks in parallel to filter invalid candidates, and records the candidate vertices that fail the checks in a set to be deleted; (5) Following the tree sampling process given by the FaSTest algorithm, the query graph is processed. Spanning tree Perform sampling and evaluate the accuracy requirements of the sampled estimate; when the estimation accuracy meets the preset requirements, return the unbiased estimate based on the sampling results and directly execute step (7); otherwise, execute step (6). (6) Parallel graph sampling: Select the query graph vertex with the smallest candidate set. As the starting vertex for backtracking search; based on the size of the candidate set of starting vertices. With thread count Based on the relationship, different parallel granularity control strategies are set; (7) Output cardinality estimate: Based on the global sampling statistics, the final cardinality estimate is calculated and output using the corresponding estimation formula in the FaSTest algorithm.

2. The method for cardinality estimation of parallel subgraph matching results according to claim 1, characterized in that, The implementation process of step (1) is as follows: Data chart , Data chart The set of vertices; Data chart The set of edges; The vertex labeling function maps each vertex of the data graph to a finite set of labels. Count the degree of each vertex. And label frequency distribution, for each edge Calculate processing cost: And calculate the average processing cost for all edges: Initialize the thread pool, setting the number of threads according to the user-provided parameters. This binds different threads to different CPU cores.

3. The method for cardinality estimation of parallel subgraph matching results according to claim 1, characterized in that, The implementation process of constructing the parallel four-ring index with nested granularity partitioning in step (2) is as follows: For each edge Assuming It is the endpoint with the lower degree of the edge; for those satisfying the condition For ordinary edges, a coarse-grained index is used to construct a task partitioning scheme, where, Let $\frac{ ... For high-load edges, a fine-grained index construction task partitioning scheme is adopted; for all four-ring index construction tasks obtained by the above partitioning scheme, multiple threads are used to execute in parallel; during the execution of the task, each thread uses a thread-local buffer to collect the enumerated four-ring structures; after all threads have completed the calculation, the four-ring structures collected in the local buffer are batch merged into the global index through atomic operations.

4. The method for cardinality estimation of parallel subgraph matching results according to claim 3, characterized in that, The coarse-grained index building task partitioning scheme is as follows: All tasks that meet the conditions... The set of edges is divided into disjoint subsets, of which For each subset, create a four-ring index building task for each thread.

5. The method for cardinality estimation of parallel subgraph matching results according to claim 3, characterized in that, The fine-grained index building task partitioning scheme is as follows: for all conditions... edge , will set Divided into For each of the disjoint subsets, create a four-ring index building task.

6. The method for cardinality estimation of parallel subgraph matching results according to claim 1, characterized in that, The implementation process of step (3) is as follows: For each query vertex Based on tag matching conditions Neighbor label counting constraint Constructing a candidate vertex set ,in Represents a query graph A collection of tags, In the data chart Mid-vertex The neighbors are tagged as The number of vertices, Indicates querying the graph Mid-vertex The neighbors are tagged as The number of vertices; Indicates querying the vertex The candidate vertex set in the data graph; construct the corresponding candidate edge set for each query edge, forming the initial candidate space. , This is a combination of all candidate sets of query vertices and candidate sets of query edges.

7. The method for cardinality estimation of parallel subgraph matching results according to claim 1, characterized in that, In step (4), each thread uses a local buffering mechanism to delete invalid candidates in batches, avoiding frequent modifications to the candidate space. Access to the corresponding global data structure; each thread creates a local deletion set before starting to process the allocated subset of candidate vertices. Used for temporary storage of invalid candidate vertices that need to be deleted; Each thread independently performs a series of safety checks on the assigned candidate vertices, including neighbor safety, triangle safety, four-ring safety, and edge binary search safety checks; During the inspection process, the thread only checks the candidate space. Perform read-only access by querying a pre-built triangular index. and four-ring index To verify the validity of the candidate vertices; When a thread discovers a candidate vertex If any security condition is violated, do not immediately select from the global candidate set. Instead of deleting the vertex, add it to the local deletion set. In the middle; after all threads have completed their assigned candidate vertex checks, the system enters a synchronization point, where the main thread removes the local deletion sets of each thread. Merge into a global deletion set Then from the candidate set all at once Remove all marked invalid vertices, i.e., update. While deleting invalid vertices, the system simultaneously updates the vertices. The candidate set of all adjacent query edges is used to ensure the consistency of the candidate space; for each edge From the candidate set Remove all candidate edges that contain deleted vertices.

8. The method for cardinality estimation of parallel subgraph matching results according to claim 1, characterized in that, The different parallel granularity control strategies mentioned in step (6) are as follows: when At that time, among them For the number of threads, the candidate set Divided into A disjoint subset; when At this time, parallelization is not triggered; all candidate vertices are processed sequentially in a serial manner; all subsets are assigned to Multiple threads process in parallel. Each thread independently performs subgraph matching sampling search based on the assigned subset of candidate vertices. The number of samples and successful matches obtained by each thread are recorded. The local statistical results of each thread are periodically merged into the global statistical variables through batch atomic operations to reduce the overhead of frequent synchronization.

9. An electronic device, characterized in that, Includes memory and processor, wherein: Memory is used to store computer programs that can run on a processor; A processor, configured to, while running the computer program, perform the steps of the parallel subgraph matching result cardinality estimation method as described in any one of claims 1 to 8.

10. A storage medium, characterized in that, The storage medium stores a computer program that, when executed by at least one processor, implements the steps of the parallel subgraph matching result cardinality estimation method as described in any one of claims 1 to 8.