Single-point query method and device based on distributed graph database

By directly generating the current physical plan using the physical plan cache in the graph database, skipping the logical plan generation and physical plan conversion steps, the problem of low single-point query performance in the existing technology is solved, and query performance and QPS are significantly improved.

CN119807237APending Publication Date: 2025-04-11SICHUAN SHUTIANMENGTU DATA TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411936819.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

In the prior art, the internal optimizer workflow of graph databases is complex, and the time-consuming proportion of logical plan generation and physical plan conversion is too high, resulting in a low query per second (QPS) of single-point queries.

Method used

By determining whether there are available physical plans in the physical plan cache that matches the physical plan parameters of the statement to be queried, when there is a matching available physical plan, it is determined as a physical plan template, and the core query parameters in the physical plan template are replaced with the parameters to be queried for the statement to be queried, directly generate the current physical plan, skipping the steps of logical plan generation and physical plan conversion.

Benefits of technology

This greatly improves the single-point query performance of graph databases, and solves the problem of low single-point query QPS caused by excessive time-consuming generation of logical plan and physical plan conversion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807237A_ABST
    Figure CN119807237A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of databases, and provides a single-point query method and device based on a distributed graph database. The method comprises the steps of determining a physical plan parameter corresponding to a to-be-queried statement; judging whether an available physical plan matched with the physical plan parameter exists in a physical plan cache or not; when the matched available physical plan exists, determining the available physical plan as a physical plan template; obtaining a to-be-queried parameter of the to-be-queried statement; replacing a core query parameter in the physical plan template with the to-be-queried parameter to obtain a current physical plan; and executing the current physical plan to obtain a single-point query result of the to-be-queried statement. According to the method, the current physical plan is directly generated by utilizing the physical plan cache, so that the problem that the query rate per second of single-point query is relatively low due to the fact that the time consumption proportion of logic plan generation and physical plan conversion is too high in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a single-point query method and device based on a distributed graph database. Background Art

[0002] Graph databases are used to store and manage highly connected data. In graph databases, entities are abstracted as vertices, and the relationships between entities are represented by edges (i.e., the connecting lines between vertices). This structured model allows data relationships and connections to be presented in a natural way, which can effectively reflect the complex connections in the real world.

[0003] Single-point query refers to querying a specific data point in the database. Single-point query is the most basic and important function of a database. In actual business scenarios, analytical operations such as tracing, tracing causes, deduction, induction, and transmission often cannot be separated from starting from one or more data points. Therefore, databases often have high requirements for single-point query performance. When performing single-point queries in a graph database, one or more conditions are usually specified to accurately locate a record in the graph database that meets the conditions. The optimizer of the graph database aims to minimize query execution time and resource consumption, and formulates the optimal logical plan and physical plan for the query statement submitted by the user for subsequent execution; among them, the logical plan refers to: the calculation method and flow direction of data during query; the physical plan refers to: based on the logical plan, according to the distribution of devices and data, specify a plan to perform specific computing operations on a certain device.

[0004] The quality of the optimizer algorithm directly determines the execution efficiency of the query statement. However, in the prior art, the internal optimizer workflow of the map database is complex, and the time consumption of logical plan generation and physical plan conversion is too high, resulting in a single-point query statement that may take tens of milliseconds to return the query result, resulting in a low query rate per second (Queries Per Second, abbreviated as QPS) for single-point queries; among them, QPS is a measure of the number of query requests that a specific service can handle per unit time. And when using a third-party external optimizer, the logical plan of a single-point query must go through multiple network interactions to be generated, which greatly reduces the performance of the single-point query, resulting in a further reduction in the single-point query QPS.

[0005] In view of this, overcoming the defects of the prior art is an urgent problem to be solved in the field of this technology. Summary of the invention

[0006] The technical problem to be solved by the present invention is to provide a single-point query method and device based on a distributed graph database, the purpose of which is to directly generate the current physical plan by using the matching available physical plan in the physical plan cache, skipping the steps of logical plan generation and converting the logical plan into a physical plan, thereby greatly improving the single-point query performance of the graph database, and solving the problem of low QPS of single-point query due to the high proportion of time consumed in logical plan generation and physical plan conversion in the prior art.

[0007] The present invention adopts the following technical solution:

[0008] In a first aspect, the present invention provides a single-point query method based on a distributed graph database, comprising:

[0009] Determine the physical plan parameters corresponding to the query statement to be queried;

[0010] Determine whether there is an available physical plan matching the physical plan parameters in the physical plan cache; when there is an available physical plan matching, determine the available physical plan as a physical plan template;

[0011] Obtaining the query parameters of the query statement; replacing the core query parameters in the physical plan template with the query parameters to obtain the current physical plan;

[0012] The current physical plan is executed to obtain a single-point query result of the query statement.

[0013] Furthermore, the physical plan parameters include the name of the to-be-queried graph and the converted statement of the to-be-queried statement;

[0014] Determining the physical plan parameters corresponding to the query statement includes:

[0015] Based on the abstract syntax tree of the query statement, determining whether the query statement is a single-point query statement;

[0016] When the statement to be queried is a single-point query statement, the graph name to be queried and the converted statement are obtained based on the abstract syntax tree to generate the physical plan parameters.

[0017] Further, judging whether the query statement is a single-point query statement based on the abstract syntax tree of the query statement includes:

[0018] Determine an abstract syntax tree corresponding to the query statement;

[0019] Traversing the abstract syntax tree, when a Where expression is matched in the abstract syntax tree, determining whether the nodes constituting the Where expression only constitute the first predicate expression and the second predicate expression; wherein the abstract syntax tree includes at least one node;

[0020] When the nodes constituting the Where expression only constitute the first predicate expression and the second predicate expression, obtaining a unique identifier corresponding to the graph name to be queried in the abstract syntax tree, so as to determine whether the attribute key in the second predicate expression is a primary key column according to the unique identifier;

[0021] When the attribute key is the primary key column, the query statement to be queried is a single-point query statement.

[0022] Further, the determining the abstract syntax tree corresponding to the query statement includes:

[0023] Using the query statement as a unique keyword, searching in the syntax tree cache whether there is a parsed syntax tree corresponding to the query statement;

[0024] If there is no corresponding parsed syntax tree in the syntax tree cache, perform syntax parsing, abstract syntax tree rewriting and syntax checking on the query statement to obtain a corresponding abstract syntax tree, and store the obtained abstract syntax tree in the syntax tree cache;

[0025] If there is a corresponding parsed syntax tree in the syntax tree cache, the parsed syntax tree is determined as the abstract syntax tree.

[0026] Further, the obtaining of the query parameters of the query statement; replacing the core query parameters in the physical plan template with the query parameters to obtain the current physical plan includes:

[0027] The core query parameters are replaced with a tag name and a primary key value; wherein the parameters to be queried include the tag name and the primary key value, the tag name is extracted from the first predicate expression, and the primary key value is extracted from the second predicate expression;

[0028] The replaced physical plan template and the parameters to be queried are used as the current physical plan, so that when the current physical plan is executed, values ​​corresponding to corresponding parameters are obtained according to the parameters to be queried.

[0029] Furthermore, when the query statement is a single-point query statement, obtaining the query graph name and the converted statement based on the abstract syntax tree to generate the physical plan parameters includes:

[0030] Extracting the to-be-queried parameters from the abstract syntax tree, and generating a converted statement based on the to-be-queried parameters; acquiring the to-be-queried graph name from the abstract syntax tree; and generating a cache query parameter using the to-be-queried graph name and the converted statement;

[0031] Using the cache query parameter as a unique keyword, searching in the query result cache whether there is a query result corresponding to the cache query parameter;

[0032] When there is a query result corresponding to the cache query parameter in the query result cache, the corresponding query result is obtained from the query result cache, so as to directly determine the obtained query result as the single-point query result;

[0033] When there is no query result corresponding to the cached query parameter in the query result cache, the graph name to be queried and the converted statement are determined as the physical plan parameters.

[0034] Further, the physical plan parameters include a metadata version number;

[0035] Before determining whether there is an available physical plan matching the physical plan parameters in the physical plan cache, the method further includes:

[0036] Get the metadata version number of the required query from the local cache;

[0037] Determine whether the metadata version number to be queried matches the metadata version number of the physical plan cache;

[0038] When the metadata version number of the required query does not match the metadata version number of the physical plan cache, all available physical plans in the physical plan cache are cleared.

[0039] Furthermore, when the life cycle of a session object ends, all data in the cache space of the session object is cleared.

[0040] In a second aspect, the present invention further provides a single-point query device based on a distributed graph database, comprising:

[0041] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor to execute the single-point query method based on a distributed graph database described in the first aspect.

[0042] In a third aspect, the present invention further provides a non-volatile computer storage medium, wherein the computer storage medium stores computer executable instructions, which are executed by one or more processors to complete the single-point query method based on a distributed graph database described in the first aspect.

[0043] In a fourth aspect, a computer program product comprising instructions is provided, which, when executed on a computer or a processor, enables the computer or the processor to execute a single-point query method based on a distributed graph database as described in the first to third aspects and any one of the aspects.

[0044] In the fifth aspect, the present invention also provides a single-point query system, including the single-point query device based on the distributed graph database as in the second aspect, and using the single-point query method based on the distributed graph database as described in the first aspect to complete the interaction of the single-point query device based on the distributed graph database of the second aspect.

[0045] Different from the prior art, the present invention has at least the following beneficial effects:

[0046] The present invention determines whether there is an available physical plan in the physical plan cache that matches the physical plan parameters of the statement to be queried. When there is an available physical plan that matches, it is determined as a physical plan template, and the core query parameters in the physical plan template are replaced with the parameters to be queried of the statement to be queried to obtain the current physical plan; finally, the current physical plan is executed to obtain a single-point query result of the statement to be queried. Among them, when there is an available physical plan that matches in the physical plan cache, the corresponding available physical plan can be directly obtained, and the current physical plan is directly generated by replacing the core query parameters, thereby skipping the steps of generating the logical plan and converting the logical plan into the physical plan, thereby greatly improving the single-point query performance of the graph database, and solving the problem of low QPS of single-point query due to the high proportion of time consumed in the logical plan generation and physical plan conversion in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0048] Figure 1 It is a flow chart of a single-point query method based on a distributed graph database provided by an embodiment of the present invention;

[0049] Figure 2 is a flow chart of step 10 provided in an embodiment of the present invention;

[0050] Figure 3 is a schematic diagram of a specific example of an abstract syntax tree provided by an embodiment of the present invention;

[0051] Figure 4 It is a schematic diagram of an execution process of a query statement provided by an embodiment of the present invention;

[0052] Figure 5 is a flowchart of step 101 provided in an embodiment of the present invention;

[0053] Figure 6 is a flowchart of step 201 provided by an embodiment of the present invention;

[0054] Figure 7 is a flow chart of step 102 provided in an embodiment of the present invention;

[0055] Figure 8 is a flow chart of step 20 provided in an embodiment of the present invention;

[0056] Fig. 9 is a flow chart of step 30 provided in an embodiment of the present invention;

[0057] Fig.10 It is a schematic diagram of the architecture of a single-point query device based on a distributed graph database provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0058] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0059] Unless the context requires otherwise, throughout the specification and claims, the term "including" is to be interpreted as open inclusion, that is, "including, but not limited to". In the description of the specification, the terms "one embodiment", "some embodiments", "exemplary embodiments", "examples", "specific examples" or "some examples" and the like are intended to indicate that specific features, structures, materials or characteristics associated with the embodiment or example are included in at least one embodiment or example of the present disclosure. The schematic representation of the above terms does not necessarily refer to the same embodiment or example. In addition, the specific features, structures, materials or characteristics may be included in any one or more embodiments or examples in any appropriate manner, that is, although they may be carried in the embodiments or examples of the above terms due to reasons such as the order and position of appearance, it is not limited to that they can be carried in combination by one embodiment or example.

[0060] In the description of the present invention, it is necessary to understand that the terms "center", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present disclosure and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present disclosure.

[0061] In the description of the present invention, the terms "first" and "second" are used only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present disclosure, unless otherwise specified, the meaning of "multiple" is two or more. In addition, for example, the same type of nouns may be described as two independent individuals by adding "A" and "B" at the end. In this case, the corresponding features defined as "A" and "B" are only used to distinguish the same type of individuals for description purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features.

[0062] When describing some embodiments, the expressions "coupling", "coupling" and "connection" and their derivatives may be used. For example, when describing some embodiments, the term "connection" may be used to indicate that two or more components are in direct physical or electrical contact with each other. For another example, when describing some embodiments, the term "coupling" may be used to indicate that two or more components are in direct physical or electrical contact. However, the terms "connection" or "coupling" may also refer to two or more components that are not in direct contact with each other, but still cooperate or interact with each other, such as "optical path coupling", "wireless connection", etc. The embodiments disclosed herein are not necessarily limited to the contents of the present invention.

[0063] In the description of the present invention, the expression "A and / or B" (where A and B are used to formally represent specific characteristic contents) will be involved, and the corresponding expressions include the following three combinations: only A, only B, and a combination of A and B.

[0064] As used herein, "about," "substantially," or "approximately" includes the stated value and an average value that is within an acceptable range of deviation from the particular value as determined by one of ordinary skill in the art taking into account the measurements in question and the errors associated with the measurement of the particular quantity (i.e., the limitations of the measurement system).

[0065] Embodiment 1:

[0066] In order to solve the above problems, the embodiment of the present invention provides a single-point query method based on a distributed graph database, such as Figure 1 Specifically, it includes:

[0067] Step 10: Determine the physical plan parameters corresponding to the query statement.

[0068] The query statement to be queried is a query statement submitted by a user; in an optional embodiment, the query statement to be queried may use the cypher query language.

[0069] The embodiment of the present invention provides a physical plan cache for storing available physical plans, wherein the available physical plans are physical plans generated and / or executed historically. Physical plan parameters are obtained according to a query statement, and the physical plan parameters are relevant parameters required when querying whether there is a matching available physical plan in the physical plan cache.

[0070] Step 20: Determine whether there is an available physical plan in the physical plan cache that matches the physical plan parameters; when there is an available physical plan that matches, determine the available physical plan as a physical plan template.

[0071] Step 30: Obtain the query parameters of the query statement; replace the core query parameters in the physical plan template with the query parameters to obtain the current physical plan.

[0072] The core query parameters refer to: the key fields and / or parameter values ​​to be queried; for example, the operators, keywords, corresponding operands or parameter values ​​in the query statement. In the query statement, the core query parameters and the corresponding parameters to be queried need to be consistent; in an optional embodiment, the core query parameters and the corresponding parameters to be queried can be primary key values ​​and tag names. The core query parameters are replaced with the parameters to be queried to generate the current physical plan. The process of generating the current physical plan will be further described below.

[0073] Step 40: Execute the current physical plan to obtain a single-point query result of the query statement.

[0074] The present invention determines whether there is an available physical plan in the physical plan cache that matches the physical plan parameters of the statement to be queried. When there is an available physical plan that matches, it is determined as a physical plan template, and the core query parameters in the physical plan template are replaced with the parameters to be queried of the statement to be queried to obtain the current physical plan; finally, the current physical plan is executed to obtain a single-point query result of the statement to be queried. Among them, when there is an available physical plan that matches in the physical plan cache, the corresponding available physical plan can be directly obtained, and the current physical plan is directly generated by replacing the core query parameters, thereby skipping the steps of generating the logical plan and converting the logical plan into the physical plan, thereby greatly improving the single-point query performance of the graph database, and solving the problem of low QPS of single-point query due to the high proportion of time consumed in the logical plan generation and physical plan conversion in the prior art.

[0075] The embodiment of the present invention introduces a multi-level cache mechanism to optimize the query performance of the graph database, and sets three levels of cache: the first level is the syntax tree cache, the second level is the query result cache, and the third level is the physical plan cache. Each layer of cache has its specific functions and advantages to ensure the efficiency and scalability of the query process. The single-point query method based on the distributed graph database of the embodiment of the present invention is specifically described below in combination with the multi-level cache:

[0076] In an optional embodiment, the physical plan parameters include the name of the to-be-queried graph and the converted statement of the to-be-queried statement; Figure 2 As shown, in step 10, determining the physical plan parameters corresponding to the query statement includes:

[0077] Step 101: Based on the abstract syntax tree of the query statement, determine whether the query statement is a single-point query statement.

[0078] The Abstract Syntax Tree (AST) represents the syntax structure of the source code of the query statement in a tree-like form. Each node on the AST represents a structure in the source code. For example, Figure 3 The figure shows a specific example of an abstract syntax tree when the query statement uses the cypher query language. Each operator or keyword in the query statement is a node on the abstract syntax tree, and the corresponding operand or parameter becomes its child node. The process of determining whether the query statement is a single-point query statement based on the abstract syntax tree will be described below.

[0079] Step 102: When the query statement is a single-point query statement, the query graph name and the converted statement are obtained based on the abstract syntax tree to generate the physical plan parameters.

[0080] The execution process of a query statement is as follows: Figure 4 As shown, the query plan includes a logical plan and a physical plan. In the process of generating the query plan, it is necessary to generate the logical plan and convert the logical plan into a physical plan; finally, after obtaining the current physical plan, the executor executes the current physical plan to obtain the query result. The embodiments of the present invention respectively focus on the process of generating an abstract syntax tree, generating a logical plan and a physical plan, and obtaining a query result, and use the corresponding data cached in the three-level cache to directly obtain the abstract syntax tree, the logical plan, the physical plan and the query result, so as to achieve the purpose of improving the query performance. The following is a specific description:

[0081] In order to first explain the process of judging a single-point query statement, Figure 5 As shown, in step 101, judging whether the query statement is a single-point query statement based on the abstract syntax tree of the query statement includes:

[0082] Step 201: Determine the abstract syntax tree corresponding to the query statement.

[0083] Step 202: traverse the abstract syntax tree, and when a Where expression is matched in the abstract syntax tree, determine whether the nodes constituting the Where expression only constitute the first predicate expression and the second predicate expression; wherein the abstract syntax tree includes at least one node.

[0084] The specific types of the first predicate expression and the second predicate expression are selected by those skilled in the art according to the query language used by the query statement to be queried. In an optional embodiment, the first predicate expression may be a HasLabel expression, and the second predicate expression may be an Equals expression. In an optional embodiment, the abstract syntax tree may be traversed from the root node of the abstract syntax tree from top to bottom until each leaf node of the abstract syntax tree is checked to complete the traversal of the abstract syntax tree.

[0085] In one embodiment, when the query statement uses the cypher query language, since information such as the primary key value and the tag name are usually included in the Where expression of the Match column, the embodiment of the present invention determines whether the query statement is a single-point query statement by judging the predicate expression constituting the Where expression.

[0086] In the abstract syntax tree of the query statement, the contents contained in multiple nodes together constitute a Where expression. When the Where expression is matched in its abstract syntax tree, it is determined whether the Where expression contains only two predicate expressions, and the two predicate expressions are HasLabel expression and Equals expression; that is, since the entire Where clause (that is, Where expression) spans multiple nodes in the abstract syntax tree, when the abstract syntax tree contains a Where expression, for the predicate expressions contained therein, it is determined whether the types of the predicate expressions are only HasLabel expression and Equals expression.

[0087] Step 203: When the nodes constituting the Where expression only constitute the first predicate expression and the second predicate expression, obtain the unique identifier corresponding to the graph name to be queried in the abstract syntax tree, so as to determine whether the attribute key in the second predicate expression is the primary key column according to the unique identifier.

[0088] For example, when the first predicate expression is a HasLabel expression and the second predicate expression is an Equals expression, for the query statement "Match(n:Person{id:1001})return n", its Where expression contains only two predicate expressions: one is a HasLabel expression, which contains label-related information; the other is an Equals expression, which contains the property key and the corresponding value; the LabelName expression contained in the HasLabel expression corresponds to the Person string, and the PropertyKey expression in the Equals expression corresponds to the id string. Therefore, the types of predicate expressions in the Where expression of the query statement are only HasLabel expression and Equals expression. Then, obtain the unique identifier "id" corresponding to the name of the graph to be queried. Since the property key in the Equals expression is "id", it is the primary key column.

[0089] Step 204: When the attribute key is the primary key column, the query statement to be queried is a single-point query statement.

[0090] For example, the PropertyKey expression in the Equals expression (ie, the property key in the second predicate expression) corresponds to the id string, and id is the primary key column corresponding to the graph name to be queried in the abstract syntax tree.

[0091] When the query statement is not a single-point query statement, the conventional query process should be followed, the standard query logic should be executed, and the subsequent optimization steps should be skipped to avoid unnecessary complexity; among them, the conventional query process is selected by technical personnel in this field according to the specific usage scenario and their own experience, and is not limited here.

[0092] To illustrate the process of using the syntax tree cache, Figure 6 As shown, in step 201, determining the abstract syntax tree corresponding to the query statement includes:

[0093] Step 301: using the query statement as a unique keyword, searching in a syntax tree cache whether there is a parsed syntax tree corresponding to the query statement.

[0094] When receiving a query statement, the query statement is used as a unique key to traverse the syntax tree cache, and a full match cache search is performed therein to determine whether there is a parsed syntax tree that matches the syntax structure of the query statement among the historically generated parsed syntax trees; the purpose of this is to confirm whether there is a parsed result of the query statement in the syntax tree cache. In an optional embodiment, an efficient hash algorithm can be used to quickly locate a matching parsed syntax tree to ensure query efficiency.

[0095] Step 302: If there is no corresponding parsed syntax tree in the syntax tree cache, perform syntax parsing, abstract syntax tree rewriting and syntax checking on the query statement to obtain a corresponding abstract syntax tree, and store the obtained abstract syntax tree in the syntax tree cache.

[0096] If the search fails, it means that there is no corresponding parsed syntax tree in the syntax tree cache; at this time, a new abstract syntax tree is generated based on the query statement. In one embodiment, the parser first decomposes the query statement into different grammatical components, identifies keywords, identifiers and operators, and then establishes the nodes of the syntax tree; each node will contain relevant information, such as node type, sub-node relationship and semantic information, and finally forms a complete abstract syntax tree for subsequent query optimization and execution. When a new abstract syntax tree is generated, it is stored in the syntax tree cache so that it can be quickly accessed for subsequent identical queries.

[0097] Step 303: If there is a corresponding parsed syntax tree in the syntax tree cache, the parsed syntax tree is determined as the abstract syntax tree.

[0098] When a parsed syntax tree is hit in the syntax tree cache, a series of abstract syntax tree generation operations can be skipped, including syntax parsing, abstract syntax tree rewriting, and syntax checking. Since repeated syntax parsing processes are reduced, performance can be significantly improved in high-frequency query scenarios.

[0099] To illustrate the process of using the query result cache, Figure 7 As shown, in step 102, when the query statement is a single-point query statement, obtaining the query graph name and the converted statement based on the abstract syntax tree to generate the physical plan parameters includes:

[0100] Step 401: extract the parameters to be queried from the abstract syntax tree, and generate a converted statement based on the parameters to be queried; obtain the graph name to be queried from the abstract syntax tree; and generate a cache query parameter using the graph name to be queried and the converted statement.

[0101] The generation process of the converted statement will be described in detail below. In an optional embodiment, the cache query parameters may include: data version number, the name of the graph to be queried and the converted statement, as well as other related parameters required when searching in the query result cache.

[0102] Since a single-point query usually only involves a specific record in a graph database, an embodiment of the present invention extracts core query parameters by analyzing an abstract syntax tree. For example, the core query parameters may be primary key values ​​and label names. After extraction, the query statement is converted into an optimized form for a single-point query to obtain a converted statement to improve execution efficiency. Since the query statement is subjected to analysis and inspection steps such as syntax parsing to obtain an abstract syntax tree, the name of the graph to be queried is obtained directly from the abstract syntax tree.

[0103] The data version number is obtained from the storage in real time each time a query is made, and is used to track changes in the data version. When it is detected that the queried data version number does not match the data version number in the current query result cache, all data in the query result cache is immediately cleared to ensure the real-time and correctness of the query results in the query result cache. Although the data version number is queried from the storage in real time, due to its very small message size (for example, only 8 bytes can be used to transmit the data version number), this overhead is negligible compared to the actual query process, thereby ensuring the efficiency of the cache mechanism.

[0104] Step 402: Using the cache query parameter as a unique keyword, searching in the query result cache whether there is a query result corresponding to the cache query parameter.

[0105] In order to ensure the accuracy and consistency of the cache, a set of serialized parameters (i.e., cache query parameters) is used as a unique key to find out whether there is a corresponding query result in the query result cache, so that the previous query result can be directly returned when the same query exists, avoiding re-executing the query. Serialization refers to the process of converting a data structure or object into a format that can be stored and / or transmitted. In this embodiment, the process of integrating parameters such as the name of the graph to be queried and the converted statement into cache query parameters is serialization.

[0106] Step 403: when there is a query result corresponding to the cache query parameter in the query result cache, the corresponding query result is obtained from the query result cache, so as to directly determine the obtained query result as the single-point query result.

[0107] When a hit query result exists in the query result cache, the query result is directly returned as a single-point query result of the query statement to be queried, without the need for further query processing, thereby significantly reducing query response time and resource consumption; by reducing the number of direct accesses to the graph database, the overall query performance is improved.

[0108] Step 404: When there is no query result corresponding to the cached query parameter in the query result cache, the to-be-queried graph name and the converted statement are determined as the physical plan parameters.

[0109] When there is no hit in the query result cache, the only option is to query in the graph database to obtain the query result. At this time, the current physical plan needs to be determined to guide the specific method of this query. Therefore, the graph name to be queried and the converted statement are determined as physical plan parameters to facilitate the subsequent determination of the current physical plan.

[0110] In this embodiment, for the application scenario of single-point query of distributed graph database, the entire multi-level cache mechanism is maintained based on session objects; wherein, session is a technology for maintaining user status information in multiple request and response cycles, which allows the server to remember user (i.e., client) data between multiple page visits, and the session object is used to store the attributes and configuration information required by a specific user in multiple request and response cycles, and the multiple request and response cycles are the life cycle of the session object. In the cache of the embodiment of the present invention, each session object has an independent cache space, and when the life cycle of a session object ends, all data in the cache space of the session object is cleared. Although this session-private cache mechanism has relatively large memory overhead, it can effectively avoid competition in high-concurrency scenarios, and avoid lock contention and synchronization overhead.

[0111] When there is no hit in the query result cache, a specific identifier is added to the query parameters of the current session corresponding to the query statement to indicate that the results obtained by this query should be cached. The setting of the identifier not only helps the system track the status of this query in subsequent operations, but also ensures that the relevant results can be cached for future calls. After executing the current physical plan and obtaining the single-point query result of the query statement, it also includes: when there is an identifier in the query parameters of the current session, it is determined that the query result needs to be added to the query result cache, and cached for future fast access.

[0112] The following describes the process of determining the current physical plan:

[0113] In an optional embodiment, the physical plan parameters include a metadata version number; Figure 8 As shown, before determining whether there is an available physical plan matching the physical plan parameters in the physical plan cache in step 20, the method further includes:

[0114] Step 501: Obtain the metadata version number required for query from the local cache.

[0115] Step 502: Determine whether the metadata version number to be queried matches the metadata version number of the physical plan cache.

[0116] Step 503: When the metadata version number to be queried does not match the metadata version number of the physical plan cache, all available physical plans in the physical plan cache are cleared.

[0117] This cache is more stable than the query result cache. The physical plan cache uses a set of serialized information as the unique key. The physical plan parameters include: metadata version number, the name of the graph to be queried, and the converted statement. Unlike the data version number, the metadata version number is mainly read from the local cache instead of being obtained from the storage system in real time. Therefore, the cleanup and refresh of the physical plan cache is only triggered when the metadata version number changes, which makes the third-level cache more stable because the frequency of metadata changes is much lower than that of business data changes.

[0118] The embodiment of the present invention uses the physical plan parameters to query in the physical plan cache to determine whether there is an available physical plan matching the physical plan parameters in the physical plan cache; when there is an available physical plan matching, the available physical plan is determined as a physical plan template, and the core query parameters in the physical plan are replaced with the parameters to be queried, so as to prepare to execute the actual query.

[0119] In an optional embodiment, the query statements with the same meaning but different expressions can also be classified so as to use the same physical plan template; wherein, the specific method of classifying the query statements with the same meaning but different expressions is selected by those skilled in the art according to the specific usage scenario and is not limited here; for example, an intelligent recognition algorithm can be selected, combined with the grammar of the cypher query language, to perform semantic analysis on multiple query statements to obtain query statements with the same meaning but different expressions. For example: Query statement 1 is "Match(n:Person{id:1001})returnn;", and query statement 2 is "Match(n:Person)where n.id=1001return n;"; although these two query statements are written differently, they both express the same query meaning. When processing the above two forms of statements, they are uniformly processed according to the second query statement.

[0120] After getting the physical plan template, such as Fig. 9 As shown, in step 30, the obtaining of the query parameters of the query statement; replacing the core query parameters in the physical plan template with the query parameters to obtain the current physical plan includes:

[0121] Step 601: Replace the core query parameters with a tag name and a primary key value; wherein the parameters to be queried include the tag name and the primary key value, the tag name is extracted from the first predicate expression, and the primary key value is extracted from the second predicate expression.

[0122] The following is an explanation of the generation process of query parameters:

[0123] The single-point query with parameters in the prior art only supports the input of primary key parameters. In order to enhance the function, the embodiment of the present invention extracts the label name together. In addition, in the process of generating the converted statement, the label name is taken into consideration when rewriting the abstract syntax tree to support the label parameters. In this way, the same physical plan template can be used for different labels in the future.

[0124] For example, for the query statement "Match(n:Person{id:1001})return n", the LabelName expression contained in the HasLabel expression corresponds to the Person string, the PropertyKey expression in the Equals expression corresponds to the id string, and the literal expression corresponds to the value 1001.

[0125] In the abstract syntax tree of the query statement, the label name "Person" is extracted from the LabelName expression, and the primary key value "1001" is extracted from the Equals expression.

[0126] For ease of understanding, the generation process of the converted statement is described below: the abstract syntax tree corresponding to the part of the query statement is rewritten to make it a parameterized query statement, that is, the converted statement: "Match(n:$LabelName{id:$id})return n;", in one embodiment, the query parameter is "{LabelName:Person,id:1001}", where "$LabelName" is used to obtain the label name and "$id" is used to obtain the primary key value; and the query parameter is bound to the current session.

[0127] Step 602: The replaced physical plan template and the parameters to be queried are used as the current physical plan, so that when the current physical plan is executed, values ​​corresponding to corresponding parameters are obtained according to the parameters to be queried.

[0128] When executing the current physical plan, the value corresponding to the corresponding parameter is obtained according to the parameter to be queried. For example, when the parameter to be queried is LabelName, the corresponding value is Person; when the parameter to be queried is id, the corresponding value is the literal 1001.

[0129] After determining whether there is an available physical plan matching the physical plan parameters in the physical plan cache, when there is no available physical plan matching, the method further includes:

[0130] When the statement to be queried is a single-point query statement, index information involved in the statement to be queried is obtained; at least one logical plan is generated according to the abstract syntax tree and metadata of the statement to be queried; the optimal logical plan is selected from the at least one logical plan based on the index information; and the current physical plan is generated based on the physical execution order and method of the query operation in the selected logical plan.

[0131] In the process of generating the logical plan for a single-point query, the traditional plan generation process can be greatly simplified, specifically by ignoring complex links such as rewriting the logical plan, calculating the cost of the logical plan, and selecting the optimal step for the logical plan. Compared with complex queries, the goal of a single-point query is clearer. Since the query path is usually unique and efficient (such as direct access through an index), it is only necessary to query the index-related information to generate an index plan. Therefore, in this process, we only need to obtain the index plan based on the existing index information and then generate the corresponding physical plan without the need for conventional logical optimization and cost estimation. Index-related information is usually continuously updated and managed by an asynchronous maintenance thread, so when performing a query, interaction with the storage system can be completely avoided, and there is no additional network overhead.

[0132] Specifically, the abstract syntax tree is first rewritten to convert it into an executable semantic analysis form to ensure that the rewritten abstract syntax tree meets the execution requirements and lays the foundation for subsequent syntax checking and logical plan generation; then a syntax check is performed, including a check on the legality of the variable name. If any error is found, the executed step is immediately returned upward to prevent subsequent steps from being processed based on incorrect syntax; then the expression of the abstract syntax tree is rewritten twice to convert it into a structure that is easier for the planner to operate. This rewriting makes the subsequent logical plan generation more efficient and accurate; then a secondary syntax check is performed, including variable collection and internal renaming, to ensure that all variables can be correctly referenced when generating the logical plan to avoid naming conflicts and potential execution errors; when generating the logical plan, if the statement is a simple statement (such as a single-point query statement or a single-point insert statement), steps such as cost calculation and logical plan rewriting are omitted to speed up processing; when generating the current physical plan, the logical plan tree is traversed through the stack and converted into the corresponding physical plan. After successful generation, the current physical plan will be cached in memory for subsequent quick access and use to ensure efficient query execution, while maximizing the use of the cache mechanism to improve overall system performance;

[0133] When executing the current physical plan and obtaining the single-point query result of the query statement to be queried, the variables of each operator are initialized first. In order to improve efficiency, the variables that have been initialized will be excluded from this step, which can avoid repeated operations and save time and resources; then the various request parameters are packaged into a format suitable for network transmission and serialized into binary data.

[0134] Among them, since the core calculation expression of the physical plan in a single-point query is the label name and the primary key value, when executing the actual query, the query request parameters are encapsulated according to the process. The request parameters include the name of the figure to be queried (the data type of the name to be queried can be a string), the label name (the data type of the label name can be a string), and the primary key value (the data type of the primary key value can be a string or an integer, etc.). Among them, the label name and the primary key obtain the corresponding values ​​through the parameters to be queried of the current session. In addition to the parameters to be queried, other variables, such as the physical plan id, signal channel, and request parameter objects, directly reuse the parameters contained in the current physical plan, avoiding repeated memory requests.

[0135] The corresponding storage node is calculated based on the primary key, and the request data is sent to the storage system, and the query result is obtained after sending. In this process, the fields carried in the request message (such as primary keys and tags) do not need to participate in deserialization because they have been clearly identified during the query process; deserialization refers to: converting data back to the original data structure or object. When deserializing the query results, since the query parameters already contain key information such as primary key values ​​and tag names, only the actual attribute data needs to be processed during the deserialization process.

[0136] In order to further optimize the performance, in an optional embodiment, the query execution mode can be adjusted from asynchronous mode to synchronous mode. Although asynchronous execution has its advantages in a concurrent environment, in some queries that take a short time, the performance loss caused by thread creation cannot be ignored. This performance loss may include the overhead of thread creation, context switching, etc.

[0137] For single-point query statements, if the physical plan cache is fully matched based on the query statement, when the query conditions or label names in the query statement change, the corresponding physical plan can only be different. In this way, the performance of single-point query can only be significantly improved when the client sends a large number of identical query statements. If the label name and primary key value in the query statement sent by the client change at any time, the performance improvement of the physical plan cache is minimal, and even the query speed itself will be reduced due to some cache queries that miss. In actual application scenarios, such as data preprocessing of graph computing, all points under the current graph or a layer of adjacency of a specified point will be queried; before executing the adjacency query, the physical id of each point will be queried first to speed up the subsequent adjacency query, and the physical id of the point in the graph needs to be obtained through a single-point query. If the physical plan cache is fully matched based on the query statement, each single-point query needs to execute the entire process because the plan cache cannot hit. Therefore, the embodiment of the present invention uses a multi-level cache mechanism and combines it with the method of replacing core query parameters to realize that the entire process is executed only in the first query. When the query conditions or label names in the query statement change, the same current physical plan can be used later. Each time when the current physical plan is executed, the corresponding values ​​of the query parameters that are different from the previous query are obtained. Using the single-point query method based on a distributed graph database of the embodiment of the present invention, in one embodiment, the average query time is 1ms, and the average time to execute the entire query process is 10ms. A single query can save 9ms, and the performance improvement can reach 90%.

[0138] The present invention optimizes the execution efficiency and resource consumption of single-point queries by setting up a series of technical means such as multi-level cache, conversion of query statements, step optimization, and simplified execution logic, so as to ensure that the system can execute more queries per unit time, greatly improve the single-point query performance, and ensure the QPS of single-point queries.

[0139] Embodiment 2:

[0140] like Fig.10 , is a schematic diagram of the architecture of a single-point query device based on a distributed graph database according to an embodiment of the present invention. The single-point query device based on a distributed graph database according to this embodiment includes one or more processors 21 and a memory 22. Fig.10 A processor 21 is taken as an example.

[0141] The processor 21 and the memory 22 may be connected via a bus or other means. Fig.10 The example of connecting through bus is taken in the following.

[0142] The memory 22 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs and non-volatile computer executable programs, such as the single-point query method based on the distributed graph database in this embodiment. The processor 21 executes the single-point query method based on the distributed graph database by running the non-volatile software programs and instructions stored in the memory 22.

[0143] The memory 22 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 22 may optionally include a memory remotely arranged relative to the processor 21, and these remote memories may be connected to the processor 21 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0144] The program instructions / modules are stored in the memory 22, and when executed by the one or more processors 21, they execute the single-point query method based on the distributed graph database in the above-mentioned embodiment, for example, they execute the various steps of the single-point query method based on the distributed graph database in the embodiment of the present invention described above.

[0145] An embodiment of the present invention further provides a non-volatile computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions are executed by one or more processors, such as Fig.10A processor 21 can enable the above one or more processors to execute the single-point query method based on the distributed graph database in the specific implementation of the present invention, for example, to execute the various steps of the single-point query method based on the distributed graph database in the embodiment of the present invention described above; it can also realize Fig.10 The modules and units described above; or executing the single-point query method based on the distributed graph database in the specific implementation of the present invention, for example, executing the various steps of the single-point query method based on the distributed graph database in the embodiment of the present invention described above; it can also be implemented Fig.10 The various modules and units described.

[0146] It is worth noting that the information interaction, execution process, etc. between the modules and units within the above-mentioned devices and systems are based on the same concept as the processing method embodiment of the present invention. The specific contents can be found in the description of the method embodiment of the present invention and will not be repeated here.

[0147] A person skilled in the art may understand that all or part of the steps in the various methods of the embodiments may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0148] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A single-point query method based on a distributed graph database, characterized in that: include: Determine the physical plan parameters corresponding to the query statement to be queried; Determine whether there is an available physical plan in the physical plan cache that matches the physical plan parameters; When there is a matching available physical plan, determining the available physical plan as a physical plan template; Obtaining the query parameters of the query statement; Replacing the core query parameters in the physical plan template with the parameters to be queried to obtain the current physical plan; The current physical plan is executed to obtain a single-point query result of the query statement.

2. The single-point query method based on a distributed graph database according to claim 1 is characterized in that: The physical plan parameters include the name of the graph to be queried and the converted statement of the statement to be queried; Determining the physical plan parameters corresponding to the query statement includes: Based on the abstract syntax tree of the query statement, determining whether the query statement is a single-point query statement; When the statement to be queried is a single-point query statement, the graph name to be queried and the converted statement are obtained based on the abstract syntax tree to generate the physical plan parameters.

3. The single-point query method based on a distributed graph database according to claim 2 is characterized in that: The determining, based on the abstract syntax tree of the query statement, whether the query statement is a single-point query statement comprises: Determine an abstract syntax tree corresponding to the query statement; Traversing the abstract syntax tree, when a Where expression is matched in the abstract syntax tree, determining whether the nodes constituting the Where expression only constitute the first predicate expression and the second predicate expression; wherein the abstract syntax tree includes at least one node; When the nodes constituting the Where expression only constitute the first predicate expression and the second predicate expression, obtaining a unique identifier corresponding to the graph name to be queried in the abstract syntax tree, so as to determine whether the attribute key in the second predicate expression is a primary key column according to the unique identifier; When the attribute key is the primary key column, the query statement to be queried is a single-point query statement.

4. The single-point query method based on a distributed graph database according to claim 3 is characterized in that: Determining the abstract syntax tree corresponding to the query statement includes: Using the query statement as a unique keyword, searching in the syntax tree cache whether there is a parsed syntax tree corresponding to the query statement; If there is no corresponding parsed syntax tree in the syntax tree cache, perform syntax parsing, abstract syntax tree rewriting and syntax checking on the query statement to obtain a corresponding abstract syntax tree, and store the obtained abstract syntax tree in the syntax tree cache; If there is a corresponding parsed syntax tree in the syntax tree cache, the parsed syntax tree is determined as the abstract syntax tree.

5. The single-point query method based on a distributed graph database according to claim 3 is characterized in that: The step of obtaining the query parameter of the query statement; The core query parameters in the physical plan template are replaced with the parameters to be queried, and the current physical plan is obtained including: The core query parameters are replaced with a tag name and a primary key value; wherein the parameters to be queried include the tag name and the primary key value, the tag name is extracted from the first predicate expression, and the primary key value is extracted from the second predicate expression; The replaced physical plan template and the parameters to be queried are used as the current physical plan, so that when the current physical plan is executed, values ​​corresponding to corresponding parameters are obtained according to the parameters to be queried.

6. The single-point query method based on a distributed graph database according to claim 2 is characterized in that: When the query statement is a single-point query statement, obtaining the query graph name and the converted statement based on the abstract syntax tree to generate the physical plan parameters includes: Extracting the to-be-queried parameters from the abstract syntax tree, and generating a converted statement based on the to-be-queried parameters; acquiring the to-be-queried graph name from the abstract syntax tree; and generating a cache query parameter using the to-be-queried graph name and the converted statement; Using the cache query parameter as a unique keyword, searching in the query result cache whether there is a query result corresponding to the cache query parameter; When there is a query result corresponding to the cache query parameter in the query result cache, the corresponding query result is obtained from the query result cache, so as to directly determine the obtained query result as the single-point query result; When there is no query result corresponding to the cached query parameter in the query result cache, the graph name to be queried and the converted statement are determined as the physical plan parameters.

7. The single-point query method based on a distributed graph database according to any one of claims 1 to 6, characterized in that: The physical plan parameters include a metadata version number; Before determining whether there is an available physical plan matching the physical plan parameters in the physical plan cache, the method further includes: Get the metadata version number of the required query from the local cache; Determine whether the metadata version number of the required query matches the metadata version number of the physical plan cache; When the metadata version number of the required query does not match the metadata version number of the physical plan cache, all available physical plans in the physical plan cache are cleared.

8. The single-point query method based on a distributed graph database according to any one of claims 1 to 6, characterized in that: When the life cycle of a session object ends, all data in the cache space of the session object is cleared.

9. A single-point query device based on a distributed graph database, characterized in that: The single-point query device based on a distributed graph database includes at least one processor and a memory. The at least one processor and the memory are connected via a data bus. The memory stores instructions that can be executed by the at least one processor. After being executed by the processor, the instructions are used to implement the single-point query method based on a distributed graph database as described in any one of claims 1-8.

10. A non-volatile computer storage medium, characterized in that: The computer storage medium stores computer executable instructions, and the computer executable instructions are executed by one or more processors to complete the single-point query method based on a distributed graph database as described in any one of claims 1-8.

Citation Information

Cited By

  • Graph database adjacency record management method and device, equipment and storage medium

    CN121030048A

  • A graph database adjacency record management method, device and equipment and storage medium

    CN121030048B