Graph database control flow interpretation execution system and method

By introducing a control flow interpreter and Nebula Graph compilation and execution module into the graph database kernel, the problems of frequent data interaction and decentralized logic in existing technologies are solved. This enables seamless integration of control flow statements and GQL statements, improves execution efficiency and query response speed, enhances the graph query expression capabilities, and optimizes the scheduling of complex business logic.

CN120705366APending Publication Date: 2025-09-26杭州悦数科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510832121.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-20
Publication Date
2025-09-26

AI Technical Summary

Technical Problem

Existing graph databases lack support for kernel-level control flow statements in complex business scenarios, resulting in frequent data interactions, increased network latency, and resource overhead. These issues also limit decentralized logic optimization and make it difficult to meet the needs of logical judgment, loop iteration, and state transfer.

Method used

A control flow interpreter, scope manager, and Nebula Graph compilation and execution module are introduced into the graph database kernel to implement the parsing, scheduling, and variable management of control flow statements. The stack structure is used to manage variable states and intermediate results. If statements, while statements, and assignment statements are supported. Through the collaborative work of kernel-level interpretation and compilation, complex business logic is optimized.

Benefits of technology

It achieves unified scheduling of control flow statements and native GQL statements, reduces frequent interactions between clients and servers, improves overall execution efficiency and query response speed, and enhances graph query expression capabilities and optimized scheduling capabilities for complex business logic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120705366A_ABST
    Figure CN120705366A_ABST
Patent Text Reader

Abstract

The invention discloses a graph database control flow interpretation execution system and method, relates to the technical field of graph database query and kernel interpretation execution, and solves the problems that in the prior art, network delay and resource overhead are increased frequently due to data interaction which is caused by realizing control flow logic through multiple calls in an upper-layer SDK (Software Development Kit); the system comprises a kernel-level control flow interpreter, an action range manager and a Nebula Graph compiling execution module, in a Nebula Graph kernel, native GQL grammar is expanded, support for control flow statements such as if statements and whil statements is added, the control flow interpreter firstly analyzes the whole mixed script, and the action range manager and the Nebula Graph compilation execution module are used for compiling the control flow statements in the Nebula Graph kernel in the Nebula Graph kernel in the Nebula Graph kernel in the Nebula Graph kernel in the Nebula Graph kernel in the Nebula Graph kernel. Different branches are scheduled and executed at a server side according to logic such as conditional judgment, and when the branches only comprise native GQL statements, execution plans are generated by a Nebula Graph compiling execution module and then executed, so that kernel-level dynamic scheduling is realized, state and variable transmission is optimized, and the overall performance of the system is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of graph database query and kernel interpretation and execution, and in particular to a graph database control flow interpretation and execution system and method. Background Art

[0002] Currently, graph database kernels primarily support queries and operations centered around declarative native GQL statements. These operations typically use a compiled execution model, compiling GQL statements into execution plans before running them. However, in complex business scenarios, a single GQL query often fails to meet requirements such as logical reasoning, loop iteration, and state transfer, forcing developers to implement control flow logic through multiple calls in the upper-level SDK. This approach has the following drawbacks:

[0003] 1. Frequent data interaction

[0004] The multiple sending of response data between the client and the server increases network latency and resource overhead, reducing overall system performance.

[0005] 2. Logic is decentralized and optimization is limited

[0006] The control flow logic is located at the SDK layer. The server side cannot fully perceive the execution process of the entire business logic, making it difficult to implement scheduling strategies such as overall optimization, early termination, and unnecessary query calls.

[0007] 3. Lack of dedicated kernel support

[0008] Although existing graph databases such as Neo4j have certain scalability capabilities, they generally lack support for kernel-level control flow statements and cannot implement complex logic and state management within a single process. Summary of the Invention

[0009] The purpose of this application is to overcome the problems in the prior art of implementing control flow logic through multiple calls in the upper-level SDK, which frequently causes data interaction to increase network delays and resource overhead, as well as limited logic distribution optimization, and to provide a graph database control flow interpretation and execution system and method.

[0010] In a first aspect, a graph database control flow interpretation and execution system is provided, comprising:

[0011] The control flow interpreter is used to parse the control flow statements in the mixed script, schedule the execution of the control flow statements, and manage the variables and states of the overall execution process;

[0012] Scope manager, which uses a stack structure to manage variables, states, and intermediate results in different scopes;

[0013] Nebula Graph's compilation and execution module handles variable binding for native GQL statements, compiling them into execution plans, and subsequent plan execution.

[0014] The control flow interpreter, scope manager, and Nebula Graph compilation and execution module all run in the Nebula Graph kernel.

[0015] In some possible implementations, the control flow statements include if statements, while statements, and assignment statements.

[0016] In some possible implementations, the Nebula Graph compilation and execution module includes a GQL compiler, a GQL optimizer, and a GQL execution engine. The control flow interpreter is further configured to provide the GQL compiler and GQL optimizer with QGL statements and their runtime context. The GQL compiler is configured to formulate an execution plan based on the QGL statements and their runtime context and send it to the control flow interpreter. The GQL optimizer is configured to return compiler feedback to the control flow interpreter based on the QGL statements and their runtime context. The GQL execution engine is configured to collect GQL statement runtime statistics and send them to the GQL compiler and GQL optimizer. The GQL compiler and GQL optimizer are further configured to analyze the GQL statement runtime statistics to obtain analysis results and adjustment suggestions and feed them back to the control flow interpreter.

[0017] In some possible implementations, the control flow interpreter is further used to pre-analyze subsequent operations so that the storage system and the cache system can read data in advance and optimize cache usage.

[0018] In some possible implementations, a security management module and an interpreter sandbox environment are also included. The security management module is used to define security policies and perform permission checks on control flow scripts based on the security policies. Control flow scripts that pass the permission check are placed in the interpreter sandbox environment for isolated execution. The interpreter sandbox environment accesses graph database functions or system resources through a controlled interface. The controlled interface is used to reconfirm whether the operations of the control flow interpreter when executing the script comply with the security policy.

[0019] In some possible implementations, a static code analysis module and a monitoring module are also included. The static code analysis module is used to perform a risk scan on the control flow script before the security management module performs permission verification on the control flow script. The monitoring module is used to monitor the running control flow script and issue an alarm or terminate the running of the control flow script if an abnormality is found.

[0020] In a second aspect, a method for interpreting and executing control flow in a graph database is provided, including the system in any one of the implementations of the first aspect, the method comprising:

[0021] Parsing if statements in mixed scripts;

[0022] Extract the conditional expression of the if statement and obtain the value of the conditional expression from the scope, wherein the conditional expression is the variable expression createNode;

[0023] Determine the value of the conditional expression. If the value of the conditional expression is true, execute the then branch statement block and determine whether there is a GQL statement in the then branch. Otherwise, execute the else branch statement block and determine whether there is a GQL statement in the else branch.

[0024] If there is a GQL statement, the Nebula Graph compilation and execution module is called to compile and execute the GQL statement.

[0025] Store the execution results of the GQL statement in the scope and update the database status.

[0026] In some possible implementations, if the conditional expression evaluates to true and there is a GQL statement in the then branch, the Nebula Graph compilation and execution module is called to compile and execute the INSERT statement. If the conditional expression evaluates to false and there is a GQL statement in the else branch, the Nebula Graph compilation and execution module is called to compile and execute the MATCH and DELETE statements.

[0027] In a third aspect, a method for interpreting and executing control flow in a graph database is provided, including the system in any one of the implementations of the first aspect, the method comprising:

[0028] Parse while statements in mixed scripts;

[0029] Initialize the loop counter and record the current loop count;

[0030] Extract the conditional expression of the while statement and obtain the value of the conditional expression from the scope;

[0031] Determine the value of the conditional expression. If the conditional expression is true, exit the current loop scope. Otherwise, create a new loop scope, ensure that the variables in the loop body are localized, traverse and execute each statement in the loop body, determine the statement type and execute the statement. If an interrupt instruction is received or the maximum number of loops is exceeded, exit the current loop scope.

[0032] If the loop exits because the condition is not met, the scope cleanup is performed first and then the success status is returned; if the loop exits due to an interrupt instruction, the scope is cleaned up in advance and the interrupt result is passed.

[0033] In a fourth aspect, a method for interpreting and executing control flow in a graph database is provided, including the system in any one of the implementations of the first aspect, the method comprising:

[0034] Parsing assignment statements in mixed scripts;

[0035] Extract the expression and value of the assignment statement;

[0036] Assign the value of the expression to the specified variable and use scope management to implement variable storage. If an error occurs during expression calculation or variable assignment, an exception is thrown or an error status is returned.

[0037] Returns the execution result.

[0038] This application has the following beneficial effects:

[0039] 1. The system of this application uses a kernel-level control flow interpreter to achieve unified scheduling and seamless integration of control flow statements and native GQL statements on the server side. The control flow logic is directly interpreted and executed in the kernel, while GQL queries follow the efficient compilation and execution process. This design avoids frequent interactions and context switching between the client and the server, significantly improving overall execution efficiency and reducing query latency.

[0040] 2. The system of this application realizes the transfer of variable status and intermediate results between different control flow statements by designing a stack-based scope management module, ensuring the accurate and efficient transfer of data status during the entire execution process.

[0041] 3. The system of this application takes advantage of the collaborative work of kernel-level interpreted execution and compiled execution to achieve overall optimized scheduling of complex business logic, thereby achieving higher query efficiency and faster response speed in typical business scenarios of graph databases (such as financial risk control, social networks, and recommendation systems).

[0042] 4. The method of this application embeds control flow statements such as if statements, while statements, and assignment statements in the Nebula Graph kernel, so that both native GQL statements and complex process control logic can be written in one procedure, effectively improving the graph query expression capability. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] The drawings that constitute a part of this application are used to provide a further understanding of this application. The illustrative embodiments of this application and their descriptions are used to explain this application and do not constitute an improper limitation on this application.

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

[0045] Figure 1 This is a structural diagram of the graph database control flow interpretation and execution system of Example 1 of the present application;

[0046] Figure 2 This is a schematic diagram of the hybrid execution architecture of the graph database control flow interpretation and execution system of Example 1 of the present application;

[0047] Figure 3 This is a schematic diagram of the communication and collaboration between the control flow interpreter and the NebulaGraph compilation and execution module of the graph database control flow interpretation and execution system in Example 1 of the present application;

[0048] Figure 4 This is a schematic diagram of graph data prefetching and caching optimization of the graph database control flow interpretation and execution system of Example 1 of the present application;

[0049] Figure 5 This is a schematic diagram of permission verification in the graph database control flow interpretation and execution system of Example 1 of the present application;

[0050] Figure 6 This is a flowchart of the graph database control flow interpretation and execution method of Example 2 of the present application;

[0051] Figure 7 This is a flowchart of the graph database control flow interpretation and execution method of Example 3 of the present application;

[0052] Figure 8 It is a flowchart of the graph database control flow interpretation and execution method of Example 4 of the present application.

[0053] Reference numerals:

[0054] 100. Control flow interpreter; 200. Scope manager; 300. Nebula Graph compilation and execution module; 301. GQL compiler; 302. GQL optimizer; 303. GQL execution engine; 400. Security management module; 500. Interpreter sandbox environment; 600. Static code analysis module; 700. Monitoring module. DETAILED DESCRIPTION

[0055] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.

[0056] Example 1

[0057] like Figure 1 As shown, a graph database control flow interpretation and execution system involved in Example 1 of the present application includes:

[0058] The control flow interpreter 100 (ControlFlowInterpreter) is used to parse control flow statements in hybrid scripts, schedule their execution, and manage variables and states throughout the execution process. By embedding control flow statements such as if and while in the Nebula Graph kernel, the native GQL syntax is extended. This allows both native GQL statements and complex process control logic to be written within a single procedure, effectively improving the expressiveness of graph queries.

[0059] In this embodiment, a kernel-level control flow interpreter 100 is used to achieve unified scheduling and seamless integration of control flow statements and native GQL statements on the server side. Control flow logic is directly interpreted and executed within the kernel, while GQL queries follow the efficient compilation and execution process. This design avoids frequent interactions and context switches between the client and server, significantly improving overall execution efficiency and reducing query latency.

[0060] The scope manager 200 (i.e., ScopeManager) is used to manage variables, states, and intermediate results within different scopes using a stack structure. By designing a stack-based scope management module, it realizes the transfer of variable states and intermediate results between different control flow statements, ensuring the accurate and efficient transfer of data states throughout the execution process.

[0061] Nebula Graph's compilation and execution module 300 (NG ExecModule) handles variable binding, compilation, and subsequent execution of native GQL statements. Leveraging the collaborative power of kernel-level interpreted and compiled execution, it optimizes and schedules complex business logic, resulting in higher query efficiency and response speed in typical graph database scenarios, such as financial risk control, social networks, and recommendation systems.

[0062] The control flow interpreter 100, scope manager 200, and Nebula Graph compilation and execution module 300 all run in the Nebula Graph kernel.

[0063] In the Nebula Graph core, native GQL syntax is extended to support control flow statements such as if and while statements. The control flow interpreter 100 first parses the entire hybrid script and schedules execution of different branches on the server based on conditional logic. If a branch contains only native GQL statements, the Nebula Graph compilation and execution module 300 generates an execution plan for execution.

[0064] The control flow is scheduled and executed by the kernel-level extended control flow interpreter 100, while native GQL statements still use the traditional compiled execution model. Both share variables and state within a unified execution environment, leveraging the server's overall execution advantages and avoiding multiple data transfers between the client and server.

[0065] A stack-based scope manager 200 is introduced to manage variable definitions, state caching, and intermediate result transfer within the process. This mechanism ensures that references to previous GQL query results in control flow statements are seamlessly passed to subsequent processing steps, achieving efficient state management.

[0066] It should be noted that in the traditional SDK layer calling solution, multiple network communications are required between each process, resulting in large response delays and high optimization difficulty; this embodiment uniformly processes control flow and GQL queries within the server-side kernel, perceives the entire process as a whole, and can make judgments in advance, execute in batches, and cache status, effectively reducing delays and improving execution efficiency; similar to the stored procedures of relational databases, this system is specially designed for graph database application scenarios to address the lack of support for control flow statements in existing graph databases.

[0067] like Figure 2 As shown in the figure, the Nebula Graph core uses the following layered architecture to achieve hybrid execution:

[0068] Control flow layer:

[0069] This system consists of an extended kernel-level control flow interpreter 100, which parses scripts containing a mix of native GQL and control flow statements (such as if and while), constructs a syntax tree, and schedules the execution of the corresponding flow control statements. Furthermore, the scope manager 200 enables the transfer of variables and intermediate results across statements.

[0070] GQL execution layer:

[0071] The native GQL is kept in compiled execution mode. When called by the control flow interpreter 100, the native GQL statement is bound to variables and converted into an execution plan, which is then executed by the execution engine and the results are fed back to the upper-level control flow interpreter 100 for process control and status update.

[0072] The control flow layer parses the hybrid script. When a control flow statement is encountered, it is executed by the control flow interpreter 100. When a native GQL statement is encountered, it is passed to the GQL execution layer for processing by the compiler and execution engine. The execution result is returned to the control flow layer for control flow decision making and status updates.

[0073] The code for the control flow interpreter 100 to uniformly execute a single statement is as follows:

[0074] @param statement The statement to be executed, which may be a control flow statement or a native GQL statement

[0075] @return ExecutionResult The execution result of a single statement

[0076] /

[0077] ExecutionResult ExecuteStatement(const Statement& statement) {

[0078] if (IsNativeGQL(statement)) {

[0079] / / If it is a native GQL statement, call the corresponding execution function

[0080] return ExecuteNativeGQL(statement);

[0081] } else {

[0082] / / Otherwise, recursively call the interpreter to process control flow statements

[0083] return InterpretControlFlow(statement);

[0084] }

[0085] }.

[0086] The code for the control flow interpreter 100 to execute native GQL statements is as follows:

[0087] * @param gqlStmt contains the native GQL statement

[0088] * @return ExecutionResult GQL statement execution result

[0089] * /

[0090] ExecutionResult ExecuteNativeGQL(const Statement& gqlStmt) {

[0091] / / Bind the variables in the scope to the statement

[0092] Statement boundQuery = BindVariables(gqlStmt, *scopeManager_);

[0093] / / Compile native GQL statements and generate execution plans

[0094] ExecutionPlan plan = ngExecModule_->Compile(boundQuery);

[0095] / / Execute the plan and return the execution result

[0096] ExecutionResult result = ngExecModule_->Execute(plan); 160

[0097] / / Store the results

[0098] scopeManager_->StoreTemp(result);

[0099] return result;

[0100] }.

[0101] The code for executing the control flow statement by the control flow interpreter 100 is as follows:

[0102] * @param statement statement to be executed

[0103] * @return ExecutionResult statement execution result

[0104] * /

[0105] ExecutionResult InterpretControlFlow(const Statement& statement) {

[0106] if (statement.type == StatementType::IF) {

[0107] / / Process IF statement

[0108] return ProcessCondition(statement.condition,statement.thenStatements, statement.elseStatements);

[0109] } else if (statement.type == StatementType::WHILE) {

[0110] / / Processing WHILE statement

[0111] return ProcessLoop(statement.condition, statement.bodyStatements);

[0112] } else if (statement.type == StatementType::SET) {

[0113] / / Process the assignment statement

[0114] return ProcessAssignment(statement.assignmentTarget,statement.assignmentValue).

[0115] In the above examples, at the graph database kernel level, procedural control flow statements (such as IF / ELSE and WHILE) are tightly integrated with native GQL compilation and execution for the first time. This design not only enhances the expressive power of the graph database but also provides a more efficient execution environment for complex graph computations, with the following technological advancements:

[0116] Enhanced graph computing expressiveness: Developers can directly write complex graph algorithms on the server using procedural control flow, such as custom path analysis, risk accumulation, and community evolution, without having to split the algorithm into multiple GQL calls or perform tedious process control on the client.

[0117] Higher execution efficiency: The algorithm's iteration process is all completed within the server, avoiding frequent data transmission and synchronization of intermediate results between the client and server, significantly improving performance;

[0118] Query and analysis performance optimization: Business logic and analysis processes can be pushed down to the server kernel for execution, reducing network communication and data movement and fully leveraging data locality.

[0119] Improve development efficiency and maintainability: Complex business logic and graph algorithms can be implemented centrally on the server side, making the code clearer and easier to maintain, and allowing the application layer to focus more on the business itself.

[0120] To make the graph database control flow interpretation and execution system in this example more efficient, a fine-grained collaboration and feedback mechanism has been designed between the control flow interpreter 100 (responsible for executing control flow statements step by step) and the GQL compiler 301 / GQL optimizer 302 (responsible for processing graph query statements). The core of this mechanism is to enable them to work more closely together and pass information to each other, thereby better adjusting and optimizing scripts that mix control flow and graph queries based on actual execution conditions. Simply put, this allows the interpreter and compiler / optimizer to "communicate" with each other.

[0121] like Figure 3 As shown, Nebula Graph's compilation and execution module 300 includes a GQL compiler 301, a GQL optimizer 302, and a GQL execution engine 303. The control flow interpreter 100 provides runtime context to the GQL compiler 301 (steps 1 & 2). Before the GQL compiler 301 processes a GQL query, the control flow interpreter 100 provides the GQL statement and related runtime context information. For example, if the GQL query is in a loop, the current iteration number, the current values ​​of certain variables in the script, and the approximate number of results obtained by the previous GQL query are displayed. With this real-time information, the GQL compiler 301 can formulate a more appropriate execution plan. The GQL compiler 301 may also provide compile-time feedback to the control flow interpreter 100, such as informing it that a query cannot be fully optimized at compile time because it depends on dynamically changing variables, or suggesting an alternative way to write the query.

[0122] Adjustment based on runtime statistics (steps 3, 4, and 5): When the GQL execution engine 303 performs a data query (step 3), it collects runtime statistics (e.g., actual time spent, data read and written, etc.) (step 4) and communicates this information to the GQL compiler 301 / GQL optimizer 302. After analyzing this data, the GQL compiler 301 / GQL optimizer 302 provides feedback to the control flow interpreter 100 (A) along with some "adjustment suggestions" (step 5). With these suggestions, the control flow interpreter 100 can adjust subsequent operations. For example, if a loop condition is already met or the data distribution is uneconomical, it can terminate the loop early; modify the parameters of subsequent GQL queries; or, if certain conditions change significantly, have the GQL compiler 301 re-formulate the query plan.

[0123] In the above embodiment, the control flow interpreter 100 and the GQL compiler 301 / GQL optimizer 302 no longer operate independently, but instead continuously coordinate and adjust based on the dynamic state of script execution and the actual query results. This allows the entire system to run faster and save server resources when processing complex business logic and graph algorithms.

[0124] To enable the graph database control flow interpretation and execution system of this embodiment to execute control flow scripts more quickly, particularly when the scripts process large amounts of data, a graph data prefetching and cache optimization mechanism, driven proactively by the control flow interpreter 100, has been designed. This mechanism leverages the control flow interpreter 100's ability to "pre-analyze" subsequent operations, enabling the storage and cache systems to prefetch data (read data in advance) and optimize cache usage, thereby reducing the wait time for data during actual query execution.

[0125] like Figure 4 As shown, control flow-based access prediction and data prefetching (steps 1 & 2) are performed: When the control flow interpreter 100 analyzes the script and detects that one or more GQL queries are about to be executed, it analyzes the query pattern of the GQL statement (for example, the types of nodes and edges, and the depth of the query) and combines it with the context of the current control flow (for example, the value of the loop variable, which can be used to predict the specific nodes or edges to be queried). Based on this analysis, the control flow interpreter 100 proactively issues a data prefetch request to the underlying storage engine before the GQL is actually executed (step 1). Upon receiving the request, the storage engine will read the predicted data from the hard disk into the memory cache in the background (step 2).

[0126] Leveraging cached data and guiding cache management (steps 3, 4, and 5): This way, when the GQL execution engine 303 (GQL_Exec) actually begins executing the query (step 3), the data it needs is likely already in the cache. It can quickly retrieve the required data directly from the cache (step 4), eliminating the need to wait for disk I / O. Furthermore, because the control flow interpreter 100 understands the entire control flow logic (for example, which data is repeatedly used in a loop and which data is temporarily unused after a branch is executed), it can provide the cache manager with cache management hints (step 5). For example, it can tell the cache which data is important to retain and which data can be cleared early to make room for more needed data. This allows for more efficient cache usage.

[0127] In the above embodiment, by combining high-level script logic with underlying data management, precise data prefetching and targeted cache optimization prompts driven by the control flow interpreter 100 can significantly reduce data access latency. This significantly improves the performance of the graph database control flow interpretation and execution system of this embodiment when processing graph analysis scripts with large data volumes and requiring repeated calculations.

[0128] In this embodiment, after adding the ability for users to write their own control flow scripts to the graph database kernel, security issues must be considered. For example, this involves preventing user scripts from accessing unauthorized data or excessively consuming server resources. To this end, a security policy-based interpretation and execution permission control and sandboxing mechanism has been designed. This mechanism primarily involves strict permission control and placing scripts in a secure, sandboxed (isolated) environment.

[0129] like Figure 5 As shown, the control flow script submitted by the user must first undergo permission verification by the security management module 400. A user-defined security policy is preset in the security management module 400. After the verification is passed, the execution of the control flow script is allowed, otherwise the execution of the control flow script is rejected. Among them, the control flow script that is allowed to be executed is placed in the interpreter sandbox environment 500 for isolated operation and runs under restricted conditions. The control flow interpreter 100 accesses the graph database function or system resources through a controlled interface.

[0130] When customizing security policies and permissions, system administrators can predefine a detailed set of security policies. These policies may include: which users or roles can execute which scripts and which GQL commands can be called; which data scripts can access (e.g., by data type or tag) and which they cannot access (data access control); which operations scripts can perform (e.g., prohibiting commands to delete data) (operation permission control); and the maximum amount of server resources a script can use (e.g., CPU time, memory size, number of query results, etc.) (resource quota management). Before execution, user-submitted control flow scripts undergo strict permissions verification by the security management module 400 (step 1). Only scripts that fully comply with these rules are allowed to execute.

[0131] The control flow interpreter 100 of a control flow script that has passed permission verification is not allowed to run freely in the system. Instead, it is placed in a specially prepared interpreter sandbox environment 500 (step 2). This interpreter sandbox environment 500 can be implemented using various technologies (such as container technologies like Docker, or by leveraging the security features provided by the scripting language itself). The purpose is to isolate the execution of the control flow script from the rest of the system, limit the underlying system resources and unauthorized data it can directly access, and control the amount of resources it can use.

[0132] In the interpreter sandbox environment 500, when the control flow interpreter 100 executes the control flow script, all access to graph database functions (such as executing GQL queries and calling other kernel functions) or necessary system resources must be conducted through a regulated, secure, and controlled interface (step 3). This controlled interface reconfirms the compliance of the current operation and ensures that the operation is within the current user's permissions and resource limits.

[0133] To further enhance security, the system can incorporate additional support measures. For example, when a user submits a script, the static code analysis module 600 can first scan the code to identify any obvious risks. Meanwhile, while the script is running, a monitoring module 700 can continuously monitor the behavior and resource usage of the control flow interpreter 100. If an anomaly is detected (such as attempting to access something it shouldn't access, or exceeding resource usage), an alarm will be immediately issued or the script will be terminated, and the situation will be recorded (via an audit log).

[0134] In the above-described embodiment, a multi-layered security system is formed through a combination of permission control, sandbox isolation, controlled interface access, and optional static analysis and runtime monitoring. This ensures that the graph database control flow interpretation and execution system of this embodiment not only provides powerful and flexible kernel programming capabilities, but also ensures stability and reliability when used in enterprise and multi-user environments with high requirements for data security, system stability, and resource fairness.

[0135] Example 2

[0136] like Figure 6 As shown, a graph database control flow interpretation and execution method involved in Example 2 of the present application includes:

[0137] The following example describes the execution flow of an if / else statement in detail. The if condition is a simple variable expression, and the then and else branches contain GQL operations for creating and deleting nodes, respectively. The example script is as follows:

[0138] / / Define a variable to control the if condition

[0139] VALUE createNode = true

[0140] IF createNode THEN {

[0141] / / THEN branch: create a new node

[0142] INSERT (n:NewNode {prop1: 'value1', prop2: 123})

[0143] } ELSE {

[0144] / / ELSE branch: delete node

[0145] MATCH (n:ToDelete) DELETE n

[0146] }.

[0147] S101, parsing the if statement in the mixed script: the control flow interpreter 100 parses the entire script and identifies the IF...ELSE... statement block;

[0148] S102. Extract the conditional expression of the if statement and obtain the value of the conditional expression from the scope, wherein the conditional expression is a variable expression createNode. Specifically, extract the conditional expression: createNode from the if statement, which is a variable expression. The control flow interpreter 100 obtains the value of the variable createNode from the current scope, wherein the value of createNode is true or false.

[0149] S103: Determine the value of the conditional expression. If the conditional expression evaluates to true, the then branch statement block is executed. A determination is made as to whether there are any GQL statements (i.e., INSERT statements) within the then branch. The INSERT(n:NewNode{prop1:'value1',prop2:123}) statement is executed. This is a GQL create statement. The control flow interpreter 100 passes this statement to the NebulaGraph compilation and execution module 300 for processing. The Nebula Graph compilation and execution module 300 compiles and executes this statement, creating a new node in the database. If the conditional expression evaluates to false, the else branch statement block is executed. A determination is made as to whether there are any GQL statements (i.e., MATCH statements and DELETE statements) within the else branch.

[0150] S104. If a GQL statement exists, the Nebula Graph compilation and execution module 300 is called to compile and execute the GQL statement. Specifically, if the conditional expression evaluates to true and there is a GQL statement in the then branch, the Nebula Graph compilation and execution module 300 is called to compile and execute the INSERT statement. If the conditional expression evaluates to false and there is a GQL statement in the else branch, the Nebula Graph compilation and execution module 300 is called to compile and execute the MATCH statement and the DELETE statement.

[0151] S105: The execution result of the GQL statement is stored in the scope, and the database status is updated. The INSERT statement usually does not return a result, but it will update the database status. The if / else statement is executed.

[0152] It should be noted that for other specific implementations of the graph database control flow interpretation and execution method in this embodiment, please refer to the specific implementations of the graph database control flow interpretation and execution system mentioned above. To avoid redundancy, they will not be repeated here.

[0153] Example 3

[0154] like Figure 7As shown, a graph database control flow interpretation and execution method involved in Example 3 of the present application includes:

[0155] S201, parsing the while statement in the mixed script;

[0156] S202, initialize the loop counter and record the current loop count: int currentIteration = 0;

[0157] S203, extracting the conditional expression of the while statement and obtaining the value of the conditional expression from the scope;

[0158] S204, judging the value of the conditional expression, if the value of the conditional expression is false, exiting the current loop scope: while (EvaluateExpression(condition));

[0159] If the conditional expression evaluates to true, a new loop scope is created to ensure localization of variables within the loop body: scopeManager_->PushScope(ScopeType::LOOP);

[0160] Traverse and execute each statement in the loop body: for (const auto& stmt : body), use a unified interface to execute statements, and internally determine the statement type: ExecutionResult result = ExecuteStatement(stmt);

[0161] If an interrupt instruction is received or the maximum number of loops is exceeded, the current loop scope is exited: if(result.HasTerminationFlag() || (++currentIteration> MAX_LOOP))

[0162] {

[0163] scopeManager_->PopScope();

[0164] return result;

[0165] }.

[0166] If the loop exits because the condition is not met, the scope cleanup is performed first and then the success status is returned; if the loop exits due to an interrupt instruction, the scope is cleaned up in advance and the interrupt result is passed.

[0167] It should be noted that for other specific implementations of the graph database control flow interpretation and execution method in this embodiment, please refer to the specific implementations of the graph database control flow interpretation and execution system mentioned above. To avoid redundancy, they will not be repeated here.

[0168] Example 4

[0169] like Figure 8 As shown, a graph database control flow interpretation and execution method involved in Example 4 of the present application includes:

[0170] S301. Parse the assignment statement in the mixed script:

[0171] * @param variableName the variable name to be assigned

[0172] * @param valueExpression assignment expression

[0173] * @return ExecutionResult assignment result

[0174] * / ExecutionResult ProcessAssignment(const std::string& variableName,const Expression& valueExpression);

[0175] S302. Extract the expression and value of the assignment statement: Variant value = EvaluateExpression (valueExpression);

[0176] S303. Assign the value of the expression to the specified variable and use scope management to implement variable storage: scopeManager_->SetVariable(variableName, value);

[0177] S304. Return the execution result: return ExecutionResult::Success().

[0178] If an error occurs during expression evaluation or variable assignment, an exception is thrown or an error status is returned.

[0179] It should be noted that for other specific implementations of the graph database control flow interpretation and execution method in this embodiment, please refer to the specific implementations of the graph database control flow interpretation and execution system mentioned above. To avoid redundancy, they will not be repeated here.

[0180] Example 5

[0181] A computer-readable storage medium according to embodiment 5 of the present application, wherein the computer-readable storage medium stores program code for execution by a device, the program code including steps for executing the method in any one of the implementations in embodiment 1 of the present application;

[0182] Among them, the computer-readable storage medium can be a read-only memory (ROM), a static storage device, a dynamic storage device or a random access memory (RAM); the computer-readable storage medium can store program code, and when the program stored in the computer-readable storage medium is executed by the processor, the processor is used to execute the steps of the method in any one of the implementation methods in Example 1 of the present application.

[0183] The above are only preferred specific implementations of this application; however, the scope of protection of this application is not limited thereto. Any person skilled in the art who, within the technical scope disclosed in this application, makes equivalent substitutions or modifications based on the technical solutions and improved concepts of this application shall be covered by the scope of protection of this application.

Claims

1. A graph database control flow interpretation and execution system, characterized by: include: The control flow interpreter is used to parse the control flow statements in the mixed script, schedule the execution of the control flow statements, and manage the variables and states of the overall execution process; Scope manager, which uses a stack structure to manage variables, states, and intermediate results in different scopes; Nebula Graph's compilation and execution module handles variable binding for native GQL statements, compiling them into execution plans, and subsequent plan execution. The control flow interpreter, scope manager, and Nebula Graph compilation and execution module all run in the Nebula Graph kernel.

2. The graph database control flow interpretation and execution system according to claim 1, characterized in that: The control flow statements include if statements, while statements and assignment statements.

3. The graph database control flow interpretation and execution system according to claim 1 or 2, characterized in that: The NebulaGraph compilation and execution module includes a GQL compiler, a GQL optimizer, and a GQL execution engine. The control flow interpreter is also used to provide QGL statements and their runtime context to the GQL compiler and GQL optimizer. The GQL compiler is used to formulate an execution plan based on the QGL statements and their runtime context and send it to the control flow interpreter. The GQL optimizer is used to return compiler feedback to the control flow interpreter based on the QGL statements and their runtime context. The GQL execution engine is used to collect GQL statement runtime statistics and send them to the GQL compiler and GQL optimizer. The GQL compiler and GQL optimizer are also used to analyze the GQL statement runtime statistics to obtain analysis results and adjustment suggestions and feed them back to the control flow interpreter.

4. The graph database control flow interpretation and execution system according to claim 3, characterized in that: The control flow interpreter is also used to pre-analyze subsequent operations so that the storage system and cache system can read data in advance and optimize cache usage.

5. The graph database control flow interpretation and execution system according to any one of claims 1, 2 and 4, characterized in that: It also includes a security management module and an interpreter sandbox environment. The security management module is used to define security policies and perform permission checks on control flow scripts based on the security policies. Control flow scripts that pass the permission check are placed in the interpreter sandbox environment for isolated operation. The interpreter sandbox environment accesses graph database functions or system resources through a controlled interface. The controlled interface is used to reconfirm whether the operations of the control flow interpreter when executing the script comply with the security policy.

6. The graph database control flow interpretation and execution system according to claim 5, characterized in that: It also includes a static code analysis module and a monitoring module. The static code analysis module is used to perform risk scanning on the control flow script before the security management module performs permission verification on the control flow script. The monitoring module is used to monitor the running control flow script and issue an alarm or terminate the operation of the control flow script if an abnormality is found.

7. A graph database control flow interpretation and execution method, characterized in that: The system according to any one of claims 1 to 6, wherein the method comprises: Parsing if statements in mixed scripts; Extract the conditional expression of the if statement and obtain the value of the conditional expression from the scope, wherein the conditional expression is the variable expression createNode; Determine the value of the conditional expression. If the value of the conditional expression is true, execute the then branch statement block and determine whether there is a GQL statement in the then branch. Otherwise, execute the else branch statement block and determine whether there is a GQL statement in the else branch. If there is a GQL statement, the Nebula Graph compilation and execution module is called to compile and execute the GQL statement. Store the execution results of the GQL statement in the scope and update the database status.

8. The graph database control flow interpretation and execution method according to claim 7, characterized in that: If the conditional expression evaluates to true and there is a GQL statement in the then branch, the Nebula Graph compilation and execution module is called to compile and execute the INSERT statement. If the conditional expression evaluates to false and there is a GQL statement in the else branch, the Nebula Graph compilation and execution module is called to compile and execute the MATCH and DELETE statements.

9. A graph database control flow interpretation and execution method, characterized in that: The system according to any one of claims 1 to 6, wherein the method comprises: Parse while statements in mixed scripts; Initialize the loop counter and record the current loop count; Extract the conditional expression of the while statement and obtain the value of the conditional expression from the scope; Determine the value of the conditional expression. If the conditional expression is true, exit the current loop scope. Otherwise, create a new loop scope, ensure that the variables in the loop body are localized, traverse and execute each statement in the loop body, determine the statement type and execute the statement. If an interrupt instruction is received or the maximum number of loops is exceeded, exit the current loop scope. If the loop exits because the condition is not met, the scope cleanup is performed first and then the success status is returned; if the loop exits due to an interrupt instruction, the scope is cleaned up in advance and the interrupt result is passed.

10. A graph database control flow interpretation and execution method, characterized in that: The system according to any one of claims 1 to 6, wherein the method comprises: Parsing assignment statements in mixed scripts; Extract the expression and value of the assignment statement; Assign the value of the expression to the specified variable and use scope management to implement variable storage. If an error occurs during expression calculation or variable assignment, an exception is thrown or an error status is returned. Returns the execution result.