Implementation method of query filter condition pushdown in graph database
By pushing query filtering conditions to the storage engine for execution in graph databases, the problem that traditional methods are not suitable for multi-level adjacency queries in graph databases is solved, thus improving query performance and efficiency.
Patent Information
- Application Number
- CN202310411384.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-18
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2043-04-18
AI Technical Summary
Traditional query filtering push-down methods are not suitable for multi-level adjacency queries in graph databases, resulting in poor query performance.
The query filtering conditions of the graph database are pushed down to the storage engine for execution. This is done by initializing the parameter list, converting the filtering conditions of the adjacency query step into a tree-structured pushdown expression, and then pushing it down to the storage engine for execution through the storage engine interface.
This significantly reduces the amount of effective data in each adjacency layer, alleviating the memory and computational pressure on the computing engine and improving query performance and efficiency.
Smart Images

Figure CN116501762B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of graph database, and particularly relates to an implementation method of graph database query filter condition pushdown. BACKGROUND
[0002] The traditional relational database often uses predicate pushdown as one of the means of query optimization. The predicate is a function that returns a boolean value, that is, true or false, or a function that is implicitly converted to boolean. Common predicates mainly include LKIE, BETWEEN, IS NULL, IS NOT NULL, IN, EXISTS, etc. The basic idea of predicate pushdown is to move the filter condition expression (=,!=, >, <, etc.) as much as possible to the position close to the data source, so that the irrelevant data can be directly skipped when actually executed. The purpose of predicate pushdown is to execute some filter conditions at the bottom layer as much as possible to reduce the amount of data interaction at each layer, thereby improving query performance.
[0003] When performing multi-table join query in the relational database, if a filter condition expression involves attributes of multiple tables, the complete pushdown of the filter condition expression may not be performed. For example, in the statement "select count(1) from A join B on A.id=B.id join C on C.id where A.x+B.x+C.x=100 and A.y+B.y>C.y", the where filter condition contains attributes of tables A, B and C, so complete pushdown may not be performed. The query method of the graph database mainly uses multi-layer adjacency query, and a filter condition expression may contain vertex and edge attributes in multiple adjacency relationships, so the query filter condition pushdown method commonly used in the traditional relational database is not applicable to the graph database whose query method mainly uses multi-layer adjacency query. SUMMARY
[0004] The application aims to solve the problem that the conventional query filter condition pushdown method is not applicable to the graph database whose query method mainly uses multi-layer adjacency query. The application discloses an implementation method of graph database query filter condition pushdown, which is applicable to filter condition pushdown in multi-layer adjacency query and improves the performance of adjacency query of the graph database.
[0005] Technical scheme: An implementation method of graph database query filter condition pushdown, comprising the following steps:
[0006] Step 1: Obtain the adjacency query statement for the graph database, and divide the adjacency query statement for the graph database into multiple adjacency query steps for execution.
[0007] Step 2: initialize a parameter list, the parameter list including: stepId, columnId and paramId, one stepId corresponding to N columnId and paramId, columnId and paramId in the same stepId corresponding one by one, the stepId being a step ID sequence number, the columnId being an attribute column ID sequence number, the attribute column ID sequence number being a sequence number automatically generated by a graph database for each attribute column when creating a point or an edge, the paramId being a parameter index value, indicating the index value of the attribute column of the front adjacency relationship in the parameter list of the current adjacency query step, N≥1;
[0008] Step 3: convert the filter condition expression of the adjacency query step into a pushdown expression; the pushdown expression being a tree structure with column type, constant type and parameter type as leaf nodes, function type as root node and non-leaf node, the value of the parameter type being the paramId in the parameter list of the current adjacency query step;
[0009] Step 4: push the pushdown expression in each adjacency query step to the storage engine through the interface provided by the storage engine, execute the adjacency query step, and obtain the preliminary query result; for the adjacency query step with the pushdown expression, use the pushdown expression to filter the preliminary query result to obtain the final query result.
[0010] Further, step 2 specifically includes:
[0011] traverse all adjacency query steps;
[0012] if there is no relevant filter condition in the current adjacency query step, proceed to the next adjacency query step;
[0013] if there is a relevant filter condition in the current adjacency query step, but the filter condition does not contain the attribute column field in the front adjacency relationship, proceed to the next adjacency query step;
[0014] if there is a relevant filter condition in the current adjacency query step, and the filter condition contains the attribute column field in the front adjacency relationship, record the current query step ID and attribute column ID in the parameter list, and record the parameter index value in the parameter list after incrementing by 1, and proceed to the next adjacency query step.
[0015] Further, step 3 specifically includes:
[0016] traverse all adjacency query steps;
[0017] parse the filter condition expression in the current adjacency query step; the filter condition expression being a tree structure, the nodes of which including constant value, attribute column and function;
[0018] If the current node is a constant value, a push-down expression of the corresponding constant type is generated;
[0019] If the current node is an attribute column, and there is no parameter information of the attribute column in the parameter list of the current adjacency query step, a push-down expression of the corresponding column type is generated;
[0020] If the current node is an attribute column, and there is parameter information of the attribute column in the parameter list of the current adjacency query step, a push-down expression of the corresponding parameter type is generated;
[0021] If the current node is a function, for each child node in the function, a child push-down expression corresponding to each child node is generated, and the set of child push-down expressions is taken as the child node of the current function, and a push-down expression of the corresponding function type is generated.
[0022] Further, the basic data structure of the push-down expression is represented as:
[0023]
[0024] Wherein, PushDownExpression represents the push-down expression, Type represents the expression type, Value represents the constant value / attribute column name / parameter list index value in the expression, Children represents the set of child push-down expressions, when the number of the set of child push-down expressions is 0, it means that the current push-down expression is a leaf node of the entire push-down expression, and Signature represents the function signature type of the push-down expression, used to represent the conditional operator of the push-down expression.
[0025] The relationship between various attributes in the push-down expression is as follows:
[0026] When the Type type is a constant type, the corresponding constant value is saved in Value, and Signature is FuncSig_Unspecified;
[0027] When the Type type is a column type, the parameter information of the attribute column is saved in Value, and Signature is FuncSig_Unspecified;
[0028] When the Type type is a parameter type, the corresponding parameter list index value is saved in Value, and Signature is FuncSig_Unspecified;
[0029] When the Type type is a function type, the child push-down expressions of the function operation are saved in Children, and Signature is the corresponding function signature type.
[0030]
[0031] ExprType_String represents a constant type, ExprType_Column represents a column type, which represents that the current pushdown expression is an attribute column field; ExprType_Param represents a parameter type, which represents that the attribute column of the current pushdown expression comes from the attribute column field in the previous adjacency relation and will exist as a parameter type in the pushdown expression of the current adjacency relation; and ExprType_ScalarFunc represents a function type, which represents that the current pushdown expression is a function operation.
[0032] Further, the step 4 specifically comprises:
[0033] creating a statement handle of the current adjacency query step, which is used to identify and recognize the current adjacency query step and the pushdown expression of the current adjacency query step in the storage engine;
[0034] through an interface provided by the storage engine, pushing down and transferring the pushdown expression in each adjacency query step to the storage engine, and before the end of the current adjacency query step, the current adjacency query step is always bound to the created statement handle;
[0035] traversing each adjacency query step;
[0036] if there is no relevant pushdown expression in the current adjacency query step, directly executing the current adjacency query step and returning the query result;
[0037] if there is a relevant pushdown expression in the current adjacency query step, and the pushdown expression does not contain a parameter type, directly executing the current adjacency query step, and returning the query result after the storage engine uses the pushdown expression to complete the data filtering of the current query;
[0038] if there is a relevant pushdown expression in the current adjacency query step, and the pushdown expression contains a parameter type, constructing a parameter value array, the parameter value array sequentially saves actual data corresponding to the parameter type node in the pushdown expression, and the actual data comes from the query result of the previous adjacency query step; the parameter value array is transmitted to the storage engine while the current adjacency query step is executed, the storage engine references the actual data in the parameter value array to the pushdown expression, and returns the query result after the storage engine uses the pushdown expression to complete the data filtering of the current query.
[0039] Further, the structure of the parameter value array is represented as:
[0040] [0] Param_Value |
[0041] [1]Param_Value| ......
[0043] [N]Param_Value|
[0044] Wherein, the number in square brackets is the array index, and Param_Value represents the actual data corresponding to the parameter type node in the push-down expression of the current adjacency query step.
[0045] Further, the actual data in Param_Value is the actual data of the specified attribute column in the query result set of the previous adjacency query step obtained through columnId in the parameter list.
[0046] Further, the [N]th element in the parameter value array corresponds to the element with paramId [N+1] in the parameter list.
[0047] The application discloses a computer device, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the disclosed implementation method of graph database query filtering condition push-down when executing the computer program.
[0048] The application discloses a storage medium, wherein the storage medium stores a method for accelerating switching power supply program, and the method for accelerating switching power supply program implements the steps of the disclosed implementation method of graph database query filtering condition push-down when executed by at least one processor.
[0049] Advantages: compared with the prior art, the application has the following advantages:
[0050] (1) In the multi-layer adjacency query process of the graph database, the application pushes down the filtering condition to the storage engine, greatly reduces the effective data amount of each layer of adjacency relationship, reduces the memory pressure and calculation pressure of the calculation engine, and improves the query performance.
[0051] (2) The method effectively reduces the network communication between the calculation engine and the storage engine in the multi-layer adjacency query process of the graph database, and improves the query efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0052] Figure 1 It is the initialization flowchart of the parameter list of the application;
[0053] Figure 2 It is the conversion flowchart of converting the filtering condition expression into the push-down expression of the application;
[0054] Figure 3 It is the execution flowchart of the push-down expression of the application;
[0055] Figure 4 Point, edge adjacency relationship diagram for an embodiment;
[0056] Figure 5 Step 2 conditional expression tree for an embodiment;
[0057] Figure 6 Step 3 conditional expression tree for an embodiment. DETAILED DESCRIPTION
[0058] The core idea of the present application is that in the multi-layer adjacency query process of a graph database, filter conditions are pushed down from the calculation engine of the graph database to the storage engine for execution, and valid data is extracted and irrelevant data is filtered out in the storage engine, which is closest to the data source.
[0059] An implementation method of the present application for pushing down filter conditions of a graph database query mainly includes the following steps:
[0060] Step 1: define a push-down format filter condition expression, which is referred to as a push-down expression for short below for convenience of description.
[0061] The push-down expression PushDownExpression is a tree structure, and its basic data structure is as follows:
[0062]
[0063] Among them, Type represents the expression type; Value represents the constant value / attribute column name / parameter list index value in the expression; Children represents the collection of child expressions, and when the number of child expressions is 0, it means that the current expression is a leaf node of the entire push-down expression; Signature represents the function signature type of the expression, which is mainly used to represent the conditional operator of the expression.
[0064] The relationship between the various attributes in the push-down expression is as follows:
[0065] When Type is a constant, the corresponding constant value is saved in Value, and Signature is FuncSig_Unspecified;
[0066] When Type is a column, the corresponding attribute column name is saved in Value, and Signature is FuncSig_Unspecified;
[0067] When Type is a parameter, the corresponding parameter list index value is saved in Value, and Signature is FuncSig_Unspecified;
[0068] When the Type type is function, the Children holds the child node condition expression of the function operation, and the Signature is the corresponding function signature type.
[0069]
[0070]
[0071] The expression type ExprType mainly contains four categories, which are constant, column, parameter and function types. The constant type can be further divided into various value types such as int and string (not all types are shown here due to too many data types). The column type ExprType_Column represents that the current expression is an attribute column field. The parameter type ExprType_Param indicates that the attribute column of the current expression comes from the (point / edge) attribute column field in the previous adjacent relationship (previous step / N steps) and will exist as a parameter type in the push-down expression of the current adjacent relationship. The function type ExprType_ScalarFunc represents that the current expression is a function operation.
[0072]
[0073] The function signature FuncSig mainly contains four types of operators, which are comparison operators, arithmetic operators, logical operators and bitwise operators (not all operators are shown here due to too many operators). The comparison operators and arithmetic operators will define different function signatures for each supported data type, such as int and string. The function FuncSig_Unspecified represents that the current expression is not a function operation.
[0074] Step 2: Build the push-down expression. The specific construction steps include:
[0075] S210: Initialize the parameter list:
[0076] The parameter list is mainly used to record the (point / edge) attribute column field related information in the previous adjacent relationship (previous step / N steps) included in the filter condition of the current query step in the multi-step adjacent query. The main members of the parameter list are shown in Table 1, where one stepId corresponds to N (N >= 1) columnId and paramId, and the columnId and paramId in the same stepId correspond one by one:
[0077] Table 1 Parameter list members
[0078]
[0079]
[0080] The process of initializing the parameter list is as follows:
[0081] Traverse all the adjacent query steps;
[0082] If there is no relevant filter condition in the current query step, traverse the next query step;
[0083] If there is a relevant filter condition in the current query step, but the filter condition does not contain the attribute column field in the previous adjacent relationship, traverse the next query step;
[0084] If there is a relevant filter condition in the current query step, and the filter condition contains the attribute column field in the previous adjacent relationship, update the relevant stepId, columnId, and paramId information and insert it into the parameter list, record the current query step ID, attribute column ID, and parameter index value, and increment 1. In this case, the attribute column field in the previous adjacent relationship will exist as a parameter of the filter condition in the current query step, and then traverse the next query step.
[0085] Suppose a graph query statement (such as select...match(v1)-[e2]->(v2)-[e3]->(v3)......-[eN]->(vN), where v represents a point and e represents an edge) contains N-step adjacent queries, Step1, Step2, Step3,..., StepN, the division of the query steps is as follows: Step1: v1; Step2: -[e2]->(v2); Step3: -[e3]->(v3); StepN: -[eN]->(vN). If Step1 has no relevant filter condition, the filter condition in Step2 only involves the adjacent relationship in the current step, and the filter condition in Step3 contains the attribute column fields in Step1 and Step2, then the final generated parameter list is as shown in Table 2:
[0086] Table 2 Parameter list data format
[0087]
[0088] S220: Convert the query conditions of the multi-layer adjacent relationship into a pushdown expression:
[0089] Generally, the filter condition expression is a tree structure, and there are mainly three types of nodes, which are constant value, attribute column and function, for example: "name = 5", in which "name" is an attribute column, which is the left leaf node; '=' is a function, which is the root node; '5' is a constant value, which is the right leaf node. The pushdown expression basically refers to this data structure, and contains four types, which are constant type, column type, parameter type and function type. The parameter type is a newly set type, which is mainly used to set parameter information. Here, the parameter refers to the parameter index value paramId in the parameter list.
[0090] The transformed pushdown expression is also a tree structure, in which the constant type, column type and parameter type have no child nodes and can only be leaf nodes.
[0091] The process of converting the query condition into a pushdown expression is as follows:
[0092] Traverse all the adjacent query steps;
[0093] Parse the query condition expression tree in the current adjacent query step, and use pre-order traversal to access all the nodes in the order of root left and right;
[0094] If the current node is a constant value, generate a pushdown expression of the corresponding constant type, and the specific information is as follows:
[0095]
[0096] If the current node is an attribute column, and there is no parameter information of this attribute column in the parameter list of the current step, generate a pushdown expression of the corresponding column type, and the specific information is as follows:
[0097]
[0098] If the current node is an attribute column, and there is parameter information of this attribute column in the parameter list of the current step, generate a pushdown expression of the corresponding parameter type, and the specific information is as follows:
[0099]
[0100] If the current node is a function, for each child node in the function, execute the above steps to generate a corresponding pushdown expression for each child node, and finally take the set of child pushdown expressions as the child node of the current function expression, to generate a pushdown expression of the corresponding function type, and the specific information is as follows:
[0101]
[0102] Step 3: Execute the pushdown expression, and the specific execution steps include:
[0103] Create a statement handle of the current query, which is mainly used to identify and recognize the current query and the pushdown expression of the current query in the storage engine;
[0104] Through the interface provided by the storage engine, push down the pushdown expression in each generated adjoin query step to the storage engine, and always bind it with the created statement handle before the current query ends;
[0105] Traverse each adjoin query step;
[0106] If there is no relevant pushdown expression in the current adjoin query step, directly execute the current adjoin query and return the query result;
[0107] If there is a relevant pushdown expression in the current adjoin query step, but the pushdown expression does not contain a parameter type, directly execute the current adjoin query, and return the query result after the storage engine uses the pushdown expression to complete the data filtering of the current query;
[0108] If there is a relevant pushdown expression in the current adjoin query step, and the pushdown expression contains a parameter type, the processing process is as follows:
[0109] Build a parameter value array: the parameter value array is a two-dimensional array that sequentially saves the actual data corresponding to the parameter type nodes in the pushdown expression in the current adjoin query step. The actual data comes from the query return result of the previous adjoin step. The main members of the parameter value array are as follows:
[0110] [0]Param_Value|
[0111] [1]Param_Value| ...
[0113] [N]Param_Value|
[0114] Wherein, the number in the square brackets represents the array subscript and does not need to be actually stored. Param_Value represents the actual data corresponding to the parameter type node in the pushdown expression in the current adjoin query step (since the array subscript in the parameter value array starts from 0, while the valid serial number of paramId in the parameter list starts from 1, so the matching relationship between the two is that the [N]th element in the parameter value array corresponds to the element with paramId [N+1] in the parameter list). The actual data in Param_Value comes from the query return result of the previous adjoin step, and the actual data of the specified attribute column in the query result set of the previous adjoin step is obtained through columnId in the parameter list.
[0115] The parameter value list is passed to the storage engine while executing the current adjacency query step, the storage engine references the actual data in the parameter value array to the pushdown expression, and finally performs data filtering to return the query result. The reference method is: the [N]th element in the parameter value array corresponds to the paramId of the parameter type node in the pushdown expression, which is [N+1].
[0116] The technical solutions of the present application will be further described in combination with the drawings and embodiments.
[0117] Embodiment:
[0118] Assume that the data model in the graph database is as shown in Figure 3 and Figure 4 The simulation data is shown in Tables 3-6, wherein the columnId of Teacher.age is 101, and the columnId of School.age is 202:
[0119] Table 3 Point and edge structure definition
[0120]
[0121] Table 4 School data
[0122]
[0123] Table 5 Employ and Teacher data
[0124]
[0125] Table 6 Teach and Student data
[0126]
[0127]
[0128] Assume that the current adjacency query statement is "select st.name match(sc:School)-[e:Employ]->(tr:Teacher)-(t:Teach)->(st:Student)where tr.subject="geography" and tr.age+st.age>sc.age", which will be executed in three adjacency query steps, which are:
[0129] Step 1: (sc:School), no filtering condition;
[0130] Step 2: -[e:Employ]->(tr:Teacher), filtering condition (tr.subject="geography"); Step 3: -(t:Teach)->(st:Student), filtering condition (tr.age+st.age>sc.age).
[0131] Step3: -(t:Teach)->(st:Student), filter condition (tr.age+st.age>sc.age).
[0132] The implementation method of the graph database adjacency query filter condition pushdown of the embodiment comprises:
[0133] Step 1: initialize the parameter list: as shown in the following table 1, specifically comprising the following steps: Figure 1
[0134] S101: first traverse Step1, there is no filter condition, so there is no need to update the parameter list, and directly proceed to the next step of the adjacency query step traversal;
[0135] S102: then traverse Step2, there is a related filter condition (tr.subject="geography"), but "tr.subject" in the filter condition is the attribute column of Teacher in the current adjacency query step, which is not the attribute column in the previous adjacency query step Step1, so there is no need to update the parameter list, and proceed to the next step of the adjacency query step traversal;
[0136] S103: finally traverse Step3, there is a related filter condition (tr.age+st.age>sc.age), and "tr.age" and "sc.age" in the filter condition are the attribute columns of Teacher in the previous adjacency query step Step2 and School in Step1 respectively, and "st.age" is the attribute column of Student in the current adjacency query step, so the related stepId, columnId, paramId information is updated and inserted into the parameter list, as shown in the following table 7:
[0137] Table 7: parameter list of the embodiment
[0138]
[0139] S104: the traversal is completed, and the parameter list initialization of the current query statement is completed.
[0140] Step 2: convert the filter condition expression into a pushdown expression; as shown in the following table 2, specifically comprising the following steps: Figure 2
[0141] S201: first traverse Step1, there is no related filter condition, so there is no need to generate the corresponding pushdown expression, and directly proceed to the next step of the adjacency query step traversal;
[0142] S202: Next, iterate through Step 2. There is a relevant filter condition (tr.subject = "Geography"). This filter condition needs to be converted into a pushdown expression. The structure diagram of this filter condition is as follows: Figure 5 As shown, the tree structure of the transformed pushdown expression remains unchanged. Node ①, with the equals sign '=', is a function type; Node ②, tr.subject, is the attribute column of Teacher in the current adjacency query, so it's a column type; Node ③, "Geography," is a string, which is a constant type. Nodes ② and ③ are two child nodes of Node ①, and the pushdown expressions in each node are shown in Table 8. After the current adjacency query's filtering conditions are transformed into pushdown expressions, the next adjacency query step is performed.
[0143] S203: Finally, traversing Step 3, a relevant filtering condition exists (tr.age + st.age > sc.age). This filtering condition needs to be transformed into a pushdown expression. The structure diagram of this filtering condition is as follows: Figure 6 As shown, the tree structure of the transformed pushdown expression remains unchanged. Node ① (>) is a function type; Node ② (+) is a function type; Node ③ (tr.age) is an attribute column from the preceding adjacency query Step2 (Teacher), so it is a parameter type with paramId = 1; Node ④ (st.age) is an attribute column from the current adjacency query (Student), so it is a column type; Node ⑤ (sc.age) is an attribute column from the preceding adjacency query (Step1 (School), so it is a parameter type with paramId = 2). Nodes ② and ⑤ are two child nodes of Node ①, and nodes ③ and ④ are two child nodes of Node ②. The pushdown expressions for each node are shown in Table 9.
[0144] S204: Traversal ends, completing the pushdown expression transformation of the current query statement.
[0145] Table 8. Information on each node of the Step 2 pushdown expression.
[0146]
[0147] Table 9. Information on each node of the Step 3 pushdown expression.
[0148]
[0149]
[0150] Step 3: Execute the pushdown expression; such as Figure 6 As shown in .3, the specific steps include:
[0151] S301: Create a statement handle for the current adjacency query;
[0152] S302: pass the pushdown expression built in Step 2 to the storage engine through the filter condition pushdown interface provided by the storage engine;
[0153] S303: first execute Step 1, no related pushdown expression, so directly execute the adjoint query of Step 1, and return the query result, the Step 1 query result set is shown in Table 10:
[0154] Table 10 Step 1 query result set
[0155]
[0156] S304: then execute Step 2, there is a related pushdown expression, but there is no parameter type in the pushdown expression, so directly execute the adjoint query of Step 2, and return the query result, since the query condition of Step 2 has been pushed down to the storage engine, so the adjoint query result of Step 2 is filtered by the storage engine, the Step 2 query result set is shown in Table 11:
[0157] Table 11 Step 2 query result set
[0158]
[0159] S305: finally execute Step 3, there is a related pushdown expression, and the pushdown expression contains parameter types, so the parameter value array needs to be built first. As can be seen from S203, the pushdown expression of Step 3 contains two parameter type nodes, tr.age and sc.age, and the paramId of tr.age is 1 and the paramId of sc.age is 2, according to the adjoint query result of Step 2 in S304, the value of tr.age is 62 and the value of sc.age is 80, so the final parameter value array is as follows.
[0160] [0] 62|
[0161] [1] 80|
[0162] Step 3 parameter value array
[0163] Finally, execute the adjoint query of Step 3, and pass this parameter value array to the storage engine. Since the filter condition of Step 3 has been pushed down to the storage engine, so the adjoint query result of Step 3 is also filtered by the storage engine, the Step 3 query result set is shown in Table 12.
[0164] Table 12 Step 3 query result set
[0165]
[0166] S306: The adjacency query execution is completed, and according to the query result shown in Table 13, the data of st.name is "Li Lan", which is finally returned to the client.
[0167] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when executed, can include the processes of the above-mentioned embodiment methods. Any reference to memory, storage, database or other medium used in the embodiments provided by the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0168] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the present application.
[0169] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent. It should be pointed out that for those skilled in the art, without departing from the concept of the present application, some modifications and improvements can be made, which are all within the protection scope of the present application. Therefore, the protection scope of the patent of the present application should be subject to the appended claims.
Claims
1. An implementation method of graph database query filter condition pushdown, characterized in that: The method comprises the following steps: Step 1: obtaining a current adjacency query statement for a graph database, and dividing the current adjacency query statement for the graph database into multiple adjacency query steps for execution; Step 2: initializing a parameter list, wherein the parameter list comprises: a step ID, a column ID and a param ID, one step ID corresponds to N column IDs and param IDs, the column IDs and the param IDs in the same step ID correspond to each other, the step ID is a step ID sequence number, the column ID is an attribute column ID sequence number, the attribute column ID sequence number is a sequence number automatically generated by the graph database for each attribute column when creating a point or an edge, the param ID is a param index value, and the param index value represents an index value of an attribute column of a previous adjacency relationship in the parameter list of the current adjacency query step, and N is greater than or equal to 1; Step 3: converting a filter condition expression of an adjacency query step into a pushdown expression; the pushdown expression is a tree structure with a column type, a constant type and a param type as leaf nodes, a function type as root nodes and non-leaf nodes, and the value of the param type is a param ID in the parameter list of the current adjacency query step; Step 4: pushing the pushdown expression in each adjacency query step to a storage engine through an interface provided by the storage engine, executing the adjacency query step, obtaining a preliminary query result, and using the pushdown expression to filter the preliminary query result to obtain a final query result for the adjacency query step with the pushdown expression.
2. The method of claim 1, wherein: Step 2 specifically comprises: traversing all adjacency query steps; if there is no relevant filter condition in the current adjacency query step, traversing the next adjacency query step; if there is a relevant filter condition in the current adjacency query step, but the filter condition does not contain an attribute column field in a previous adjacency relationship, traversing the next adjacency query step; if there is a relevant filter condition in the current adjacency query step, and the filter condition contains an attribute column field in the previous adjacency relationship, recording the current query step ID and the attribute column ID in the parameter list, and recording the param index value in the parameter list after incrementing the param index value by 1, and then traversing the next adjacency query step.
3. The method of claim 1, wherein: Step 3 specifically comprises: traversing all adjacency query steps; parsing a filter condition expression in the current adjacency query step; the filter condition expression is a tree structure, and the nodes of the tree structure comprise constant values, attribute columns and functions; if the current node is a constant value, generating a corresponding constant type pushdown expression; if the current node is an attribute column, and there is no param information of the attribute column in the parameter list of the current adjacency query step, generating a corresponding column type pushdown expression; if the current node is an attribute column, and there is param information of the attribute column in the parameter list of the current adjacency query step, generating a corresponding param type pushdown expression; and if the current node is a function, generating a corresponding function type pushdown expression. If the current node is a function, for each child node in the function, a corresponding child pushdown expression is generated for each child node, and a set of child pushdown expressions is taken as the child nodes of the current function to generate a pushdown expression of the corresponding function type.
4. The method of claim 3, wherein: The basic data structure of the pushdown expression is represented as: wherein PushDownExpression represents the pushdown expression, Type represents the expression type, Value represents the constant value / attribute column name / parameter list index value in the expression, Children represents a set of child pushdown expressions, when the number of the set of child pushdown expressions is 0, it means that the current pushdown expression is a leaf node of the entire pushdown expression, and Signature represents the function signature type of the pushdown expression, used to represent the conditional operator of the pushdown expression. The relationship between various attributes in the pushdown expression is as follows: When the Type type is a constant type, the corresponding constant value is saved in Value, and Signature is FuncSig_Unspecified; When the Type type is a column type, the parameter information of the attribute column is saved in Value, and Signature is FuncSig_Unspecified; When the Type type is a parameter type, the corresponding parameter list index value is saved in Value, and Signature is FuncSig_Unspecified; When the Type type is a function type, the child pushdown expressions of the function operation are saved in Children, and Signature is the corresponding function signature type; ExprType_String represents a constant type, ExprType_Column represents a column type, which means that the current pushdown expression is an attribute column field; ExprType_Param represents a parameter type, which means that the attribute column of the current pushdown expression comes from the attribute column field in the previous adjacency relationship, and will exist as a parameter type in the pushdown expression of the current adjacency relationship; ExprType_ScalarFunc represents a function type, which means that the current pushdown expression is a function operation.
5. The method of claim 1, wherein: Step 4 specifically includes: creating a statement handle of the current adjacency query step, used to identify and recognize the current adjacency query step and the pushdown expression of the current adjacency query step in the storage engine; through the interface provided by the storage engine, the pushdown expression in each adjacency query step is transferred to the storage engine, and the current adjacency query step is always bound to the created statement handle before the end of the current adjacency query step; traversing each adjacency query step; if there is no relevant pushdown expression in the current adjacency query step, the current adjacency query step is directly executed, and the query result is returned; if there is a relevant pushdown expression in the current adjacency query step, and the pushdown expression does not contain a parameter type, the current adjacency query step is directly executed, and the query result is returned after the storage engine uses the pushdown expression to complete the data filtering of the current query; If there is a related pushdown expression in the current adjacency query step, and the pushdown expression contains a parameter type, a parameter value array is constructed, which sequentially saves the actual data corresponding to the parameter type node in the pushdown expression, and the actual data comes from the query result of the previous adjacency query step; the parameter value array is passed to the storage engine while executing the current adjacency query step, and the storage engine references the actual data in the parameter value array to the pushdown expression, and returns the query result after the storage engine uses the pushdown expression to complete the data filtering of the current query.
6. The method of claim 5, wherein: The structure of the parameter value array is represented as: [0]Param_Value| [1]Param_Value| ...... [N]Param_Value| Wherein, the number in the square brackets is the array subscript, and Param_Value represents the actual data corresponding to the parameter type node in the pushdown expression of the current adjacency query step.
7. The method for implementing graph database query filtering condition pushback according to claim 6, characterized in that: The actual data in Param_Value is the actual data of the specified attribute column in the query result set of the previous adjacency query step, which is obtained through columnId in the parameter list.
8. The method for implementing graph database query filtering condition pushback according to claim 6, characterized in that: The Nth element in the parameter value array corresponds to the element with paramId[N+1] in the parameter list.
9. A computer device, comprising: A computer program product including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method for pushing down a graph database query filtering condition according to any one of claims 1 to 8.
10. A storage medium, characterized by The storage medium stores a program for accelerating the switching power supply, and the program for accelerating the switching power supply is executed by at least one processor to implement the steps of the method for pushing down a graph database query filtering condition according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method and device for querying data in graph database
CN112925954A
Method and device for database query language based on SQL (Structured Query Language) extension graph
CN115858872A