An optimization method, device and equipment of a graph database and a storage medium
By classifying and splitting the operation statements of graph databases, optimizing the operation order and index relationships, the problem of low efficiency in graph database operations is solved, achieving efficient graph database operations and adaptability to different types of underlying databases.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-23
- Publication Date
- 2026-03-31
AI Technical Summary
The low efficiency of graph database operations in existing technologies is mainly due to redundant execution statements, especially as the amount of data increases.
By categorizing the first operation statement of the graph database, the second operation statement is generated and then broken down into multiple sub-operation statements. This allows for operations on different types of underlying databases, optimizing the operation order and index relationships to improve efficiency.
It reduces the workload of graph database and underlying database operations, improves operational efficiency, and enhances the applicability of graph databases, adapting to different types of underlying databases.
Smart Images

Figure CN115712747B_ABST
Abstract
Description
Technical Field
[0001] This article relates to the field of computer technology, and in particular to an optimization method, apparatus, device, and storage medium for graph databases. Background Technology
[0002] With the continuous development of technology, the amount of data stored in databases is constantly increasing, and new types of databases are constantly emerging for data storage. However, while the amount of data stored and the types of databases are constantly increasing, it also brings about the problem of reduced database operation efficiency.
[0003] Existing technologies employ a fusion of graph databases and underlying databases for data manipulation. These operations include adding new data, deleting existing data, modifying existing data, and querying specific data. Data in a graph database comprises nodes and edges. A node is an entity, such as a person, location, transaction, or category, while an edge represents the association between two nodes. When representing many-to-many relationships, graph databases only need to indicate the existence of distinct relationships between two entities, eliminating the need to create a separate association table to record these relationships. This simplifies the data manipulation process, making graph databases widely used in the field of computer technology.
[0004] The existing method for operating graph databases is as follows: First, the graph database receives operation statements; then, based on the data stored in the graph database, it obtains execution statements; finally, the execution statements are converted into operation code for the underlying database integrated into the graph database to complete the operation. As the amount of data in the graph database increases, a large number of redundant execution statements are generated, affecting the efficiency of graph database operations.
[0005] There is an urgent need for an optimization method for graph databases to address the problem of low operational efficiency caused by the large number of redundant execution statements in existing technologies. Summary of the Invention
[0006] To address the issues of long processing times and low efficiency in existing database operations, this paper provides an optimization method, apparatus, device, and storage medium for graph databases. This method removes redundant execution statements, reduces the workload of operating on graph databases, improves operational efficiency, and enables graph databases to automatically adapt to different types of underlying databases, thereby increasing the applicability of graph databases.
[0007] This article provides an optimization method for graph databases, including,
[0008] Obtain the first operation statement of the graph database, wherein the first operation statement includes multiple graph data to be operated on;
[0009] Based on the knowledge of the domain in which the graph data is located, the graph data in the first operation statement is classified to obtain the second operation statement;
[0010] The second operation statement is split into multiple sub-operation statements;
[0011] The sub-operation statement is sent to the underlying database integrated with the graph database to complete the operation on the graph data to be operated.
[0012] This embodiment also provides an optimization device for graph databases, including,
[0013] The first operation statement acquisition unit acquires the first operation statement of the graph database, which includes multiple graph data to be operated on.
[0014] The first operation statement optimization unit classifies the graph data in the first operation statement based on knowledge of the domain in which the graph data is located, and obtains the second operation statement.
[0015] The second operation statement splitting unit splits the second operation statement into multiple sub-operation statements;
[0016] The sub-operation statement issuing unit issues the sub-operation statement to the underlying database integrated with the graph database to complete the operation on the graph data to be operated.
[0017] This embodiment also provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the above-described method.
[0018] This embodiment also provides a computer storage medium on which a computer program is stored, which, when run by the processor of a computer device, executes the above-described method.
[0019] Using the embodiments described herein, the graph data in the first operation statement is categorized to obtain the second operation statement. This eliminates redundant operation statements, reduces the workload of operating the graph database and the underlying database, and improves operational efficiency. The second operation statement is then broken down into multiple sub-operation statements, which are sent to the underlying database integrated with the graph database to complete the operation on the graph data to be operated on. This achieves automatic adaptation to different types of underlying databases, enhancing the applicability of the graph database. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments or prior art described herein, the accompanying drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this article. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 The diagram shown is a structural schematic of an optimization device for a graph database according to an embodiment of this paper.
[0022] Figure 2 The diagram shown is a flowchart of an optimization method for a graph database according to an embodiment of this paper;
[0023] Figure 3 The diagram shown is a detailed structural diagram of an optimization device for a graph database according to an embodiment of this paper.
[0024] Figure 4 The diagram shown is a flowchart of the graphical data classification for the first operation statement in this embodiment.
[0025] Figure 5 The diagram shown is a flowchart of the syntax optimization of the second operation statement in the embodiment of this paper;
[0026] Figure 6 The flowchart shown is a process for optimizing the order of sub-operation statements in an embodiment of this paper;
[0027] Figure 7 The diagram shown is a structural schematic of the computer device in the embodiment of this article.
[0028] [Explanation of Figure Markers]:
[0029] 101. First operation statement acquisition unit;
[0030] 102. First Operation Statement Optimization Unit;
[0031] 103. Second operation statement splitting unit;
[0032] 104. Sub-operation statement issuance unit;
[0033] 301. First operation statement acquisition unit;
[0034] 302. First Operation Statement Optimization Unit;
[0035] 3021. Graph data association calculation module;
[0036] 3022, Graph Data Classification Module;
[0037] 3023. Graph data index relationship establishment module;
[0038] 303. Second operation statement splitting unit;
[0039] 3031. Syntax optimization module;
[0040] 304. Sub-operation statement issuance unit;
[0041] 3041. Sequence Optimization Module;
[0042] 3042. Module for phased distribution;
[0043] 3043, Adaptor Module;
[0044] 3044, Cache module;
[0045] 702. Computer equipment;
[0046] 704. Processing equipment;
[0047] 706. Storage resources;
[0048] 708. Drive mechanism;
[0049] 710. Input / Output Module;
[0050] 712. Input devices;
[0051] 714. Output devices;
[0052] 716. Presentation equipment;
[0053] 718. Graphical User Interface;
[0054] 720. Network interface;
[0055] 722. Communication link;
[0056] 724. Communication bus. Detailed Implementation
[0057] The technical solutions in the embodiments described below will be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments described herein, and not all of them. Based on the embodiments described herein, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this document.
[0058] The graph database described in this embodiment integrates multiple different types of underlying databases. The graph data stored in the graph database includes nodes and edges. A node represents an entity stored in the underlying database and serves as an index parameter for the underlying database. Edges represent the relationships between nodes. Both nodes and edges are stored in the underlying database, and the graph data in the graph database is an abstract reflection of the nodes and edges in the underlying database. When operating on the graph database, the user first issues an operation statement containing the graph data to be operated on. Then, the user searches within the graph data to obtain the nodes or edges that need to be operated on in the underlying database. These nodes or edges are then used as indexes for the underlying database operation.
[0059] In this embodiment, the operation statement issued by the user can be a Gremlin statement, and the underlying database integrated with the graph database can be a MySQL database, a Cassandra database, and / or a Rocksdb database.
[0060] like Figure 1 The diagram shown is a schematic representation of a graph database optimization device according to an embodiment of this paper. The structure of the graph database optimization device is described in this figure, specifically including a first operation statement acquisition unit 101, a first operation statement optimization unit 102, a second operation statement splitting unit 103, and a sub-operation statement issuing unit 104.
[0061] The first operation statement acquisition unit 101 acquires the operation statement issued by the user, which includes multiple graph data to be operated, and uses it as the first operation statement;
[0062] The first operation statement optimization unit 102 classifies the graph data in the first operation statement obtained by the first operation statement acquisition unit 101 based on the knowledge of the domain in which the graph data is located, and obtains the second operation statement.
[0063] The second operation statement splitting unit 103 splits the second operation statement obtained by the first operation statement optimization unit 102 into multiple sub-operation statements.
[0064] The sub-operation statement issuing unit 104 issues multiple sub-operation statements obtained by the second operation statement splitting unit 103 to the underlying database integrated with the graph database, thereby completing the operation on the graph data to be operated.
[0065] like Figure 2 The diagram shows a flowchart of an optimization method for a graph database according to an embodiment of the text. The process of optimizing a graph database is described in this diagram, and the method includes:
[0066] Step 201: Obtain the first operation statement of the graph database, which includes multiple graph data to be operated on;
[0067] Step 202: Based on the knowledge of the domain in which the graph data is located, classify the graph data in the first operation statement to obtain the second operation statement;
[0068] Step 203: Divide the second operation statement into multiple sub-operation statements;
[0069] Step 204: Send the sub-operation statement to the underlying database integrated with the graph database to complete the operation on the graph data to be operated.
[0070] In this embodiment, the graph database is integrated with multiple underlying databases of different types. The graph data stored in the graph database includes nodes and edges, and the underlying database stores the data of the nodes and edges. The first operation statement is an operation statement issued by the user to operate on the graph database, which includes multiple graph data to be operated on. The operation types can include adding new data, deleting existing data, modifying existing data, and querying specified data in the underlying database. The domain knowledge of the graph data refers to the common knowledge of the domain in which the entities represented by the nodes in the graph data belong. For example, if the graph data is A Wine Group, then the domain of the graph data is wine. Assuming that it is known from the knowledge of the wine domain, A Wine Group is also called A Wine, and its stock code is 001002. The sub-operation statements include the operation syntax of the graph data, that is, the indexing method of the underlying database. For example, the syntax of sub-operation statement 1 is: find the nodes associated with graph node A and get the node list. The syntax of sub-operation statement 2 is: find node B from the node list. The sub-operation statements are issued to the underlying database integrated with the graph data to complete the operation on the graph data to be operated on.
[0071] The method described in this embodiment categorizes the graph data in the first operation statement based on knowledge of the domain in which the graph data resides, resulting in a second operation statement. This eliminates redundant operation statements, reduces the workload of operating the graph database and the underlying database, and improves operational efficiency. The second operation statement is further divided into multiple sub-operation statements, which are then sent to the underlying database integrated with the graph database to complete the operation on the graph data to be manipulated. This enables the graph database to automatically adapt to different types of underlying databases, enhancing its applicability.
[0072] According to one embodiment of this document, in order to remove redundant operation statements, step 202 further includes classifying the graph data in the first operation statement according to the knowledge of the domain in which the graph data is located, to obtain the second operation statement. This further includes determining the correlation between the graph data in the first operation statement according to the knowledge of the domain in which the graph data is located; classifying the graph data with the same correlation to obtain the second operation statement.
[0073] In this step, the graph data includes graph nodes and edges. The knowledge of the domain in which the graph data resides is common knowledge in the domain of the entities represented by the nodes in the graph data. Based on the knowledge of the domain in which the graph data resides, the relationships between the graph data in the first operation statement can be cooperative relationships, competitive relationships, parent-child relationships, or some graph data can represent the same meaning. Graph data with the same relationships in the first operation statement are categorized to obtain the second operation statement. For example, the first operation statement: "Find liquors that compete with Group A, stock code 001002, A liquor, and Group B liquor." The graph nodes in this first operation statement include Group A, stock code 001002, A liquor, and Group B liquor. These nodes all belong to the liquor industry. Assuming, based on knowledge of the liquor industry, the relationships between Group A and stock code 001002 (meaning they represent the same thing), Group A and A liquor (meaning the same thing), and stock code 001002 and A liquor (meaning the same thing), and Group A and Group B liquor (competing), then the graph nodes Group A, stock code 001002, and A liquor are classified as Group A liquor. Therefore, the second operation statement obtained through this classification method is: "Find liquors that compete with Group A and Group B liquor." By classifying the graph data in the first operation statement, redundant graph data is removed, thus eliminating redundant operation statements, reducing the workload of operating the graph database and the underlying database, and improving operational efficiency.
[0074] According to one embodiment of this document, step 203, which involves splitting the second operation statement into multiple sub-operation statements, further includes splitting the second operation statement into multiple sub-operation statements according to the syntax of the second operation statement.
[0075] In this step, the syntax of the second operation statement obtained in step 202 is the indexing method of the graph data in the underlying database. In simpler terms, it's how to manipulate the graph data in the second operation statement to achieve its purpose. For example, if the second operation statement obtained in step 202 is: "Find wines that compete with Group A and Group B," then the syntax of the second operation statement is: "Find wines that compete with Group A, obtain wine list 1, and then find wines that compete with Group B from wine list 1." Based on the above syntax, the second operation statement is broken down into two sub-operation statements: Sub-operation statement 1: Find wines that compete with Group A, obtain wine list 1. Sub-operation statement 2: Find wines that compete with Group B from wine list 1.
[0076] According to one embodiment of this document, in order to quickly locate target data, before splitting the second operation statement into multiple sub-operation statements according to the syntax of the second operation statement, the method further includes optimizing the syntax of the second operation statement according to the index relationship of the graph data in the graph database.
[0077] In this step, the graph data stored in the graph database includes nodes and edges. Both nodes and edges are stored in an underlying database integrated with the graph database. The underlying database contains a large amount of data, and traversing it to obtain the target data takes a long time. To address this issue, this step optimizes the syntax of the second operation statement obtained in step 202 based on the indexing relationships of the graph data in the graph database.
[0078] The index relationship represents the connection between graph data, such as competitive relationships, cooperative relationships, etc. However, the index relationship described here is not an edge in the graph database. Although edges in the graph database also represent the relationship between graph nodes, edges are data stored by the user in the underlying database. For example, nodes that have a competitive relationship with node A are stored in the underlying database. The competitive relationship is an edge in the graph database, and the competitive relationship is a data table in the underlying database. The members of this data table are nodes such as A.
[0079] According to one embodiment of this document, before obtaining the first operation statement of the graph database, the method further includes determining the relationship between the graph data in the graph database based on knowledge of the domain in which the graph data in the graph database resides; and using the relationship as an index relationship of the graph data in the graph database.
[0080] In this step, the knowledge of the domain in which the graph data in the graph database resides is common knowledge in the domain of the entities represented by the nodes in the graph data. Based on this knowledge, the relationships between the graph data in the graph database are determined. These relationships include, but are not limited to, cooperative relationships, competitive relationships, and parent-child relationships. These relationships are used as index relationships for the graph data in the graph database.
[0081] For example, the graph nodes in the graph database include Automotive Group A, Automotive Group B, and Automotive Group C, and the edges in the graph database include cooperative and competitive relationships. Assume that the underlying database's cooperative relationship table stores graph nodes including Automotive Group A and Automotive Group B, and the underlying database's competitive relationship table stores graph nodes including Automotive Group B and Automotive Group C. Assume that based on the knowledge of the domains of these graph nodes, the relationship between graph nodes Automotive Group B and Automotive Group C is competitive, and the relationship between Automotive Group A and Automotive Group B is cooperative. Then, the resulting index relationship includes both cooperative and competitive relationships. If the second operation statement is to find companies that have a cooperative relationship with Automotive Group B, then the syntax of this statement is: first, find the edges of graph node Automotive Group B to obtain an edge list; then, find the cooperative relationship edge in the edge list; finally, obtain the graph node Automotive Group A that has a cooperative relationship with graph node Automotive Group B through the cooperative relationship edge. Using the above index relationship, the syntax of the second operation statement can be optimized to: first, find the edges between graph node Automotive Group B and graph node Automotive Group A to obtain an edge list; then, check if the cooperative relationship edge exists in the edge list; if it exists, directly return graph node Automotive Group A. The second operation statement, optimized using index relationships, becomes: "Find whether there is a cooperative relationship between graph node B Automobile Group and A Automobile Group." If the underlying database stores a large number of edges for B Automobile Group, traversing the database to find these edges would be time-consuming. Furthermore, finding the cooperative relationship edge from a large number of edges would still be time-consuming. Finally, graph nodes must be extracted from this cooperative relationship edge, resulting in low efficiency in locating the target data. Optimizing the second operation statement using index relationships simplifies the query by requiring only a query to determine if there is a cooperative relationship between B Automobile Group and A Automobile Group. Therefore, by pre-establishing index relationships for graph data in the graph database and optimizing the second operation statement using these index relationships, the speed of locating the target data is accelerated.
[0082] According to one embodiment of this article, in order to improve the operational efficiency of sub-operation statements, after step 203 splits the second operation statement into multiple sub-operation statements, it further includes optimizing the operation order of the sub-operation statements according to the data structure of the graph data in the graph database.
[0083] In this step, the graph data is stored in the graph database in a tree structure, which includes child nodes and parent nodes. The tree structure has the following characteristics: each node has zero or more child nodes; a node without a parent node is called the root node; each non-root node has one and only one parent node; except for the root node, each child node can be divided into multiple disjoint subtrees. The operation order of sub-operation statements is optimized based on the tree structure.
[0084] According to one embodiment of this document, optimizing the operation order of the sub-operation statements based on the data structure of the graph database further includes: obtaining the dependencies between the graph data of the sub-operation statements based on the data structure of the graph data in the graph database; and adjusting the operation order of the sub-operation statements based on the dependencies between the graph data of the sub-operation statements.
[0085] In this step, the graph data in the sub-operation statements can be child nodes or parent nodes in the tree structure. A single graph data point may have multiple parent nodes. Therefore, the dependencies between sub-operation statements can be determined based on the tree structure of the graph database (dependencies exist between parent and child nodes, but not between root nodes). The operation order of the sub-operation statements is then adjusted according to these dependencies. For example, the sub-operation statement whose root node is the first is executed, followed by the sub-operation statements whose child nodes are also root nodes. Adjusting the operation order of the sub-operation statements based on these dependencies improves their operational efficiency.
[0086] According to one embodiment of this document, adjusting the operation order of the sub-operation statements based on the dependencies between the graph data of the sub-operation statements further includes: executing sub-operation statements that have no dependencies between the graph data in parallel; and adjusting the operation order of the sub-operation statements that have dependencies based on the operation speed of the sub-operation statements and the dependencies.
[0087] In this step, for graph data without dependencies (i.e., all graph data are root nodes in the tree structure), sub-operation statements for these graph data can be executed in parallel to improve operational efficiency. For graph data with dependencies (i.e., graph data are both parent and child nodes in the tree structure), the order of sub-operation statements is adjusted according to their operation speed and dependencies, prioritizing sub-operation statements where the graph data is a parent node and the operation speed is faster, thus improving operational efficiency.
[0088] According to one embodiment of this document, before adjusting the operation order of the dependent sub-operation statements based on their operation speed and dependencies, the method further includes: obtaining the number of parent nodes and child nodes of the graph data of the sub-operation statement in the tree data structure of the graph data in the graph database; and estimating the operation speed of the sub-operation statement based on the number of parent nodes and child nodes.
[0089] In this step, the more parent nodes the graph data in the sub-operation statement has in the tree structure, the more database tables need to be traversed, and the slower the execution speed of such sub-operation statements will be. This allows us to estimate the operation speed of each sub-operation statement.
[0090] By using the above method, the sub-operation statements that are fast and have no dependencies are executed in parallel first, and then the sub-operation statements that are slow and require operations based on dependencies are executed. This improves the efficiency of sub-operation statements compared to executing all sub-operation statements sequentially.
[0091] According to one embodiment of this document, in order to ensure that a large number of operation statements will not cause the underlying database to crash, step 204 of sending the sub-operation statements to the underlying database integrated with the graph database further includes: determining the number of operation statements that the underlying database can execute simultaneously based on the performance of the underlying database; and sending the sub-operation statements to the underlying database integrated with the graph database in batches according to the number.
[0092] Different underlying databases support different numbers of concurrent CRUD (Create, Read, Update, Delete) statements. If this number exceeds the maximum number of statements the underlying database can execute simultaneously, the database may crash. To address this issue, this step first determines the number of statements the underlying database can execute concurrently based on its performance. This number can be obtained by referring to the underlying database's operation manual. Then, based on this number, the sub-operation statements are distributed to the underlying database in batches. This ensures the normal operation of the underlying database.
[0093] According to one embodiment of this article, the operation codes of different underlying databases are also different. In order to adapt to different types of underlying databases, step 204, which sends the sub-operation statement to the underlying database that is integrated with the graph database, further includes converting the sub-operation statement into the operation code corresponding to the underlying database according to the type of the underlying database that is integrated with the graph database.
[0094] In this step, the query library and query syntax for the underlying database are pre-stored. The pre-stored query library and query syntax can include, but are not limited to, MySQL, SQL Server, Oracle, PostgreSQL, SQLite, SQLiteCassandra, HBase, MongoDB, RocksDB, and Redis. By using the pre-stored query library and query syntax, adaptation to different underlying databases is achieved.
[0095] According to one embodiment of this article, when there is frequent access to certain graph data, in order to improve the efficiency of operations on such graph data, after step 204 sends the sub-operation statement to the underlying database integrated with the graph database, it further includes caching the data returned by the underlying database when the sub-operation statement queries the underlying database, so as to respond to other query operations.
[0096] In graph database applications, certain hot data often emerges, with a large number of users frequently querying this data. In this step, when querying the underlying database, the data returned by each underlying database is cached in a fixed-size cache space according to the query time. When the cached data reaches its limit, the cached data is deleted in chronological order until the cache space occupancy reaches the user-defined value. Therefore, when the same data is queried frequently, that data remains continuously stored in the cache space. When other operations need to query the underlying database, the cached data is returned, simplifying the query process and improving operational efficiency.
[0097] like Figure 3 The figure shown is a detailed structural diagram of a graph database optimization device according to an embodiment of the present invention. The detailed structure of the graph database optimization device is specifically described in this figure, including a first operation statement acquisition unit 301, a first operation statement optimization unit 302, a second operation statement splitting unit 303, and a sub-operation statement issuing unit 304.
[0098] According to one embodiment of this document, the first operation statement acquisition unit 301 acquires the user's operation statement for the graph database, which includes multiple graph data to be operated on, wherein the graph data to be operated on includes graph nodes and / or edges. In this embodiment, the first operation statement can be a Gremlin statement. For example, to query the node associated with node A and named B, the Gremlin statement is gV('A').both().has('name','B').
[0099] According to one embodiment of this document, the first operation statement optimization unit 302 further includes a graph data association calculation module 3021, used to calculate the association relationships between graph data in the first operation statement or between graph data in the graph database. The association relationships between graph data are calculated based on knowledge of the domain in which the graph data resides. In this embodiment, the knowledge of the domain in which the graph data resides refers to common knowledge in the domain of the entities represented by the graph nodes in the graph data. Based on this knowledge, the obtained association relationships between the graph data can be cooperative relationships, competitive relationships, parent-child relationships, or some graph data representing the same meaning, etc. The graph data is then categorized or an index relationship is established between the graph data based on the association relationships.
[0100] According to one embodiment of this document, the first operation statement optimization unit 302 further includes a graph data classification module 3022. Based on the graph data association relationship calculation module 3021, the graph data with the same association relationship in the first operation statement are classified to obtain the second operation statement. In this embodiment, graph data representing the same meaning can be classified, thereby removing redundant graph data in the first operation statement, thus removing redundant operation statements, reducing the workload of operating graph data, and improving operation efficiency.
[0101] According to one embodiment of this document, the first operation statement optimization unit 302 further includes a graph data index relationship establishment module 3023, which uses the relationships between graph data in the graph database calculated by the graph data association relationship calculation module 3021 as the index relationships of the graph data in the graph database.
[0102] According to one embodiment of this document, the second operation statement splitting unit 303 further includes a syntax optimization module 3031, which optimizes the syntax of the second operation statement based on the index relationship established by the graph data index relationship establishment module 3023. The syntax refers to the indexing method of the graph data in the underlying database; simply put, it's how to operate on the graph data in the second operation statement to achieve the purpose of the second operation statement. For example, if the underlying database stores data for graph nodes A (wine group) and B (wine group), and the second operation statement is: "Find wines that compete with wine group A," then the syntax of the second operation statement is: First, find all edges of wine group A to obtain an edge list; then, find the edge representing competition in the edge list; finally, if the edge representing competition exists, find the node connected to this edge, thus obtaining the graph node representing competition with wine group A as wine group B. If the graph data index relationship establishment module 3023 has pre-established an index relationship between graph nodes A (wine group) and B (wine group) that is a competitive relationship, then the syntax of the optimized second operation statement based on the competitive relationship is as follows: First, find the edges between A and B to obtain an edge list. Then, check if there is a competitive edge in the edge list. If it exists, the graph node that competes with A is directly identified as B. When the underlying database stores a large number of edges for A, traversing the database to find the edges for A takes a long time, and finding the competitive edge from a large number of edges also takes a long time. Finally, the graph node must be extracted from the competitive edge, resulting in low efficiency in locating the target data. After optimizing the syntax of the second operation statement through the index relationship, it is only necessary to query whether there is a competitive edge between A and B, shortening the query time and achieving rapid location of the target data.
[0103] According to one embodiment of this document, the sub-operation statement issuing unit 304 further includes a sequence optimization module 3041, which optimizes the operation order of sub-operation statements based on the tree data structure of the graph database. The tree data structure includes parent nodes and child nodes. First, the dependencies between graph data in the sub-operation statements are determined based on the tree data structure. For example, if a sub-operation statement whose graph data belongs to a child node needs to be executed after a sub-operation statement whose graph data belongs to its parent node, then there is a dependency between these sub-operation statements. Nodes without parent nodes are called root nodes, and there is no dependency between root nodes. Then, sub-operation statements without dependencies are operated in parallel, and the operation order of sub-operation statements with dependencies is adjusted based on the operation speed of the sub-operation statements and the dependencies, thereby improving the operation efficiency of the sub-operation statements.
[0104] Based on the tree data structure, the number of parent nodes and child nodes of the graph data of the sub-operation statement in the tree data structure is obtained. The more parent nodes of the graph data in the sub-operation statement in the tree structure, the more database tables need to be traversed, and the slower the execution speed of such sub-operation statements. Thus, the operation speed of each sub-operation statement can be estimated.
[0105] According to one embodiment of this document, the sub-operation statement distribution unit 304 further includes a batch distribution module 3042, which determines the number of operation statements that the underlying database can execute simultaneously based on the performance of the underlying database; and distributes the sub-operation statements optimized by the sequence optimization module 3041 in batches to the underlying database fused with the graph data according to the number of sub-operation statements. Even if there are a large number of operation statements, the underlying database will not crash, thus ensuring the normal operation of the underlying database.
[0106] According to one embodiment of this document, the sub-operation statement issuing unit 304 further includes an adaptation module 3043, which pre-stores the query library and query syntax of the underlying database according to the type of the underlying database, and converts the sub-operation statements of the batch issuing module 3042 that adjust the batch into operation codes corresponding to the underlying database according to the query library and query syntax, and issues them to the underlying database to complete the operation on the underlying database.
[0107] According to one embodiment of this document, the sub-operation statement issuing unit 304 further includes a caching module 3044. When querying the underlying database, the module caches the data returned by each underlying database in the order of query time into a fixed-size cache space. When the cached data reaches the upper limit of the cache space, the cached data is deleted in chronological order until the cache space occupancy rate reaches the user-defined value. Therefore, when the same data is queried frequently, that data is continuously stored in the cache space. When other operation statements need to query the underlying database, the cached data is returned, simplifying the query process and improving operational efficiency.
[0108] like Figure 4 The diagram shows a flowchart of the graph data classification for the first operation statement in this embodiment. This diagram describes the process of classifying the graph data in the first operation statement to obtain the second operation statement, specifically including:
[0109] Step 401: Based on the knowledge of the domain in which the graph data in the first operation statement is located, determine the association relationship between multiple graph data in the first operation statement.
[0110] In this step, the knowledge in the domain in which the graph data is located is common knowledge in that domain. Based on the common knowledge in that domain, the relationships between the graph data can be determined to include cooperative relationships, competitive relationships, parent-child relationships, or relationships that represent the same meaning, etc.
[0111] Step 402: Classify the graph data with the same association relationship to obtain the second operation statement.
[0112] In this step, based on the association obtained in step 401, graph data with the same association are grouped into one graph data. For example, in your first operation statement, the graph data A Wine Group, stock code 001002, and A Wine all belong to the wine industry. According to common knowledge in the wine industry, A Wine Group, stock code 001002, and A Wine represent the same meaning. Therefore, these three graph nodes are grouped into A Wine Group, resulting in the second operation statement, which removes redundant graph data from the first operation statement.
[0113] pass Figure 4 The described method removes redundant graph data from the first operation statement, reduces the workload of manipulating graph data, and improves operation efficiency.
[0114] like Figure 5 The diagram shows a flowchart of the syntax optimization for the second operation statement in this embodiment. The flowchart describes the process of optimizing the syntax of the second operation statement, specifically including:
[0115] Step 501: Determine the relationships between graph data based on the knowledge of the domain in which the graph data in the graph database resides.
[0116] In this step, the knowledge of the domain in which the graph data in the graph database is located is the common knowledge of the domain. The relationships between the graph data can be determined based on the common knowledge of the domain, including cooperative relationships, competitive relationships, parent-child relationships, etc.
[0117] Step 502: Use the connection as an index relationship for the graph data.
[0118] In this step, the connection obtained in step 501 is used as the index relationship of the graph data. However, the index relationship mentioned here is not an edge in the graph database. Although the edge in the graph database also represents the relationship between graph nodes, the edge is data stored by the user in the underlying database. For example, the node that has a competitive relationship with node A is stored in the underlying database. The competitive relationship is an edge in the graph database, and the competitive relationship is a data table in the underlying database. The member of the data table is node A, etc.
[0119] Step 503: Optimize the syntax of the second operation statement based on the index relationship.
[0120] pass Figure 5 The described method optimizes the syntax of the second operation statement, thus speeding up the location of target data.
[0121] like Figure 6 The diagram shows a flowchart illustrating the process of optimizing the order of sub-operation statements in an embodiment of this paper. The flowchart describes the process of optimizing the order of sub-operation statements, specifically including:
[0122] Step 601: Based on the tree data structure of the graph database, obtain the dependencies between the graph data of the sub-operation statements;
[0123] In this step, the tree-like data structure of the graph database includes parent nodes and child nodes. In the graph database, a graph data may have multiple parent nodes. For example, a sub-operation statement that includes a child node depends on a sub-operation statement that includes its parent node. The sub-operation statement that the graph data is the parent node needs to be executed first, and then the sub-operation statement that the graph data is the child node under that parent node needs to be executed.
[0124] Step 602: Determine if there are dependencies between sub-operation statements;
[0125] In this step, if a node has no parent node, then that node is the root node. There are no dependencies between root nodes. Furthermore, each child node can be divided into multiple disjoint subtrees, and there are no dependencies between the subtrees. Dependencies exist between parent and child nodes.
[0126] Step 603: Execute sub-operation statements that have no dependencies between graph data in parallel;
[0127] In this step, if the graph data of some sub-operation statements does not have dependencies in the graph database, these sub-operation statements can be executed in parallel to improve the efficiency of the sub-operation statements.
[0128] Step 604: Estimate the operation speed of sub-operation statements based on the tree data structure of the graph database;
[0129] In this step, if there are dependencies between the graph data of some sub-operation statements, these sub-operation statements need to be executed according to the dependencies. However, the operation speed of the sub-operation statements can be estimated based on the tree data structure of the graph database, so as to make further adjustments to the execution order of these dependent sub-operation statements.
[0130] The more parent nodes the graph data in the sub-operation statement has in the tree structure, the more database tables need to be traversed, and the slower the execution speed of such sub-operation statements will be. This allows us to estimate the operation speed of each sub-operation statement.
[0131] Step 605: Adjust the order of operations of sub-operation statements based on speed and dependencies.
[0132] In this step, sub-operation statements that use graph data as parent nodes and have fast operation speeds are executed first to improve operational efficiency.
[0133] pass Figure 6 The described method adjusts the order of sub-operation statements based on the dependencies of graph data in the graph database, thereby improving operational efficiency.
[0134] like Figure 7The diagram illustrates the structure of a computer device according to an embodiment of this document. The graph database optimization device described herein can be the computer device in this embodiment, executing the methods described above. The computer device 702 may include one or more processing devices 704, such as one or more central processing units (CPUs), each of which can implement one or more hardware threads. The computer device 702 may also include any storage resource 706 for storing information of any kind, such as code, settings, data, etc. Without limitation, for example, the storage resource 706 may include any one or more combinations of the following: any type of RAM, any type of ROM, flash memory, hard disk, optical disk, etc. More generally, any storage resource can use any technology to store information. Furthermore, any storage resource can provide volatile or non-volatile retention of information. Further, any storage resource may represent a fixed or removable component of the computer device 702. In one case, when the processing device 704 executes associated instructions stored in any storage resource or combination of storage resources, the computer device 702 can perform any operation of the associated instructions. The computer device 702 also includes one or more drive mechanisms 708 for interacting with any storage resource, such as a hard disk drive mechanism, an optical disk drive mechanism, etc.
[0135] Computer device 702 may also include an input / output module 710 (I / O) for receiving various inputs (via input device 712) and providing various outputs (via output device 714). A specific output mechanism may include a presentation device 716 and an associated graphical user interface (GUI) 718. In other embodiments, the input / output module 710 (I / O), input device 712, and output device 714 may be omitted, and the device may function solely as a computer device within a network. Computer device 702 may also include one or more network interfaces 720 for exchanging data with other devices via one or more communication links 722. One or more communication buses 724 couple the components described above together.
[0136] Communication link 722 can be implemented in any way, such as via a local area network, a wide area network (e.g., the Internet), a point-to-point connection, or any combination thereof. Communication link 722 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc., governed by any protocol or combination of protocols.
[0137] This embodiment also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps:
[0138] Obtain the first operation statement of the graph database, wherein the first operation statement includes multiple graph data to be operated on;
[0139] Based on the knowledge of the domain in which the graph data is located, the graph data in the first operation statement is classified to obtain the second operation statement;
[0140] The second operation statement is split into multiple sub-operation statements;
[0141] The sub-operation statement is sent to the underlying database integrated with the graph database to complete the operation on the graph data to be operated.
[0142] Corresponding to Figure 2 , Figures 4-6 In addition to the methods described above, this embodiment also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the above-described methods.
[0143] This embodiment also provides a computer-readable instruction, wherein when a processor executes the instruction, the program therein causes the processor to perform the following: Figure 2 , Figures 4-6 The method shown.
[0144] It should be understood that in the various embodiments of this document, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this document.
[0145] It should also be understood that, in the embodiments herein, the term "and / or" is merely a description of the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following associated objects have an "or" relationship.
[0146] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this document.
[0147] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0148] In the embodiments provided herein, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through some interfaces, devices, or units, or they may be electrical, mechanical, or other forms of connection.
[0149] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments described herein, depending on actual needs.
[0150] Furthermore, the functional units in the various embodiments of this document can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0151] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this paper, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this paper. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0152] This document uses specific embodiments to illustrate the principles and implementation methods of this document. The descriptions of the embodiments above are only for the purpose of helping to understand the methods and core ideas of this document. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this document. Therefore, the content of this specification should not be construed as a limitation of this document.
Claims
1. An optimization method of a graph database, characterized in that, The method comprises, obtaining a first operation statement of a graph database, the first operation statement comprising a plurality of graph data to be operated; classifying the graph data in the first operation statement according to the knowledge of the field where the graph data is located, to obtain a second operation statement; splitting the second operation statement into a plurality of sub-operation statements; issuing the sub-operation statements to a bottom database fused with the graph database to complete the operation on the graph data to be operated, the graph database being fused with a plurality of different types of bottom databases; issuing the sub-operation statements to a bottom database fused with the graph database further comprises, converting the sub-operation statements into operation codes corresponding to the bottom database according to the type of the bottom database fused with the graph database.
2. The method for optimizing a graph database of claim 1, wherein, The classification of the graph data in the first operation statement according to the knowledge of the field where the graph data is located to obtain a second operation statement further comprises, determining the association relationship between a plurality of graph data in the first operation statement according to the knowledge of the field where the graph data is located; classifying the graph data with the same association relationship to obtain the second operation statement.
3. The method of optimizing a graph database of claim 1, wherein, The splitting of the second operation statement into a plurality of sub-operation statements further comprises, splitting the second operation statement into a plurality of sub-operation statements according to the syntax of the second operation statement.
4. The method of optimizing a graph database of claim 3, wherein, Before splitting the second operation statement into a plurality of sub-operation statements according to the syntax of the second operation statement, further comprising, optimizing the syntax of the second operation statement according to the index relationship of the graph data in the graph database, the index relationship being the association between the graph data, the association including cooperative relationship, competitive relationship, parent-child relationship.
5. The method of optimizing a graph database of claim 4, wherein, Before obtaining the first operation statement of the graph database, further comprising, determining the association between the graph data in the graph database according to the knowledge of the field where the graph data in the graph database is located; taking the association as the index relationship of the graph data in the graph database.
6. The method of optimizing a graph database of claim 1, wherein, After splitting the second operation statement into a plurality of sub-operation statements, further comprising, optimizing the operation order of the sub-operation statements according to the data structure of the graph data in the graph database.
7. The method of optimizing a graph database of claim 6, wherein, Optimizing the operation order of the sub-operation statements according to the data structure in the graph database further comprises, obtaining the dependency relationship between the graph data of the sub-operation statements according to the data structure of the graph data in the graph database; adjusting the operation order of the sub-operation statements according to the dependency relationship between the graph data of the sub-operation statements.
8. The method of optimizing a graph database of claim 7, wherein, Adjusting the operation order of the sub-operation statements according to the dependency relationship between the graph data of the sub-operation statements further comprises, parallelly executing the sub-operation statements without dependency relationship between the graph data; adjusting the operation order of the sub-operation statements with the dependency relationship according to the operation speed of the sub-operation statements and the dependency relationship.
9. The method of optimizing a graph database of claim 8, wherein, Before adjusting the operation order of the sub-operation statements with the dependency relationship according to the operation speed of the sub-operation statements and the dependency relationship, further comprising, According to a tree data structure of graph data in the graph database, a number of child nodes and parent nodes of the graph data of the sub-operation statement in the tree data structure is obtained; According to the number of child nodes and parent nodes, an operation speed of the sub-operation statement is estimated.
10. The method of optimizing a graph database of claim 1, wherein, Further comprising, According to a performance of the underlying database, a number of operation statements simultaneously executed by the underlying database is determined; The sub-operation statement is batched according to the number and issued to the underlying database fused with the graph database.
11. The method of optimizing a graph database of claim 1, wherein, Further comprising, When the sub-operation statement queries the underlying database, data returned by the underlying database is cached to facilitate responding to other query operations.
12. An optimization apparatus of a graph database, characterized by, Further comprising, A first operation statement obtaining unit obtains a first operation statement of a graph database, the first operation statement including a plurality of graph data to be operated; A first operation statement optimization unit classifies the graph data in the first operation statement according to knowledge of a field in which the graph data is located, to obtain a second operation statement; A second operation statement splitting unit splits the second operation statement into a plurality of sub-operation statements; A sub-operation statement issuing unit issues the sub-operation statement to an underlying database fused with the graph database, to complete operation on the graph data to be operated, the graph database being fused with a plurality of underlying databases of different types; Further comprising, According to a type of the underlying database fused with the graph database, the sub-operation statement is converted into operation code corresponding to the underlying database.
13. A computer device comprising a memory, a processor, and a computer program stored on the memory, wherein the computer program comprises instructions that, when executed by the processor, cause the processor to perform the method of any one of claims 1-12. The computer program is run by the processor, and instructions of the method according to any one of claims 1-11 are executed.
14. A computer storage medium having stored thereon a computer program, characterized in that The computer program is run by the processor of the computer device, and instructions of the method according to any one of claims 1-11 are executed.
Citation Information
Patent Citations
Data cleaning method and device based on knowledge base graph matching
CN109063048A
Efficiently committing large transactions in a graph database
US9465832B1