Database stored procedure execution methods, apparatus, and computer equipment

By determining the target branch of a stored procedure in a distributed database and executing the data to be executed in parallel, the problem of slow processing speed of traditional stored procedures for large amounts of data is solved, achieving more efficient data processing.

CN117149770BActive Publication Date: 2025-11-14JINZHUAN INFORMATION TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311117631.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-31
Publication Date
2025-11-14
Estimated Expiration
2043-08-31

AI Technical Summary

Technical Problem

In distributed databases, traditional stored procedures need to be executed serially when processing large amounts of data, resulting in slow data processing speed and failing to meet users' real-time business needs.

Method used

By obtaining the execution parameters of the data to be executed, calling the judgment conditions of the stored procedure, determining the target branch, and executing the data through that branch, parallel processing of multiple data to be executed can be achieved.

Benefits of technology

It improves the efficiency of data execution, avoids the occupation of the entire storage process, and meets the real-time business needs of users.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117149770B_ABST
    Figure CN117149770B_ABST
Patent Text Reader

Abstract

This disclosure provides a method, apparatus, and computer device for executing stored procedures in a database. The method includes: acquiring data to be executed and determining execution parameters of the data to be executed; invoking a judgment condition corresponding to the stored procedure and determining a target branch corresponding to the execution parameters in the stored procedure based on the judgment condition; and executing the data to be executed through the target branch. This improves the efficiency of data execution by allowing multiple data items to be executed to be executed in parallel through different branches of the stored procedure without occupying the entire stored procedure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of database technology, and more specifically, to a method, apparatus, and computer device for executing stored procedures in a database. Background Technology

[0002] In the database field, a stored procedure is a set of SQL statements designed to perform a specific function. After being compiled for the first time, it is stored in the database and executed directly each time it is called, without being recompiled.

[0003] With the development and popularization of the internet, the amount of business data in enterprises is constantly increasing. Faced with the real-time business needs in massive data scenarios, traditional single-machine databases have reached their performance bottlenecks. More and more enterprises are choosing to use distributed databases composed of multiple nodes to complete the storage and processing of business data. However, in existing distributed database technologies, when encountering large amounts of data that require stored procedure determination, the data can still only pass through the stored procedures serially. It takes a lot of time for all the data to be executed, resulting in slow data processing speed, which often fails to meet the user's needs. Summary of the Invention

[0004] This disclosure provides at least a method, apparatus, and computer device for executing stored procedures in a database.

[0005] In a first aspect, embodiments of this disclosure provide a method for executing a stored procedure in a database, comprising:

[0006] Obtain the data to be executed and determine the execution parameters of the data to be executed;

[0007] Invoke the judgment condition corresponding to the stored procedure, and based on the judgment condition, determine the target branch corresponding to the execution parameter in the stored procedure;

[0008] The data to be executed is executed through the target branch.

[0009] In one optional implementation, determining the target branch corresponding to the execution parameters in the stored procedure based on the judgment condition includes:

[0010] The execution parameters are judged based on the judgment conditions to obtain the judgment result;

[0011] Among multiple execution branches, the target branch that matches the judgment result is determined.

[0012] In one optional implementation, the target branch includes: a Structured Query Language (SQL) statement;

[0013] The step of executing the data to be executed through the target branch includes:

[0014] When the SQL statement includes a static SQL statement, the data to be executed is executed according to the execution order of the statements indicated by the target branch.

[0015] In an optional implementation, executing the data to be executed through the target branch further includes:

[0016] When the SQL statement includes a dynamic SQL statement, the variables in the dynamic SQL statement are assigned values ​​based on the data to be executed to obtain an assignment SQL statement;

[0017] Based on the assigned SQL statement, a target database for executing the data to be executed is determined, and the data to be executed is executed according to the target database.

[0018] In one optional implementation, the target branch includes: a conditional statement;

[0019] The step of executing the data to be executed through the target branch includes:

[0020] The conditional statement is used to evaluate the data to be executed and to determine the sub-branch that matches the evaluation result.

[0021] Based on the sub-branch, execute the data to be executed.

[0022] In one optional implementation, the method further includes:

[0023] During the execution of the data to be executed, the thread corresponding to the target branch is determined to be in a blocked state;

[0024] The blocking state ends after all sub-branches of the target branch have been executed.

[0025] In one optional implementation, the method further includes:

[0026] The stored procedure is parsed to obtain at least one conditional statement;

[0027] The stored procedure is divided according to each of the conditional statements, and corresponding execution branches are established.

[0028] Secondly, embodiments of this disclosure also provide a stored procedure execution apparatus for a database, comprising:

[0029] A determining unit is used to acquire data to be executed and determine the execution parameters of the data to be executed;

[0030] The calling unit is used to call the judgment condition corresponding to the stored procedure, and based on the judgment condition, determine the target branch corresponding to the execution parameter in the stored procedure;

[0031] An execution unit is used to execute the data to be executed through the target branch.

[0032] Thirdly, embodiments of this disclosure also provide a computer device, including: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the computer device is running, the processor communicates with the memory via the bus, and when the machine-readable instructions are executed by the processor, the steps of the first aspect above, or any possible implementation of the first aspect, are performed.

[0033] Fourthly, this application also provides a computer storage medium storing computer-executable instructions for executing the stored procedure execution method of the database described in any of the preceding claims of this application.

[0034] Compared with the prior art, the above-mentioned technical solution provided in this application has the following advantages: The method provided in this application can first obtain the data to be executed and determine the execution parameters of the data to be executed. Then, it calls the judgment condition corresponding to the stored procedure and, based on the judgment condition, determines the target branch of the execution parameters in the stored procedure so as to execute the data to be executed through the target branch. Thus, when processing the data to be executed, it is not necessary to occupy the entire stored procedure. Instead, multiple data to be executed can be executed in parallel through different branches in the stored procedure, thereby improving the efficiency of data execution. Attached Figure Description

[0035] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.

[0036] Figure 1 A flowchart illustrating a database stored procedure execution method provided in an embodiment of this disclosure is shown;

[0037] Figure 2 This diagram illustrates the execution process of the stored procedure operationFlow provided in an embodiment of this disclosure.

[0038] Figure 3 A flowchart illustrating the database stored procedure execution method provided in this embodiment of the present disclosure is shown.

[0039] Figure 4 A schematic diagram of a database stored procedure execution apparatus provided in an embodiment of this disclosure is shown;

[0040] Figure 5 A schematic diagram of a computer device provided in an embodiment of this disclosure is shown. Detailed Implementation

[0041] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.

[0042] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0043] In this document, the term "and / or" merely describes a relationship, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Furthermore, the term "at least one" in this document means any combination of at least two of any one or more elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.

[0044] Research has shown that in the database field, a stored procedure is a set of SQL statements designed to perform a specific function. After its first compilation, it is stored in the database and executed directly each time it is called, without being recompiled.

[0045] With the development and popularization of the internet, the amount of business data in enterprises is constantly increasing. Faced with the real-time business needs in massive data scenarios, traditional single-machine databases have reached their performance bottlenecks. More and more enterprises are choosing to use distributed databases composed of multiple nodes to complete the storage and processing of business data. However, in existing distributed database technologies, when encountering large amounts of data that require stored procedure determination, the data can still only pass through the stored procedures serially. It takes a lot of time for all the data to be executed, resulting in slow data processing speed, which often fails to meet the user's needs.

[0046] Based on the above research, this disclosure provides a method, apparatus, and computer device for executing stored procedures in a database. In the embodiments of this disclosure, the data to be executed can first be obtained and the execution parameters of the data to be executed can be determined. Then, the judgment condition corresponding to the stored procedure is called, and based on the judgment condition, the target branch of the execution parameters in the stored procedure is determined so that the data to be executed can be executed through the target branch. Thus, when processing the data to be executed, it is not necessary to occupy the entire stored procedure. Instead, multiple data to be executed can be executed in parallel through different branches of the stored procedure, thereby improving the efficiency of data execution.

[0047] To facilitate understanding of this embodiment, a database stored procedure execution method disclosed in this disclosure will first be described in detail. The execution subject of the database stored procedure execution method provided in this disclosure is generally a computer device with a certain computing power. In some possible implementations, the database stored procedure execution method can be implemented by a processor calling computer-readable instructions stored in memory.

[0048] See Figure 1 The diagram shows a flowchart of a database stored procedure execution method according to an embodiment of this disclosure. The method includes steps S101 to S105, wherein:

[0049] S101: Obtain the data to be executed and determine the execution parameters of the data to be executed.

[0050] As can be seen from the above, a stored procedure is a set of SQL statements designed to perform a specific function. Therefore, the above execution parameters can be used as the running parameters of the SQL statements in the stored procedure.

[0051] For example, if the specific function to be performed by the stored procedure is to push data to accounts with a registration period of more than X, then the stored procedure includes SQL statements for filtering accounts with a registration period of more than X.

[0052] After obtaining the data to be executed, if the execution parameter corresponding to the data to be executed is a registration period of 2 years, then the execution parameter can be passed into the above stored procedure as the running parameter of the SQL statement, so as to filter out accounts with a registration period of more than 2 years through the SQL statement.

[0053] S103: Invoke the judgment condition corresponding to the stored procedure, and based on the judgment condition, determine the target branch corresponding to the execution parameter in the stored procedure.

[0054] S105: Execute the data to be executed through the target branch.

[0055] In this embodiment of the disclosure, the above-mentioned judgment condition may include a conditional expression. Based on this, the above-mentioned execution parameters can be passed into the conditional expression to obtain the judgment result and determine the target branch that matches the judgment result.

[0056] It should be understood that, according to the execution logic of the above-mentioned stored procedure, the stored procedure can be pre-divided into multiple execution branches, where each execution branch can correspond to at least one piece of execution logic.

[0057] For example, if the function of the above stored procedure is to process user data based on the user's age, then the conditional statement above could be to determine whether the user's age is greater than 50 years old. If yes, then execute branch 1; if no, then execute branch 2. If the execution parameter corresponding to the data to be executed is 20 years old, then the result is no, and the target branch corresponding to this data to be executed is branch 2.

[0058] As described above, in this embodiment of the present disclosure, the data to be executed can first be obtained and the execution parameters of the data to be executed can be determined. Then, the judgment condition corresponding to the stored procedure is called, and based on the judgment condition, the target branch of the execution parameters in the stored procedure is determined so that the data to be executed can be executed through the target branch. Thus, when processing the data to be executed, it is not necessary to occupy the entire stored procedure. Instead, multiple data to be executed can be executed in parallel through different branches of the stored procedure, thereby improving the efficiency of data execution.

[0059] In an optional implementation, step S103 above, which determines the target branch corresponding to the execution parameter in the stored procedure based on the judgment condition, specifically includes the following process:

[0060] S1031: Based on the judgment condition, the execution parameters are judged to obtain the judgment result.

[0061] S1032: Among multiple execution branches, determine the target branch that matches the judgment result.

[0062] In this embodiment of the disclosure, the above-mentioned judgment condition includes a conditional expression, and the judgment result is used to indicate whether the execution parameter satisfies the judgment condition indicated by the conditional expression. For example, the conditional expression can be used to determine whether the execution parameter of the data to be executed is greater than 50.

[0063] It should be understood that, according to the execution logic of the stored procedure described above, the stored procedure can be pre-divided into multiple execution branches, where each execution branch can correspond to at least one piece of execution logic. Here, the conditional expression described above can be used to indicate the logical segmentation nodes in the execution logic.

[0064] For example, in a distributed database, company A writes its business logic as a stored procedure called operationFlow. This stored procedure corresponds to several input parameters (inputOptions), and can perform business logic judgments based on conditional expressions of the input parameters (such as expression_1), thereby executing SQL statement sets (SQLs) within different conditional branches. The execution process of this stored procedure is as follows:

[0065] create procedure operationFlow(IN inputOptions)

[0066] Begin IF expression_1(inputOptions)THEN

[0067] / / Branch 1

[0068] SQLs_1;

[0069] ELSE expression_2(inputOptions)THEN

[0070] / / Branch 2

[0071] SQLs_2;

[0072] IF expression_2_1(inputOptions)THEN

[0073] / / Branch 2_1

[0074] SQLs_2_1;

[0075] ELSE

[0076] / / Branch 2_2

[0077] SQLs_2_2;

[0078] END IF;

[0079] ELSE

[0080] / / Branch 3

[0081] SQLs_3;

[0082] END IF;

[0083] END.

[0084] The judgment conditions in the above stored procedure include condition expression 1: IF expression_1(inputOptions)THEN, ELSE expression_2(inputOptions)THEN and condition expression 2: IF expression_2_1(inputOptions)THEN, ELSE.

[0085] In practice, the execution parameters of the data to be executed can be first passed to conditional expression 1. If the execution parameters match expression_1, the data to be executed is executed through branch 1. If they do not match expression_1, it is determined whether the execution parameters match expression_2. If they match, branch 2 is executed; otherwise, branch 3 is executed.

[0086] In this embodiment of the disclosure, the stored procedure can be pre-divided into multiple execution branches according to the execution logic of the stored procedure described above. Each execution branch can correspond to at least one piece of execution logic, so that multiple pieces of data to be executed can be executed in parallel by multiple branches, so that the data to be executed does not need to go through the stored procedure serially, thereby improving the data execution efficiency.

[0087] In an optional implementation, the target branch includes: a Structured Query Language (SQL) statement; step S105, executing the data to be executed through the target branch, includes:

[0088] When the SQL statement includes a static SQL statement, the data to be executed is executed according to the execution order of the statements indicated by the target branch.

[0089] In the embodiments of this disclosure, the strings in the above static SQL statement are fixed. For example, the static SQL statement can be used to instruct the data to be executed to be stored in a specified storage location in the database.

[0090] Considering that the target branch usually consists of a set of SQL statements (SQLs), the SQL statements can be executed sequentially according to the execution order indicated by the set of SQLs.

[0091] It should be understood that the above distributed database typically includes multiple database nodes, and each database node can correspond to at least one database transaction. Therefore, when executing the statement set SQLs in the target branch according to the above statement execution order, the statement set SQLs can be executed once under each database transaction.

[0092] In this embodiment of the disclosure, the data to be executed can be executed in the order of statement execution indicated by the target branch, thereby executing the data to be executed through the target branch without occupying the entire stored procedure.

[0093] In an optional implementation, step S105 above, which involves executing the data to be executed through the target branch, further includes the following process:

[0094] S11: When the SQL statement includes a dynamic SQL statement, the variables in the dynamic SQL statement are assigned values ​​based on the data to be executed to obtain the assignment SQL statement.

[0095] S12: Based on the assignment SQL statement, determine the target database for executing the data to be executed, and execute the data to be executed according to the target database.

[0096] In this embodiment of the disclosure, the dynamic SQL statement described above contains strings whose variables cannot be determined at compile time. Therefore, it is necessary to assign values ​​to these variables based on the data to be executed. For example, this dynamic SQL statement is used to filter out accounts with a registration period exceeding A. The value of A depends on the number of data entries x in the data to be executed, i.e., A = x / b.

[0097] After assigning values ​​to variables in a dynamic SQL statement to obtain the assignment SQL statement, it can be executed. Considering that in the aforementioned distributed database, the assignment SQL statement may involve multiple database nodes during execution, the corresponding database node in the distributed database can be determined to obtain the target database.

[0098] In this embodiment of the disclosure, after determining the above assignment SQL statement, the assignment SQL statement can be merged and the merged content can be sent to the target database for execution, so as to reduce the number of communication between database nodes and thus reduce communication consumption.

[0099] In an optional implementation, the target branch includes a conditional statement. Step S105, which executes the data to be executed through the target branch, specifically includes the following process:

[0100] S21: The conditional statement is used to judge the data to be executed, and the sub-branch that matches the judgment result is determined.

[0101] S22: Based on the sub-branch, execute the data to be executed.

[0102] In this embodiment of the disclosure, considering that the above-mentioned stored procedure may include multiple conditional statements, nested execution conditional statements can be used, wherein the conditional statement is the above-mentioned conditional expression. Here, the above-mentioned stored procedure operationFlow is taken as an example.

[0103] In branch 2 of the above stored procedure operationFlow, there is a conditional expression expression_2_1(inputOptions)THEN,ELSE. If the result of the conditional expression on the execution parameters of the data to be executed matches expression_2_1, then subbranch 2_1 is determined as the matching subbranch; if the result does not match expression_2_1, then subbranch 2_2 is determined as the matching subbranch.

[0104] Once a sub-branch is identified, the data to be executed can be processed based on that sub-branch. It should be understood that conditional statements can be nested within sub-branches. This disclosure does not impose a specific limit on the number of nesting levels; the actual usage requirements shall prevail.

[0105] In this embodiment of the disclosure, considering that the above-mentioned stored procedure may include multiple conditional statements, the conditional statements can be nested to improve the execution process of the statements in the stored procedure.

[0106] In an optional implementation, step S105 above further includes the following process:

[0107] (1) During the execution of the data to be executed, the thread corresponding to the target branch is determined to be in a blocked state;

[0108] (2) After all sub-branches of the target branch have been executed, the blocking state ends.

[0109] In this embodiment of the disclosure, when the thread corresponding to the target branch is in a blocked state, it cannot respond to processing requests for other pending data. Therefore, when executing a sub-branch within the target branch, it is necessary to adjust the state of the thread corresponding to the target branch to a blocked state.

[0110] After the SQL statements in the sub-branch have been executed, the sub-branch can send the execution results back to the target branch. Once the target branch has determined that all the SQL statements in the sub-branch have been executed based on the received execution results, it can confirm that the data to be executed has been completed and end the blocking state of the target branch, so that the target branch can continue to execute the data received next.

[0111] In this embodiment of the disclosure, when executing a sub-branch in the target branch, the state of the target branch can be adjusted to a blocked state, thereby avoiding conflicts between the sub-branches in the target branch during execution, which could lead to execution failure.

[0112] In an optional implementation, the above Figure 1 The corresponding embodiment also includes the following process:

[0113] (1) Parse the stored procedure to obtain at least one conditional statement;

[0114] (2) The stored procedure is divided according to each of the conditional statements, and corresponding execution branches are established.

[0115] In this embodiment of the disclosure, when a stored procedure includes conditional statements, these conditional statements can be used as delimiters to segment the stored procedure, thereby obtaining execution branches corresponding to each conditional statement. Here, the set of SQL statements (SQLs) between the current conditional statement and the next conditional statement can be combined with the current conditional statement to obtain an execution branch.

[0116] Here, as Figure 2 The diagram illustrates the execution process of the stored procedure `operationFlow`. First, based on the conditional expressions 1 (`IF expression_1()THEN, ELSE expression_2()THEN`) and 2 (`IF expression_2_1()THEN, ELSE`), the stored procedure is divided into three execution branches: branch 1, branch 2, and branch 3. Within branch 2, further division is achieved using conditional expression 3 (`IF expression_2_1()THEN, ELSE`), resulting in branch 2_1 and branch 2_2.

[0117] Specifically, when performing branch determination on the data to be executed through the above stored procedure operationFlow, if the number of data to be executed is 100,000, the condition of expression_1() and expression_2() in the expression can be used to determine the data. k1 data will be classified as branch 1, k2 data as branch 2, and k3 data as branch 3. Separate execution threads will be created for different branches to execute the statements in the branches in batches.

[0118] Next, for branch 2, a sub-branch judgment will be performed: based on the condition of expression_2_1() in conditional expression 3, k will be judged. 2_1 The data is categorized into branch 2_1, and k 2_2 The data is categorized into branches 2_2, and separate threads are created for different branches to execute the statements within each branch in batches. After branches 2_1 and 2_2 have finished executing, the execution result is returned to branch 2, and branch 2 is woken up to end its blocked state and continue execution. When branches 1, 2, and 3 have all finished executing, the stored procedure for 100,000 data entries ends.

[0119] In this embodiment of the disclosure, the stored procedure can be divided according to the conditional statements in the stored procedure, and corresponding execution branches can be established so that the data to be executed can be processed in parallel through multiple execution branches, thereby improving the processing efficiency of the stored procedure when processing the data to be executed.

[0120] See Figure 3 The diagram shown is a flowchart illustrating the database stored procedure execution method provided in this embodiment of the present disclosure. The specific process is as follows:

[0121] In this embodiment, the stored procedure is first compiled to obtain the machine language corresponding to the stored procedure. Then, the aforementioned judgment conditions in the compiled stored procedure are used to determine the branch of a large dataset of data to be executed, and the judgment result is obtained. Here, based on the judgment result, the target branch corresponding to dataset 1 is determined to be branch 1, and the target branches corresponding to datasets 2-N are determined to be branches 2-N.

[0122] Taking thread 1 corresponding to branch 1 as an example, when executing the statement in branch 1, the statement type can be determined first. If the statement is the above SQL statement (including static SQL statement and dynamic SQL statement), then the SQL statement is batch processed, that is, the SQL is sent to the corresponding database node for execution.

[0123] If the statement is determined to be a conditional statement as described above, then a sub-branch decision is made. It should be understood that when executing a sub-thread, the above branch 1 can be adjusted to a blocked state, and after all n sub-branches in branch 1 have been executed, thread 1 is woken up.

[0124] It should be understood that the specific execution process of branches 2-N can be referred to as the execution process of branch 1, and will not be described in detail in this disclosure.

[0125] In summary, in this embodiment of the present disclosure, the data to be executed can first be obtained and the execution parameters of the data to be executed can be determined. Then, the judgment condition corresponding to the stored procedure is called, and based on the judgment condition, the target branch of the execution parameters in the stored procedure is determined so that the data to be executed can be executed through the target branch. Thus, when processing the data to be executed, it is not necessary to occupy the entire stored procedure. Instead, multiple data to be executed can be executed in parallel through different branches of the stored procedure, thereby improving the efficiency of data execution.

[0126] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.

[0127] Based on the same inventive concept, this disclosure also provides a database stored procedure execution device corresponding to the database stored procedure execution method. Since the principle of the device in this disclosure for solving the problem is similar to the database stored procedure execution method described above in this disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.

[0128] Reference Figure 4 The diagram shown is a schematic of a database stored procedure execution device according to an embodiment of this disclosure. The device includes: a determining unit 41, a calling unit 42, and an execution unit 43; wherein,

[0129] The determining unit 41 is used to acquire the data to be executed and determine the execution parameters of the data to be executed;

[0130] Calling unit 42 is used to call the judgment condition corresponding to the stored procedure, and based on the judgment condition, determine the target branch corresponding to the execution parameter in the stored procedure;

[0131] Execution unit 43 is used to execute the data to be executed through the target branch.

[0132] In this embodiment of the disclosure, the data to be executed can first be obtained and the execution parameters of the data to be executed can be determined. Then, the judgment condition corresponding to the stored procedure is called, and based on the judgment condition, the target branch of the execution parameters in the stored procedure is determined so that the data to be executed can be executed through the target branch. Thus, when processing the data to be executed, it is not necessary to occupy the entire stored procedure. Instead, multiple data to be executed can be executed in parallel through different branches of the stored procedure, thereby improving the efficiency of data execution.

[0133] In one possible implementation, the calling unit 42 is further configured to:

[0134] The execution parameters are judged based on the judgment conditions to obtain the judgment result;

[0135] Among multiple execution branches, the target branch that matches the judgment result is determined.

[0136] In one possible implementation, the target branch includes: a Structured Query Language (SQL) statement, and execution unit 43 is further configured to:

[0137] When the SQL statement includes a static SQL statement, the data to be executed is executed according to the execution order of the statements indicated by the target branch.

[0138] In one possible implementation, execution unit 43 is further configured to:

[0139] When the SQL statement includes a dynamic SQL statement, the variables in the dynamic SQL statement are assigned values ​​based on the data to be executed to obtain an assignment SQL statement;

[0140] Based on the assigned SQL statement, a target database for executing the data to be executed is determined, and the data to be executed is executed according to the target database.

[0141] In one possible implementation, the target branch includes: a conditional statement, and the execution unit 43 is further configured to:

[0142] The conditional statement is used to evaluate the data to be executed and to determine the sub-branch that matches the evaluation result.

[0143] Based on the sub-branch, execute the data to be executed.

[0144] In one possible implementation, execution unit 43 is further configured to:

[0145] During the execution of the data to be executed, the thread corresponding to the target branch is determined to be in a blocked state;

[0146] The blocking state ends after all sub-branches of the target branch have been executed.

[0147] In one possible implementation, the device is also used for:

[0148] The stored procedure is parsed to obtain at least one conditional statement;

[0149] The stored procedure is divided according to each of the conditional statements, and corresponding execution branches are established.

[0150] The description of the processing flow of each unit in the device and the interaction flow between each unit can be found in the relevant descriptions in the above method embodiments, and will not be detailed here.

[0151] Corresponding to Figure 1 The present disclosure also provides a computer device 500, such as a method for executing stored procedures in a database. Figure 5 The diagram shown is a structural schematic of a computer device 500 provided in an embodiment of this disclosure, including:

[0152] The system includes a processor 51, a memory 52, and a bus 53. The memory 52 stores execution instructions and includes main memory 521 and external memory 522. The main memory 521, also called internal memory, temporarily stores the processing data in the processor 51, as well as data exchanged with external memory such as a hard disk. The processor 51 exchanges data with the external memory 522 through the main memory 521. When the computer device 500 is running, the processor 51 communicates with the memory 52 through the bus 53, causing the processor 51 to execute the following instructions:

[0153] Obtain the data to be executed and determine the execution parameters of the data to be executed;

[0154] Invoke the judgment condition corresponding to the stored procedure, and based on the judgment condition, determine the target branch corresponding to the execution parameter in the stored procedure;

[0155] The data to be executed is executed through the target branch.

[0156] This disclosure also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the database stored procedure execution method described in the above method embodiments. The storage medium can be a volatile or non-volatile computer-readable storage medium.

[0157] This disclosure also provides a computer program product carrying program code. The program code includes instructions that can be used to execute the steps of the database stored procedure execution method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.

[0158] The aforementioned computer program product can be implemented through hardware, software, or a combination thereof. In one optional embodiment, the computer program product is specifically embodied in a computer storage medium; in another optional embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.

[0159] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.

[0160] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0161] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0162] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0163] Finally, it should be noted that the above-described embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.

Claims

1. A method for executing a stored procedure in a database, characterized in that, include: Parse the stored procedure to obtain at least one conditional statement; The stored procedure is divided according to each of the conditional statements, and corresponding execution branches are established; Create separate execution threads for different branches to execute the statements within each branch in batches; Obtain the data to be executed and determine the execution parameters of the data to be executed; The judgment condition corresponding to the stored procedure is invoked, and the execution parameters are judged based on the judgment condition to obtain the judgment result; Among the multiple execution branches, a target branch that matches the judgment result is determined; The data to be executed is executed through the target branch.

2. The method according to claim 1, characterized in that, The target branch includes: Structured Query Language (SQL) statements; The step of executing the data to be executed through the target branch includes: When the SQL statement includes a static SQL statement, the data to be executed is executed according to the execution order of the statements indicated by the target branch.

3. The method according to claim 2, characterized in that, The step of executing the data to be executed through the target branch further includes: When the SQL statement includes a dynamic SQL statement, the variables in the dynamic SQL statement are assigned values ​​based on the data to be executed to obtain an assignment SQL statement; Based on the assigned SQL statement, a target database for executing the data to be executed is determined, and the data to be executed is executed according to the target database.

4. The method according to claim 1, characterized in that, The target branch includes: conditional statements; The step of executing the data to be executed through the target branch includes: The conditional statement is used to evaluate the data to be executed and to determine the sub-branch that matches the evaluation result. Based on the sub-branch, execute the data to be executed.

5. The method according to claim 4, characterized in that, The method further includes: During the execution of the data to be executed, the thread corresponding to the target branch is determined to be in a blocked state; The blocking state ends after all sub-branches of the target branch have been executed.

6. A storage procedure execution device for a database, characterized in that, include: A determining unit is used to parse the stored procedure to obtain at least one conditional statement; and to segment the stored procedure according to each conditional statement to establish corresponding execution branches; Create separate execution threads for different branches to execute the statements within each branch in batches; Obtain the data to be executed and determine the execution parameters of the data to be executed; The calling unit is used to call the judgment condition corresponding to the stored procedure, and judge the execution parameters based on the judgment condition to obtain the judgment result; Among the multiple execution branches, a target branch that matches the judgment result is determined; An execution unit is used to execute the data to be executed through the target branch.

7. A computer device, characterized in that, include: The computer device includes a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, they perform the steps of the stored procedure execution method for a database as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the database stored procedure execution method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method, device and system for executing stored procedure

    CN110121704A

  • Data processing method, database management system and data processing equipment

    CN112749156A