A query optimization system for distributed knowledge graph

By optimizing the shard access order and constructing a merged dependency tree for distributed knowledge graph queries, the problems of fixed shard access order and inaccurate estimation of cross-shard connection costs are solved, resulting in more efficient query response and intermediate result merging.

CN123178482APending Publication Date: 2026-11-27CHINA JILIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611687242.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-29
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

In existing technologies for distributed knowledge graph queries, the fixed access order of shards, inaccurate estimation of cross-shard connection costs, and unclear merging hierarchy of intermediate result sets lead to high cross-shard connection overhead and increased computational load for merging intermediate results.

Method used

By generating an initial query sharding routing strategy, combining the query entity frequency distribution and sharding boundary association graph, the data sharding access order is optimized, and a merge dependency tree is constructed to perform hierarchical merging of intermediate result sets, reducing cross-shard connection overhead and intermediate result redundancy.

Benefits of technology

The response efficiency of distributed knowledge graph queries has been optimized, the computational cost and storage usage of cross-shard connections and intermediate result merging have been reduced, and the response efficiency of complex queries has been improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178482A_ABST
    Figure CN123178482A_ABST
Patent Text Reader

Abstract

The application discloses a kind of distributed knowledge graph-oriented query optimization systems, belong to distributed knowledge graph query optimization technical field.The system includes the query entity and query relationship in original query sentence in syntax analysis module extraction;Routing generation module generates initial shard routing strategy according to the frequency distribution of query entity in each data shard;Cost optimization module determines cross-piece connection cost and adjusts access order to obtain optimization routing strategy according to query relationship and shard boundary graph association;Distribution execution module distributes subquery according to optimization strategy and collects intermediate result set;Dependence tree construction module constructs and merges dependence tree according to result set source identification and triple subject consistency;Result merging module is merged from leaf node to root node layer by layer to generate final result according to dependence tree.Result merging module is merged from leaf node to root node layer by layer to generate final result according to dependence tree.The application realizes the efficient routing and result merging of distributed knowledge graph query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of distributed knowledge graph query optimization technology, specifically a query optimization system for distributed knowledge graphs. Background Technology

[0002] Distributed knowledge graphs typically store entities, relations, and triples across multiple data shards according to certain partitioning rules. For cross-shard queries, existing query optimization methods often determine the data shards involved in the query based on static mapping tables of query entities, global statistics of data shards, or fixed hash rules, and then access them sequentially according to a preset shard order. This approach fails to adequately utilize the differences in entity frequency distribution across different data shards, and the initial route shard is prone to deviating from the shards where the query entities are actually densely distributed, resulting in invalid access to sparsely associated shards and the execution of additional subqueries. Regarding cross-shard joins between adjacent data shards, existing methods often determine the join order based on shard numbers, fixed order, or a simple cost model based solely on shard size, without considering the boundary relation edges in the shard boundary association graph and the semantic type of the query relation for cross-shard join cost quantification. This leads to a discrepancy between the cross-shard join order and the actual degree of association between shards, resulting in significant cross-shard data transmission and join computation overhead.

[0003] After each data shard returns an intermediate result set, existing result merging methods typically perform global joins or pairwise merging of the intermediate result sets. They fail to establish a hierarchical merging structure based on the data shard source identifiers corresponding to the intermediate result sets and the subject consistency of the intermediate result triples. This leads to repeated scanning and comparison of the same subject across intermediate results from different sources, resulting in unclear merging hierarchy relationships and increased computational and storage space consumption during intermediate result merging. Distributed knowledge graph query processes need to suppress cross-shard join overhead caused by differences in query entity distribution and unreasonable shard access order, and optimize the issues of duplicate matching and unclear hierarchical dependencies during intermediate result set merging. Summary of the Invention

[0004] To address the issues of fixed shard access order, inaccurate estimation of cross-shard connection costs, and unclear merging hierarchy of intermediate result sets during distributed knowledge graph queries, this invention provides a query optimization system for distributed knowledge graphs. It generates an initial query shard routing strategy based on the entity frequency distribution of query entities across data shards, adjusts the data shard access order by combining query relationships and shard boundary association graphs, and constructs a merging dependency tree based on the data shard source identifiers corresponding to intermediate result sets and the subject consistency of intermediate result triples. The system then merges nodes layer by layer from leaf nodes to root nodes according to the node hierarchy of the merging dependency tree, reducing cross-shard connection overhead and the cost of repeated intermediate result merging.

[0005] To achieve the above objectives, this invention provides the following technical solution: This invention provides a query optimization system for distributed knowledge graphs, including a syntax parsing module, a route generation module, a cost optimization module, a distribution and execution module, a dependency tree construction module, and a result merging module. The syntax parsing module performs syntax parsing on the received raw query statement to extract query entities and query relationships. The route generation module generates an initial query shard routing strategy based on the entity frequency distribution of query entities in each data shard of the distributed knowledge graph. The cost optimization module determines the cross-shard connection cost between adjacent data shards in the initial query shard routing strategy based on the query relationships and a preset shard boundary association graph, and adjusts the access order of each data shard in the initial query shard routing strategy according to the cross-shard connection cost to obtain an optimized query shard routing strategy. The distribution and execution module distributes subqueries to the corresponding data shards according to the optimized query shard routing strategy, and collects the intermediate result sets returned by each data shard after each data shard has executed the subqueries. The dependency tree construction module constructs a merged dependency tree for the intermediate result sets based on the data shard source identifiers corresponding to the intermediate result sets and the subject consistency of the intermediate result triples contained in the intermediate result sets. The root node of the merged dependency tree corresponds to the final query result. The result merging module performs result merging operations on the intermediate result sets layer by layer from the leaf nodes to the root node according to the node hierarchy of the merged dependency tree, generating the final query result of the original query statement. This system utilizes entity frequency distribution and cross-shard join cost to jointly constrain the access order of data shards, and performs hierarchical merging by constructing a merged dependency tree through subject consistency, which can reduce cross-shard join overhead and intermediate result redundancy, and improve the response efficiency of complex queries.

[0006] As a technical solution of this invention, the route generation module obtains the entity identifier set stored in each data shard of the distributed knowledge graph, and performs a matching operation between the query entity and the entity identifier set of each data shard to determine the entity frequency distribution of the query entity in each data shard. The data shard with the highest frequency value in the entity frequency distribution is selected as the main route shard for the query entity, and the intersection of the main route shards of all query entities in the original query statement is taken. An initial query shard routing strategy is generated based on the intersection result. When the number of shards corresponding to the intersection result is a single shard, this single shard is set as the first shard visited in the initial query shard routing strategy, and the access order of the remaining data shards is arranged in descending order of the entity frequency distribution value of the query entity in the first shard visited. When the number of shards corresponding to the intersection result is multiple shards, the sum of the entity frequency distribution values ​​of the query entities in each intersection shard is calculated, and the intersection shard with the largest sum is set as the first shard visited in the initial query shard routing strategy. The above method prioritizes accessing data shards with a more concentrated distribution of query entities, which is beneficial to increasing the number of intermediate results in the first shard visited, providing a reasonable starting point for subsequent cost optimization.

[0007] As a technical solution of the present invention, the cost optimization module extracts the first and second data shards with adjacent access orders according to the access order of each data shard in the initial query sharding routing strategy, and obtains the boundary relationship edges between the first and second data shards in the sharding boundary association graph. When the boundary relationship edge exists, the edge weight of the boundary relationship edge is extracted as the cross-shard connection cost between the first and second data shards; when the boundary relationship edge does not exist, the cross-shard connection cost is calculated based on the relationship type in the query relationship and the overlap of the entity identifiers of the first and second data shards. Further, the cost optimization module obtains the semantic type label of the query relationship and queries a preset semantic weight mapping table based on the semantic type label to determine the semantic weight value when the first data shard and the second data shard are connected across shards. It obtains the number of intersection elements between the entity identifier set stored in the first data shard and the entity identifier set stored in the second data shard, and determines the entity identifier overlap by the ratio of this number of intersection elements to the total number of elements in the entity identifier set of the first data shard. The entity identifier overlap is weighted by the semantic weight value and its reciprocal is taken to obtain the cross-shard connection cost between the first data shard and the second data shard. The cost optimization module uses the first visited shard of the initial query shard routing strategy as the starting shard of the optimized routing sequence, calculates the cross-shard connection cost between the current starting shard and all other unvisited data shards, selects the unvisited data shard with the smallest cross-shard connection cost as the successor shard of the current starting shard in the optimized routing sequence, updates this successor shard as the new current starting shard, and repeats the selection operation until all data shards are visited, thus obtaining the optimized query shard routing strategy. The above process dynamically selects adjacent shards with lower cross-shard connection costs, reducing cross-node data transmission and connection overhead in distributed queries.

[0008] As a technical solution of the present invention, the dependency tree construction module divides intermediate result sets with the same data shard source identifier into the same source group according to the data shard source identifier corresponding to each intermediate result set, and generates a leaf node of the merged dependency tree for each source group; extracts the subject field of each intermediate result triple in the intermediate result set of each source group, performs deduplication operation on all subject fields to obtain a subject identifier set, and determines the level of each subject in the merged dependency tree according to the number of attribute edges of each subject in the distributed knowledge graph, and merges intermediate result sets of the same level to generate a non-leaf node of the merged dependency tree. Specifically, for each subject in the subject identifier set, the dependency tree construction module queries the total number of attribute edges originating from that subject in each data shard of the distributed knowledge graph, and uses this total number as the attribute edge count for that subject. Subjects are then sorted from largest to smallest based on their attribute edge count. The subject with the highest number of attribute edges at the top is set to the first level, and the subject with the lowest number of attribute edges at the bottom is set to the lowest level. Subjects with the same number of attribute edges are set to the same level. The resulting merged dependency tree reflects the strength of subject associations between intermediate result sets, adapting the merging order to the entity connection density in the knowledge graph and reducing unnecessary intermediate result propagation.

[0009] As a technical solution of the present invention, the result merging module obtains all leaf nodes of the current level of the merging dependency tree, performs a union merging operation on the intermediate result sets corresponding to all leaf nodes, and obtains the hierarchical merging result of the current level. The union merging operation performs deduplication and merging based on the uniqueness of the subject and predicate combination of the intermediate result triples. The hierarchical merging result is passed to the parent node of the current level as the input intermediate result set of the parent node, and an alignment merging operation based on a common subject is performed on the input intermediate result sets from each child node at the parent node to obtain the merging result of the parent node. In the alignment and merging operation, the result merging module obtains the intermediate input result sets passed from each child node of the parent node. It retrieves the subject field of each target triplet in the first intermediate input result set and queries the remaining intermediate input result sets for triples with the same subject field. If a triple with the same subject field exists in any of the remaining intermediate input result sets, the object field of the target triplet is concatenated with the object field of the queried triplet. The subject field is used as the subject of the concatenated triplet, and the predicate field of the target triplet is used as the predicate, generating the merged result triplet for the parent node. If no triple with the same subject field exists in any of the remaining intermediate input result sets, the target triplet is directly passed to the parent node's parent node. This module compresses intermediate results layer by layer from bottom to top according to the merging dependency tree and concatenates object information based on common subject alignment, improving the completeness of the final query results and merging efficiency.

[0010] The technical effects and advantages provided by the present invention in the above technical solution are as follows: In terms of shard routing optimization, the matching results of the query entity in the entity identifier set stored in each data shard are obtained to obtain the entity frequency distribution of the query entity. The data shard with the highest frequency value is selected as the main routing shard of the query entity, and the intersection of the main routing shards of all query entities in the original query statement is taken to form the initial query shard routing strategy. For the first and second data shards with adjacent access order in the initial routing strategy, boundary relationship edges are extracted from the shard boundary association graph. When boundary relationship edges exist, the edge weight is directly used as the cross-shard connection cost. When no boundary relationship edges exist, the semantic weight value is obtained by querying the semantic weight mapping table with the semantic type label of the query relationship, and the entity identifier overlap of the two data shards is calculated. The cross-shard connection cost is obtained by weighting the overlap with the semantic weight value and taking the reciprocal. Then, taking the first visited shard as the starting shard, the shard with the smallest cross-shard connection cost between the current starting shard and the remaining unvisited data shards is repeatedly selected as the successor shard to obtain the optimized query shard routing strategy. The first shard to visit is determined by querying the entity frequency distribution, and the subsequent shard selection is driven by the shard boundary association strength. This ensures that the shard access order is consistent with the data distribution and the actual association between shards, reducing the number of cross-shard connections and the amount of cross-shard data transmission, and reducing the computational overhead of cross-shard connections.

[0011] In terms of intermediate result merging, intermediate result sets with the same source identifier are grouped into the same source group based on the data shard source identifier corresponding to each intermediate result set, and leaf nodes of the merge dependency tree are generated for each source group. The subject field of the intermediate result triples of each source group is extracted and deduplicated to obtain a set of subject identifiers. The subject level is determined based on the number of attribute edges of each subject in the distributed knowledge graph. Subjects with the same number of attribute edges are at the same level. Intermediate result sets at the same level are merged to generate non-leaf nodes, forming a merge dependency tree. During merging, the intermediate result sets are merged layer by layer from the leaf nodes to the root node, and deduplication and merging are performed based on the uniqueness of the subject and predicate combination of the intermediate result triples. For the input intermediate result sets from each child node of the parent node, the target triple subject in the first input intermediate result set is used as the benchmark. Triples with the same subject are queried in the remaining input intermediate result sets. If the same subject exists, the object field is concatenated and the merged result triple is generated. If the same subject does not exist, the target triple is directly passed to the upper level. The merging level is determined by dividing the leaf nodes by the source identifier and the number of subject attribute edges. This allows intermediate results to be merged layer by layer according to the source and subject dependency relationship, avoiding full duplicate comparisons between intermediate results from different sources, reducing the computational and storage requirements of merging intermediate results, and shortening the time to generate the final query results. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.

[0013] Figure 1 This is a schematic diagram of a query optimization system architecture for distributed knowledge graphs; Figure 2 This is a flowchart of the method for merging dependency trees; Figure 3 This is a flowchart of the result merging process based on the merging dependency tree. Detailed Implementation

[0014] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0015] See Figure 1 This invention provides a query optimization system for distributed knowledge graphs, including a syntax parsing module, a route generation module, a cost optimization module, a distribution and execution module, a dependency tree construction module, and a result merging module. The syntax parsing module receives the original query statement and performs syntax parsing to extract query entities and query relationships. The route generation module generates an initial query shard routing strategy based on the entity frequency distribution of query entities in each data shard of the distributed knowledge graph. The cost optimization module determines the cross-shard connection cost between adjacent data shards in the initial query shard routing strategy based on the query relationships and a preset shard boundary association graph, and adjusts the access order of each data shard in the initial query shard routing strategy according to the cross-shard connection cost to obtain an optimized query shard routing strategy. The distribution and execution module distributes subqueries to the corresponding data shards according to the optimized query shard routing strategy and collects the intermediate result sets returned by each data shard after each data shard has executed the subqueries. The dependency tree construction module constructs a merged dependency tree for the intermediate result sets based on the data shard source identifiers corresponding to the intermediate result sets and the subject consistency of the intermediate result triples contained in the intermediate result sets. The root node of the merged dependency tree corresponds to the final query result. The result merging module performs result merging operations on the intermediate result sets layer by layer from the leaf nodes to the root node according to the node hierarchy of the merged dependency tree, generating the final query result of the original query statement.

[0016] In practice, the route generation module obtains the entity identifier set stored in each data shard of the distributed knowledge graph. The metadata management layer of the distributed knowledge graph maintains a mapping relationship between data shard identifiers and entity identifier sets. The route generation module reads this mapping relationship from the metadata management layer to obtain the entity identifier set corresponding to each data shard. The entity identifier set consists of the unique entity identifiers of all entities within the corresponding data shard.

[0017] The route generation module performs a matching operation on each query entity in the original query statement with the entity identifier set of each data shard to determine the entity frequency distribution of the query entity in each data shard. Specifically, the matching operation compares the entity identifier of the query entity with each entity identifier in the entity identifier set one by one. When an entity identifier of the query entity matches an entity identifier in the entity identifier set, the route generation module increments the entity frequency distribution value of the query entity in that data shard by 1. The route generation module performs the above matching operation on each query entity and each data shard to obtain the entity frequency distribution of the query entity in each data shard.

[0018] In some embodiments, the route generation module selects the data shard with the highest frequency value in the entity frequency distribution as the primary route shard for the query entity. For each query entity, the route generation module compares the entity frequency distribution values ​​of the query entity in all data shards and selects the data shard with the highest entity frequency distribution value as the primary route shard for the query entity. When multiple data shards have the same maximum entity frequency distribution value, the route generation module selects the data shard with the smallest lexicographical order of its data shard identifier as the primary route shard for the query entity.

[0019] The route generation module obtains the main route fragment identifiers of all query entities in the original query statement, forming a main route fragment identifier set. The route generation module then performs an intersection operation on the main route fragment identifier set to obtain the intersection result. The intersection result is the data fragment identifier set.

[0020] When the number of shards corresponding to the intersection result is a single shard, the routing generation module sets the unique data shard in the intersection result as the first shard in the initial query shard routing strategy. The routing generation module places the first shard at the beginning of the access sequence. The routing generation module obtains the entity frequency distribution values ​​of all query entities in the first shard. The routing generation module sorts the query entities according to their entity frequency distribution values ​​from largest to smallest, obtaining a query entity sorting sequence. The routing generation module iterates through each query entity in the query entity sorting sequence, obtaining the main routing shard for that query entity. If the main routing shard has not yet appeared in the access sequence, the routing generation module appends the main routing shard to the end of the access sequence. After the traversal, if there are still data shards not yet in the access sequence, the routing generation module appends the remaining data shards to the end of the access sequence according to the lexicographical order of their data shard identifiers. The access sequence forms the initial query shard routing strategy.

[0021] When the number of fragments corresponding to the intersection result is multiple fragments, the route generation module calculates the sum of the entity frequency distribution values ​​of the query entities in each intersection fragment. For one intersection fragment in the intersection result... All queried entities are in data shards The sum of the numerical values ​​of the entity frequency distribution in Calculate using the following formula:

[0022] in, This represents the set of all query entities in the original query statement; Represents a set One of the query entities; This represents a segment of the intersection result; Indicates the query entity In data sharding The numerical values ​​of entity frequency distribution in the data; Indicates data sharding The sum of the entity frequency distribution values ​​of all queried entities.

[0023] The route generation module compares the corresponding intersection fragments. Select The largest intersection shard is used as the first shard in the initial query sharding routing strategy. When multiple intersection shards exist... When all data fragment identifiers have the same maximum value, the routing generation module selects the intersection fragment with the smallest lexicographical order as the first fragment visited. After the first fragment is determined, the access order of data fragments following the first fragment in the initial query fragment routing strategy is arranged according to the lexicographical order of the data fragment identifiers.

[0024] In practice, the cost optimization module reads the access order of each data shard in the initial query sharding routing strategy. The initial query sharding routing strategy, generated by the routing generation module, contains an ordered data shard access sequence. The cost optimization module extracts the first and second data shards, which are adjacent in access order, from the access sequence. The first data shard is positioned before the second data shard in the access sequence, and the first and second data shards are adjacent in the access sequence.

[0025] The cost optimization module retrieves the boundary relationship edges between the first and second data shards in the shard boundary association graph. The shard boundary association graph is pre-constructed by the metadata management layer of the distributed knowledge graph. The graph uses data shard identifiers as nodes and boundary relationship edges generated when cross-shard semantic associations exist between two data shards as edges. Each boundary relationship edge carries an edge weight, representing the historical cost statistics of the cross-shard connection between the two data shards. The cost optimization module locates the first and second data shard nodes in the shard boundary association graph and queries whether a direct boundary relationship edge exists between them.

[0026] In some embodiments, when boundary relationship edges exist, the cost optimization module extracts the edge weights of the boundary relationship edges as the cross-shard connection cost between the first data shard and the second data shard. The cost optimization module reads the edge weights from the edge attributes of the shard boundary association graph and directly determines the edge weights as the cross-shard connection cost between the first data shard and the second data shard, without performing subsequent calculations.

[0027] When no boundary relationship exists, the cost optimization module calculates the cross-shard join cost based on the relationship type in the query relationship and the overlap of entity identifiers between the first and second data shards. The cost optimization module extracts the semantic type tags of the query relationships from the original query statement. The query relationships of the original query statement are extracted by the syntax parsing module, and the semantic type tags of the query relationships are stored in the metadata of the query relationships. The semantic type tags of the query relationships indicate the semantic type to which the query relationship belongs in the distributed knowledge graph. Semantic type tags include one of the following: hierarchical relationship type, attribute relationship type, or association relationship type. The cost optimization module queries a pre-defined semantic weight mapping table based on the semantic type tags of the query relationships.

[0028] A pre-defined semantic weight mapping table stores the mapping relationship between semantic type labels and semantic weight values. The semantic weight mapping table is determined during system initialization based on the average selectivity when the relationships corresponding to the semantic type labels participate in cross-shard joins. A lower average selectivity results in a higher semantic weight value; a higher average selectivity results in a lower semantic weight value. The semantic weight value corresponding to hierarchical relationships is set to 1.5, the semantic weight value corresponding to attribute relationships is set to 0.9, and the semantic weight value corresponding to association relationships is set to 1.0. The cost optimization module reads the corresponding semantic weight value from the pre-defined semantic weight mapping table based on the semantic type label of the query relationship.

[0029] The cost optimization module obtains the entity identifier set stored in the first data shard and the entity identifier set stored in the second data shard. The entity identifier set stored in the first data shard is provided by the metadata management layer of the distributed knowledge graph, and the entity identifier set stored in the second data shard is also provided by the metadata management layer of the distributed knowledge graph. The cost optimization module calculates the number of intersection elements between the entity identifier sets stored in the first and second data shards. The number of intersection elements is calculated as follows: the cost optimization module iterates through each entity identifier in the entity identifier set stored in the first data shard and determines whether that entity identifier exists in the entity identifier set stored in the second data shard. If it exists, the number of intersection elements is incremented by 1. The cost optimization module determines the entity identifier overlap degree as the ratio of the number of intersection elements to the total number of elements in the entity identifier set stored in the first data shard. The value of the entity identifier overlap degree is greater than or equal to 0 and less than or equal to 1.

[0030] The cost optimization module calculates the cross-shard connection cost between the first and second data shards by weighting the entity identifier overlap using semantic weight values ​​and then taking the reciprocal. In the specific calculation, the cross-shard connection cost is determined according to the following formula:

[0031] in, This represents the cost of the cross-shard join between the first and second data shards, where p and q are identifiers of the two different data shards. It is a real number greater than 0; This represents the semantic weight value when performing a cross-shard join between the first and second data shards. Retrieved from the preset semantic weight mapping table. The range of values ​​for is real numbers greater than 0; This indicates the degree of overlap in entity identifiers between the first and second data fragments. The value range of is greater than or equal to 0 and less than or equal to 1. It equals the number of elements in the intersection of the entity identifier set stored in the first data shard and the entity identifier set stored in the second data shard, divided by the total number of elements in the entity identifier set stored in the first data shard.

[0032] The cost optimization module will use the above calculations to obtain... The cost of cross-shard connection between the first and second data shards is used as the cost of cross-shard connection and is stored in the temporary cost record of the cost optimization module for subsequent adjustment of the access order of each data shard in the initial query shard routing strategy.

[0033] In practice, the cost optimization module reads the initial query fragment routing strategy. This initial strategy is an ordered data fragment access sequence generated by the routing generation module, with the first data fragment in the access sequence being the first accessed fragment. The cost optimization module extracts the first accessed fragment from the initial query fragment routing strategy and creates an optimized routing sequence. The cost optimization module adds the first accessed fragment to the optimized routing sequence as its starting fragment and marks it as an accessed data fragment.

[0034] The cost optimization module constructs a set of unvisited data shards. This set consists of the remaining data shard identifiers from all data shard identifiers in the distributed knowledge graph, excluding those already included in the optimized routing sequence. The cost optimization module sets the current starting shard as the most recently added data shard in the optimized routing sequence.

[0035] In some embodiments, the cost optimization module calculates the cross-shard connection cost between the current starting shard and each unvisited data shard in the set of unvisited data shards. For each unvisited data shard in the set of unvisited data shards, the cost optimization module determines whether there is a boundary relationship edge between the current starting shard and the unvisited data shard in the shard boundary association graph. If a boundary relationship edge exists, the cost optimization module extracts the edge weight of the boundary relationship edge as the cross-shard connection cost between the current starting shard and the unvisited data shard. If no boundary relationship edge exists, the cost optimization module calculates the cross-shard connection cost between the current starting shard and the unvisited data shard based on the relationship type in the query relationship and the overlap of the entity identifiers of the current starting shard and the unvisited data shard.

[0036] The cost optimization module compares the cross-shard connection costs between the current starting shard and each unaccessed data shard, and selects the unaccessed data shard with the lowest cross-shard connection cost as the successor shard of the current starting shard. The successor shard is selected according to the following formula:

[0037] in, This indicates the data fragment identifier that represents the current starting fragment. Indicates the current iteration number. A positive integer starting from 1; Indicates the first The data shard set was not accessed during the next iteration. It consists of the remaining data fragment identifiers after removing the data fragment identifiers that have entered the optimized routing sequence from all the data fragment identifiers of the distributed knowledge graph; express A data fragment identifier for an unaccessed data fragment; Indicates the current starting fragment Sharding of unaccessed data The cost of cross-slice connections between them It is a real number greater than 0; Indicates in Selecting from the middle makes The identifier of the unaccessed data fragment that yielded the minimum value; This indicates the data fragment identifier of the selected subsequent fragment.

[0038] The cost optimization module will The corresponding data fragment is added to the end of the optimized routing sequence as the successor fragment to the current starting fragment. The cost optimization module will... The corresponding data shard is marked as an accessed data shard, and... The corresponding data shard is updated to the new current starting shard. The cost optimization module then... Remove from Corresponding data sharding, and the number of iterations. Increase by 1.

[0039] The cost optimization module repeatedly performs cross-shard join cost calculation and subsequent shard selection operations until... This is an empty set. All data shards have been included in the optimized routing sequence. The cost optimization module determines the optimized routing sequence as the optimized query shard routing strategy. The data shard access order included in the optimized query shard routing strategy is used by the distribution and execution module to distribute subqueries to the corresponding data shards.

[0040] In specific implementation, please refer to Figure 2 The dependency tree building module receives intermediate result sets returned by each data shard collected by the distribution and execution module. Each intermediate result set carries a corresponding data shard source identifier, which is a unique identifier for the data shard in the distributed knowledge graph.

[0041] The dependency tree building module groups intermediate result sets with the same data shard source identifier into the same source group based on the data shard source identifier corresponding to each intermediate result set. Specifically, the dependency tree building module iterates through all intermediate result sets, reads the data shard source identifier corresponding to each intermediate result set, and places intermediate result sets with the same data shard source identifier into the same source group. Each source group corresponds to one data shard source identifier.

[0042] The dependency tree building module generates a leaf node for each source group in the merged dependency tree. The leaf node stores all intermediate result sets corresponding to the source group.

[0043] The dependency tree building module extracts the subject field of each intermediate result triple from the intermediate result sets of each source group. Each intermediate result triple contains a subject field, a predicate field, and an object field. The subject field is extracted as follows: the dependency tree building module iterates through each intermediate result set within each source group, reads the subject field from each intermediate result triple, and then summarizes all subject fields from all source groups.

[0044] The dependency tree building module performs deduplication on all subject fields to obtain a set of subject identifiers. The deduplication operation is performed as follows: the dependency tree building module adds all extracted subject fields to the deduplication container one by one. Subject fields that already exist in the deduplication container are not added again. The subject fields that are finally retained in the deduplication container form the set of subject identifiers.

[0045] In some embodiments, the dependency tree construction module determines the level of each subject in the merged dependency tree based on the number of attribute edges of each subject in the subject identifier set in the distributed knowledge graph. For each subject in the subject identifier set, the dependency tree construction module queries the total number of attribute edges originating from that subject in each data shard of the distributed knowledge graph, and uses this total number as the number of attribute edges for that subject in the subject identifier set. The query method is as follows: the dependency tree construction module traverses each data shard in the distributed knowledge graph, retrieves attribute edges originating from that subject in the subject identifier set within each data shard, counts the number of attribute edges, and accumulates the counts of attribute edges obtained from all data shards.

[0046] The total number of attribute edges is calculated using the following formula:

[0047] in, This represents a subject within a set of subject identifiers; Indicates the number of the data fragment. The value range is from 1 to Integers; This represents the total number of data fragments in a distributed knowledge graph. It is a positive integer; Indicates the first In each data shard, the subject The number of attribute edges starting from the origin. It is a non-negative integer; Indicates the subject The total number of attribute edges in a distributed knowledge graph. It is a non-negative integer.

[0048] The dependency tree building module sorts the subjects from largest to smallest based on the number of attribute edges. The subject with the highest number of attribute edges at the first position after sorting is set to the first level. The subject with the lowest number of attribute edges at the end of the sorting is set to the lowest level. When multiple subjects have the same number of attribute edges, these subjects are set to the same level.

[0049] The dependency tree building module merges intermediate result sets at the same level into non-leaf nodes of the merged dependency tree. Specifically, based on the level of each subject in the subject identifier set within the merged dependency tree, the module merges the intermediate result sets corresponding to subjects at the same level into the same non-leaf node. The root node of the resulting merged dependency tree corresponds to the final query result.

[0050] In specific implementation, please refer to Figure 3 The result merging module performs result merging operations layer by layer from the leaf nodes to the root node according to the node hierarchy of the merge dependency tree. The merge dependency tree is constructed by the dependency tree construction module. The leaf nodes of the merge dependency tree correspond to the source groups obtained by the same data shard source identifier. The non-leaf nodes of the merge dependency tree correspond to the intermediate result sets corresponding to the subjects of the same level in the subject identifier set. The root node of the merge dependency tree corresponds to the final query result.

[0051] At the leaf node level, the result merging module retrieves all leaf nodes at the current level. The module then traverses and merges all leaf nodes in the dependency tree, reading the intermediate result set corresponding to each leaf node. The intermediate result set corresponding to each leaf node represents all intermediate result sets within the same source group.

[0052] The result merging module performs a union operation on the intermediate result sets corresponding to all leaf nodes to obtain the hierarchical merge result for the current level. The union operation removes duplicates based on the uniqueness of the subject and predicate combinations of the intermediate result triples. Specifically, the result merging module collects all intermediate result triples from the intermediate result sets corresponding to all leaf nodes and performs deduplication on all intermediate result triples according to the combination of the subject and predicate fields. When two intermediate result triples have the same subject and predicate fields, the result merging module retains only one intermediate result triple and discards the remaining duplicate intermediate result triples. All the retained intermediate result triples after deduplication constitute the hierarchical merge result for the current level.

[0053] The result merging module passes the hierarchical merging results to the parent node of the current level as the parent node's input intermediate result set. The parent node of the current level is a non-leaf node in the merge dependency tree that is one level above the current level. The parent node receives the input intermediate result set from all its child nodes. All child nodes of the parent node include all nodes in the next level below the parent node, and the child nodes are either leaf nodes or non-leaf nodes.

[0054] At the parent node, the result merging module performs an alignment and merging operation based on a common subject on the intermediate input result sets from each child node, obtaining the merged result of the parent node. Specifically, the alignment and merging operation involves the result merging module extracting the intermediate input result sets passed from each child node of the parent node. The result merging module obtains the first intermediate input result set. This first intermediate input result set is the intermediate input result set passed from the first child node among all the child nodes of the parent node, arranged in the order of their positions in the merge dependency tree.

[0055] The result merging module extracts the subject field of each target triplet in the first input intermediate result set. The target triplet is the intermediate result triplet to be processed in the first input intermediate result set. The result merging module iterates through all intermediate result triplets in the first input intermediate result set, and uses each intermediate result triplet as the target triplet in turn.

[0056] For each target triplet, the result merging module searches the remaining intermediate input result sets for triplets whose subject field matches that of the target triplet. The remaining intermediate input result sets are all intermediate input result sets passed from the child nodes of the parent node, excluding the first intermediate input result set. During the query, the result merging module iterates through each intermediate result triplet in the remaining intermediate input result sets, comparing the subject field of the intermediate result triplet with that of the target triplet. If the subject fields are identical, it is determined that a triplet exists that matches the subject field of the target triplet.

[0057] If a triplet with the same subject field as the target triplet exists in the remaining intermediate result set, the result merging module concatenates the object field of the target triplet with the object field of the retrieved triplet. The retrieved triplet is the intermediate result triplet in the remaining intermediate result set that has the same subject field as the target triplet. The concatenation operation determines the merged result triplet of the parent node according to the following formula:

[0058] in, This represents the merged triplet of the parent node; The subject field representing the target triple; The predicate field represents the target triple; The object field representing the target triple; This represents the object field of the triples retrieved by the query; This indicates a string concatenation operation, which will... and The objects of the target triples are concatenated into a single object field, with the object field of the target triple first and the object field of the retrieved triples last.

[0059] The result merging module uses the subject field of the target triplet as the subject of the concatenated triplet and the predicate field of the target triplet as the predicate of the concatenated triplet, generating the merged result triplet of the parent node. The merged result triplet of the parent node consists of a subject field, a predicate field, and a concatenated overall object field.

[0060] If no triple matching the subject field of the target triple exists in the remaining intermediate result sets, the result merging module directly passes the target triple to the parent node's parent node. The passed target triple becomes part of the intermediate result set of the parent node's parent node. The parent node's parent node is the node one level above the parent node in the merge dependency tree.

[0061] The result merging module performs union and alignment merging operations layer by layer from the leaf nodes to the root node of the merge dependency tree. When the result merging module reaches the root node of the merge dependency tree, the merge result at the root node is the final query result of the original query statement.

[0062] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. A query optimization system for distributed knowledge graphs, characterized in that, include: The syntax parsing module performs syntax parsing on the received raw query statement to extract query entities and query relationships; The route generation module generates an initial query shard routing strategy based on the entity frequency distribution of the queried entity in each data shard of the distributed knowledge graph. The cost optimization module determines the cross-shard connection cost between adjacent data shards in the initial query shard routing strategy based on the query relationship and the preset shard boundary association graph, and adjusts the access order of each data shard in the initial query shard routing strategy according to the cross-shard connection cost to obtain the optimized query shard routing strategy. The distribution and execution module distributes subqueries to the corresponding data shards according to the optimized query sharding routing strategy, and collects the intermediate result sets returned by each data shard after each data shard has completed the execution of the subqueries. The dependency tree construction module constructs a merged dependency tree for the intermediate result set based on the data shard source identifier corresponding to the intermediate result set and the subject consistency of the intermediate result triples contained in the intermediate result set. The root node of the merged dependency tree corresponds to the final query result. The result merging module performs result merging operations on the intermediate result sets layer by layer from the leaf nodes to the root node according to the node hierarchy of the merge dependency tree, generating the final query result of the original query statement.

2. The query optimization system for distributed knowledge graphs according to claim 1, characterized in that, The step of generating an initial query shard routing strategy based on the entity frequency distribution of the queried entity in each data shard of the distributed knowledge graph includes: Obtain the entity identifier set stored in each data shard of the distributed knowledge graph, and perform a matching operation between the query entity and the entity identifier set of each data shard to determine the entity frequency distribution of the query entity in each data shard. The data shard with the highest frequency value in the entity frequency distribution is selected as the main routing shard of the query entity. After taking the intersection of the main routing shards of all query entities in the original query statement, the initial query shard routing strategy of the original query statement is generated based on the intersection result.

3. The query optimization system for distributed knowledge graphs according to claim 2, characterized in that, The initial query sharding routing strategy for generating the original query statement based on the intersection result includes: When the number of shards corresponding to the intersection result is a single shard, the single shard is set as the first shard in the initial query shard routing strategy, and the access order of the remaining data shards is arranged in descending order of the entity frequency distribution value of the query entity in the first shard. When the number of shards corresponding to the intersection result is multiple shards, the sum of the entity frequency distribution values ​​of the query entity in each intersection shard is calculated, and the intersection shard with the largest sum is set as the first shard in the initial query shard routing strategy.

4. The query optimization system for distributed knowledge graphs according to claim 1, characterized in that, The step of determining the cross-shard connection cost between adjacent data shards in the initial query sharding routing strategy based on the query relationship and the preset sharding boundary association graph includes: Based on the access order of each data shard in the initial query sharding routing strategy, the first data shard and the second data shard with adjacent access order are extracted in sequence, and the boundary relationship edge between the first data shard and the second data shard in the sharding boundary association graph is obtained. When the boundary relationship edge exists, the edge weight of the boundary relationship edge is extracted as the cross-shard connection cost between the first data shard and the second data shard. When the boundary relationship edge does not exist, the cross-shard connection cost is calculated based on the relationship type in the query relationship and the overlap of entity identifiers between the first data shard and the second data shard.

5. A query optimization system for distributed knowledge graphs according to claim 4, characterized in that, The calculation of the cross-shard join cost based on the relationship type in the query relationship and the overlap of entity identifiers between the first data shard and the second data shard includes: Obtain the semantic type label of the query relationship, and query the preset semantic weight mapping table according to the semantic type label to determine the semantic weight value when the first data shard and the second data shard are connected across shards; The number of intersection elements between the entity identifier set stored in the first data shard and the entity identifier set stored in the second data shard is obtained, and the ratio of the number of intersection elements to the total number of elements in the entity identifier set of the first data shard is determined as the entity identifier overlap. The cross-shard connection cost between the first data shard and the second data shard is obtained by weighting the overlap of the entity identifiers with the semantic weight values ​​and taking the reciprocal.

6. The query optimization system for distributed knowledge graphs according to claim 1, characterized in that, The step of adjusting the access order of each data shard in the initial query shard routing strategy according to the cross-shard connection cost to obtain the optimized query shard routing strategy includes: The first visited fragment of the initial query fragmentation routing strategy is used as the starting fragment of the optimized routing sequence, and the cross-fragment connection cost between the current starting fragment and each of the remaining unvisited data fragments is calculated. The unvisited data fragment with the smallest cross-fragment connection cost is selected as the successor fragment of the current starting fragment in the optimized routing sequence. The successor fragment is then updated to the new current starting fragment. The selection operation is repeated until all data fragments are accessed, thus obtaining the optimized query fragment routing strategy.

7. The query optimization system for distributed knowledge graphs according to claim 1, characterized in that, The step of constructing the merged dependency tree of the intermediate result set based on the data shard source identifier corresponding to the intermediate result set and the subject consistency of the intermediate result triples contained in the intermediate result set includes: Based on the data shard source identifier corresponding to each intermediate result set, intermediate result sets with the same data shard source identifier are divided into the same source group, and a leaf node of the merge dependency tree is generated for each source group. Extract the subject field of each intermediate result triple from the intermediate result set of each source group, perform deduplication on all subject fields to obtain a subject identifier set, and determine the level of each subject in the merge dependency tree according to the number of attribute edges of each subject in the distributed knowledge graph. Merge intermediate result sets of the same level to generate non-leaf nodes of the merge dependency tree.

8. A query optimization system for distributed knowledge graphs according to claim 7, characterized in that, The step of determining the level of each subject in the merged dependency tree according to the number of attribute edges of each subject in the distributed knowledge graph in the subject identifier set includes: For each subject in the subject identifier set, query the total number of attribute edges starting from that subject in each data shard of the distributed knowledge graph, and use the total number as the number of attribute edges for that subject. Sort the subjects according to the number of attribute edges in descending order. Set the subject with the highest number of attribute edges in the first position as the first level, set the subject with the lowest number of attribute edges at the end of the sort as the lowest level, and set subjects with the same number of attribute edges to the same level.

9. A query optimization system for distributed knowledge graphs according to claim 1, characterized in that, The step of performing a result merging operation on the intermediate result set layer by layer from the leaf node to the root node according to the node hierarchy of the merging dependency tree includes: Obtain all leaf nodes of the current level of the merged dependency tree, perform a union operation on the intermediate result set corresponding to all leaf nodes to obtain the level merge result of the current level. The union operation performs deduplication and merging based on the uniqueness of the subject and predicate combination of the intermediate result triples. The hierarchical merging result is passed to the parent node of the current level as the input intermediate result set of the parent node, and an alignment merging operation based on a common subject is performed on the input intermediate result sets from each child node at the parent node to obtain the merging result of the parent node.

10. A query optimization system for distributed knowledge graphs according to claim 9, characterized in that, The step of performing a common-subject-based alignment and merging operation on the intermediate result sets of input from each child node at the parent node includes: Extract the intermediate input result set passed by each child node of the parent node, obtain the subject field of each target triple in the first intermediate input result set, and query the triples that are consistent with the subject field in the remaining intermediate input result sets; When a triplet with the same subject field exists in the remaining intermediate input result set, the object field of the target triplet is concatenated with the object field of the queried triplet, and the subject field is used as the subject of the concatenated triplet, and the predicate field of the target triplet is used as the predicate of the concatenated triplet to generate the merged result triplet of the parent node. If no triple matching the subject field exists in the remaining intermediate input result set, the target triple is directly passed to the parent node of the parent node.