Database operation method, compiler, and computer-readable storage medium

By introducing package and function concepts into the compiler, generating SQL syntax trees and using SQL dialect conversion rules to adapt to different databases, the problem of SQL code redundancy and SQL statements between databases in Internet projects is solved, and development efficiency is improved and flexibility in database operations.

WO2024230298A1PCT designated stage expired Publication Date: 2024-11-14ZTE CORP

Patent Information

Application Number
PCT/CN2024/080790
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-05-08
Filing Date
2024-03-08
Publication Date
2024-11-14

AI Technical Summary

Technical Problem

As the business demand for databases increases in Internet projects, developers need to write a large number of duplicate SQL code, resulting in redundant code, and the SQL dialects of different databases have differences, resulting in inefficient development.

Method used

By introducing package and function concepts into the compiler, an SQL syntax tree is generated and the database is operated based on this syntax tree, code redundancy is reduced, and different databases are adapted to SQL dialect conversion rules.

Benefits of technology

It realizes code reuse and redundancy reduction, improves development efficiency, solves the problem of non-common SQL statements between different databases, and improves the flexibility and efficiency of database operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024080790_14112024_PF_FP_ABST
    Figure CN2024080790_14112024_PF_FP_ABST
Patent Text Reader

Abstract

Provided are a database operation method, a compiler, and a computer-readable storage medium. The database operation method comprises: acquiring an operation request of a database, wherein the operation request comprises a target SQL statement, calling of a first function is present in the target SQL statement, and the first function is a sub-program pre-edited for achieving a sub-function of a service; acquiring an execution result of the first function when the first function is called in the target SQL statement; generating a target SQL syntax tree according to the target SQL statement and the execution result of the first function, wherein the target SQL syntax tree is a graphical representation of a syntax structure of the target SQL statement, a node in the target SQL syntax tree is an SQL syntax node, and the target SQL syntax tree comprises an SQL syntax node corresponding to the execution result of the first function; and operating data in a target database on the basis of the target SQL syntax tree.
Need to check novelty before this filing date? Find Prior Art

Description

Database operation method, compiler, and computer-readable storage medium

[0001] This disclosure claims priority to Chinese patent application No. 202310517571.1, filed on May 8, 2023, the entire contents of which are incorporated herein by reference. Technical Field

[0002] The present disclosure relates to the field of database technology, and in particular to a database operation method, a compiler, and a computer-readable storage medium. Background Art

[0003] As we all know, Structured Query Language (SQL) is a commonly used language for data analysis and data processing in databases; various business requirements for databases can be implemented based on the SQL language.

[0004] Summary of the Invention

[0005] In one aspect, an embodiment of the present disclosure provides a database operation method, which is applied to a compiler. The database operation method includes: obtaining a database operation request, the operation request including: a target SQL statement, the target SQL statement including a call to a first function, the first function being a pre-edited subroutine for implementing a business sub-function; obtaining the execution result of the first function when the first function is called in the target SQL statement; generating a target SQL syntax tree based on the target SQL statement and the execution result of the first function, the target SQL syntax tree being a graphical representation of the grammatical structure of the target SQL statement, the nodes in the target SQL syntax tree being SQL syntax nodes, the target SQL syntax tree including SQL syntax nodes corresponding to the execution result of the first function; and operating on data in a target database based on the target SQL syntax tree.

[0006] On the other hand, an embodiment of the present disclosure provides a compiler. The compiler includes:

[0007] The transceiver unit is used to obtain an operation request from a database, wherein the operation request includes: a target SQL statement, wherein the target SQL statement contains a call to a first function; the first function is a subroutine pre-edited to implement a sub-function of a business.

[0008] The transceiver unit is further configured to obtain an execution result of the first function when the first function is called in the target SQL statement.

[0009] A processing unit is used to generate a target SQL syntax tree based on the target SQL statement and the execution result of the first function; the target SQL syntax tree is a graphical representation of the syntax structure of the target SQL statement, the nodes in the target SQL syntax tree are SQL syntax nodes, and the target SQL syntax tree includes SQL syntax nodes corresponding to the execution result of the above-mentioned first function.

[0010] The processing unit is further configured to operate on the data in the target database based on the target SQL syntax tree.

[0011] In another aspect, an embodiment of the present disclosure provides a compiler, comprising: a memory and a processor; the memory and the processor are coupled; the memory is used to store a computer program; and the processor implements the database operation method described in any of the above aspects when executing the computer program.

[0012] In another aspect, an embodiment of the present disclosure provides a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, implement the database operation method described in any one of the above aspects.

[0013] In yet another aspect, an embodiment of the present disclosure provides a computer program product, which includes computer program instructions, and when executed by a processor, implements the database operation method described in any one of the above aspects. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] To more clearly illustrate the technical solutions of the present disclosure, the following briefly introduces the drawings required for use in some embodiments of the present disclosure. Obviously, the drawings described below are only drawings of some embodiments of the present disclosure, and those skilled in the art can also derive other drawings based on these drawings.

[0015] FIG1 is a schematic diagram of a data processing system according to some embodiments.

[0016] FIG2 is a flow chart of a method for configuring a compiler according to some embodiments.

[0017] FIG3 is a flow chart of another compiler configuration method according to some embodiments.

[0018] FIG4 is a flowchart of a method for parsing a packet according to some embodiments.

[0019] FIG5 is a schematic diagram of a function syntax tree according to some embodiments.

[0020] FIG6 is a flow chart of a method for generating a function syntax tree according to some embodiments.

[0021] FIG7 is a schematic diagram of another function syntax tree according to some embodiments.

[0022] FIG8 is a schematic diagram of a SQL syntax tree according to some embodiments.

[0023] FIG9 is a schematic diagram of yet another function syntax tree according to some embodiments.

[0024] FIG10 is a flowchart illustrating another method for parsing a packet according to some embodiments.

[0025] FIG11 is another schematic diagram of an SQL syntax tree according to some embodiments.

[0026] FIG12 is a flowchart of a database operation method according to some embodiments.

[0027] FIG13 is a flowchart of another database operation method according to some embodiments.

[0028] FIG14 is a flowchart of another database operation method according to some embodiments.

[0029] FIG15 is another schematic diagram of an SQL syntax tree according to some embodiments.

[0030] FIG16 is a schematic diagram of another SQL syntax tree according to some embodiments.

[0031] FIG17 is a flow chart of a method for converting a SQL statement according to some embodiments.

[0032] FIG18 is another schematic diagram of an SQL syntax tree according to some embodiments.

[0033] FIG19 is another schematic diagram of an SQL syntax tree according to some embodiments.

[0034] FIG20 is a flowchart of another method for generating a SQL syntax tree according to some embodiments.

[0035] FIG21 is another schematic diagram of an SQL syntax tree according to some embodiments.

[0036] FIG22 is another schematic diagram of an SQL syntax tree according to some embodiments.

[0037] FIG23 is a schematic diagram of the structure of a compiler according to some embodiments.

[0038] FIG24 is a schematic diagram of the hardware structure of a compiler according to some embodiments. DETAILED DESCRIPTION

[0039] The following will clearly and completely describe the technical solutions of this disclosure in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of this disclosure, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.

[0040] It should be noted that in this disclosure, expressions such as "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described in this disclosure as "exemplary" or "for example" should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of expressions such as "exemplarily" or "for example" is intended to present the relevant concepts in a detailed manner.

[0041] In the following, the terms "first," "second," etc. are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the quantity of the technical features indicated. Therefore, a feature specified as "first," "second," etc. may explicitly or implicitly include one or more of the features.

[0042] In the description of this disclosure, unless otherwise specified, " / " means "or". For example, A / B can mean A or B. "And / or" in this document is simply a description of the association relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: only A, only B, and A and B. In addition, "at least one" means one or more, and "a plurality" means two or more.

[0043] As we all know, SQL is a structured query language used to implement business requirements for databases in Internet projects.

[0044] However, as database requirements continue to increase in internet projects, developers need to write SQL code to implement each additional database requirement. Two SQL codes corresponding to two business requirements may contain subroutines with similar logic or identical functionality, resulting in code redundancy within the project.

[0045] Based on this, an embodiment of the present disclosure provides a database operation method for use in a compiler. The method calls a first function in a target SQL statement; then, based on the target SQL statement and the execution result of the first function, generates a target SQL syntax tree; and finally, operates on data in a target database based on the target SQL syntax tree. Thus, the above method reduces code redundancy by calling functions in SQL statements.

[0046] The above method is applied to a data processing system as shown in FIG1 , which includes a compiler 101 and a database 102 .

[0047] The compiler 101 is used to receive a target SQL statement written by a user, or to receive a target SQL statement sent by an application; then, the compiler 101 parses the target SQL statement and sends the parsed target SQL statement to the database 102. The parsing process of the target SQL statement is described in the following embodiment 3 and will not be repeated here.

[0048] It should be noted that the compiler 101 is a compiler that can recognize function grammar rules.

[0049] The database 102 is used to receive the parsed target SQL statement sent by the compiler 101, and implement processing actions on the data stored in the database 102 by executing the parsed target SQL statement.

[0050] It should be noted that the above-mentioned database 102 can be a MySQL database, an Oracle database, a massively parallel processing (MPP) database or a big data computing engine (such as a spark computing engine or a flink engine). The embodiment of the present disclosure does not limit the type of the above-mentioned database 102.

[0051] For ease of understanding, the present disclosure is described in detail through Examples 1 to 3. Examples 1 and 2 are preparatory steps for compiler 101 (hereinafter referred to as the compiler) to execute the database operation method provided in the present disclosure. Example 3 is a detailed description of the database operation method provided in the present disclosure.

[0052] Example 1

[0053] An embodiment of the present disclosure provides a compiler configuration method, which includes: S110 to S120, as shown in FIG2 .

[0054] S110: The compiler obtains the syntax definition rules of the package and the syntax definition rules of the function.

[0055] It should be noted that the above package includes at least one function. In other words, the package is a container for functions. The above function is a pre-edited subroutine to implement a business sub-function.

[0056] The above package syntax definition rules include: package definition rules, package reference rules, and package external dependency introduction rules.

[0057] The above package definition rules include: package keywords (such as package) and package syntax formats.

[0058] It should be noted that the grammatical format of the above package can be package pak1{}, where "package" is the keyword of the package; "pak1" is the package name; and "{}" is the package body. The grammatical format of the above package can also be package com.net.pak1[], where "package" is the keyword of the package; "com.net.pak1" is the path of the package named "pak1"; and "[]" is the package body. The present embodiment does not limit the expression form of the grammatical rules of the above package.

[0059] The above package reference rules include: package reference keywords (for example: import) and package reference syntax format; for example: import com.net.pak1 means referencing the package named "pak1" in the location indicated by "com.net" in the current file.

[0060] The rules for introducing external dependencies of the above packages include: keywords for introducing external dependencies (for example: dependency) and the syntax format for introducing external dependencies.

[0061] It should be noted that the syntax format for introducing external dependencies can be: <dependency>'The absolute address of the package to be imported' <dependency>The syntax format for introducing external dependencies may also be: dependency:'the absolute address of the package to be introduced'. The embodiment of the present disclosure does not limit the expression form of the syntax format for introducing external dependencies.

[0062] The syntax definition rules of the above functions include: function definition rules, function calling rules, function parameter passing rules and logic control rules.

[0063] It should be noted that the syntax definition rules of the above functions can refer to the interpretation of the syntax definition rules of functions in other existing languages ​​such as Java or C, and will not be repeated in this article.

[0064] It should be noted that there are no two functions in a package with exactly the same function name, function return type, and function parameters.

[0065] It should be noted that the above functions are functions included in the above package body (ie: {}). For the convenience of description, the functions included in the package will be referred to as module functions in the following text, which will not be repeated in this article.

[0066] It should be noted that the explanation of the grammatical definition rules of the above function is only an example and does not limit the grammatical definition rules in the embodiments of the present disclosure.

[0067] S120: The compiler saves the grammatical definition rules of the package and the grammatical definition rules of the function, so that the compiler can recognize and execute logical operations of the package and the function.

[0068] It should be noted that the grammatical definition rules of the above packages and the grammatical definition rules of the functions can be stored in the compiler or in the memory of the computing device specified by the compiler, which is not limited in the embodiment of the present disclosure.

[0069] It should be understood that the above-mentioned compiler can identify and execute logical operations of packages and functions based on the saved package syntax definition rules and function syntax definition rules; the detailed method of the compiler identifying and executing logical operations of packages and functions can be found in the prior art and will not be repeated here.

[0070] The disclosed embodiments introduce the concepts of packages and functions into the compiler. A package is a container for functions, and no two functions with exactly the same function name, function return type, and function parameters (referred to as: duplicate-name functions) exist in a package, thereby avoiding the problem of function name conflicts when duplicate-name functions are called.

[0071] In some embodiments, in combination with FIG. 2 , the above method further includes: S210 to S220 , as shown in FIG. 3 .

[0072] S210. The compiler obtains the syntax definition rules of the SQL subquery.

[0073] It should be noted that the above package includes at least one SQL subquery, that is, the package is also a container for SQL subqueries. The above SQL subquery is a pre-edited SQL query statement for implementing the sub-function of the service.

[0074] The syntax rules of the above SQL subquery include: the definition rule of the SQL subquery and the call rule of the SQL subquery.

[0075] The definition rule of the above SQL subquery can be: alias as + SQL query statement (for example: query statement A); this definition rule is to give an alias (for example, subSelect) to the SQL query statement; the call rule of the above SQL subquery can be to directly use the alias subSelect of the SQL query statement in the SQL statement to be executed, so as to play the role of calling the query statement A corresponding to subSelect in the SQL statement to be executed.

[0076] Exemplarily, assume that the SQL subquery is subSelect as select name from table_1 where sex = 'female'; this SQL subquery is used to query all values of the name field where the value of the sex field in the table_1 table is 'female'; the alias of this SQL subquery is subSelect. Assume that the SQL statement to be executed is: select age from table_1 where name in {ref subSelect}; at this time, this SQL statement to be executed is used to query all values of the age field where the value of the sex field in the table_1 table is 'female'; the {ref subSelect} identifier is used to represent calling the SQL query statement with the alias subSelect.

[0077] It should be noted that there are no two SQL subqueries with the same alias in a package.

[0078] S220. The compiler saves the syntax definition rules of the SQL subquery so that the compiler can recognize and execute the logical operations of the SQL subquery.

[0079] It should be noted that the above syntax definition rules of the SQL subquery can be saved in the compiler or in the memory of the computing device specified by the compiler. The embodiments of the present disclosure do not limit this.

[0080] It should be understood that the above compiler can recognize and execute the logical operations of the SQL subquery according to the syntax definition rules of the SQL subquery; the detailed method for the compiler to recognize and execute the logical operations of the SQL subquery refers to the prior art and will not be elaborated herein.

[0081] By introducing the concept of SQL subqueries into the compiler, the disclosed embodiment prevents two SQL subqueries with the same alias (referred to as duplicate SQL subqueries) from existing in a package, thereby avoiding the problem of SQL subquery alias conflicts when duplicate SQL subqueries are called.

[0082] Example 2

[0083] An embodiment of the present disclosure provides a method for parsing a packet, which includes: S310 to S330, as shown in FIG4 .

[0084] S310: The compiler obtains a locally pre-defined package.

[0085] It should be noted that the above compiler is a compiler processed by the configuration method in the above embodiment 1, and the compiler can recognize and execute logical operations of packages and functions.

[0086] The above-mentioned locally pre-defined packages include: a first package, the first package includes a first function, that is, the first function is a module function defined in the first package.

[0087] For example, assume that the detailed content of the first package is as shown in the following code block 1, which is used to indicate that the package named Pak1 (i.e., the first package) includes a function named aa (i.e., the first function). The running logic of the function includes: when the value of x is 0, return 'name', otherwise return 'age'.

[0088] Code Block 1

[0089] Package Pak1{

[0090] function aa(x){if(x==0){return'name';}else{return'age';}}

[0091] }

[0092] S320: The compiler generates a first function syntax tree according to the first function.

[0093] The first function syntax tree is a graphical representation of the syntax structure of the first function (i.e., the first function syntax tree is the function syntax tree corresponding to the first function). The function syntax tree is the result of function derivation and helps understand the hierarchy of the function's syntax structure. In other words, the function syntax tree is a tree-like derivation diagram formed when the function is deduced according to its syntax rules.

[0094] It should be noted that the above-mentioned first function syntax tree can be generated by the compiler based on the function script syntax parser (for example: Jinjava); the above-mentioned first function syntax tree can also be generated based on the function parsing module inside the compiler. This disclosure does not limit the tool for generating the first function syntax tree.

[0095] It should be understood that when the above-mentioned first function syntax tree is generated by the compiler based on the function script syntax parser, it is necessary to add the syntax definition rules of the package and function to the function script syntax parser so that the function script syntax parser can recognize the package and the functions defined in the package.

[0096] Exemplarily, based on the code shown in the above code block 1, assuming that the first function is function aa in the Pak1 package, the syntax tree of the first function is shown in Figure 5. The leaf node corresponding to (i.e., pointing to) the name branch in the function syntax tree is used to represent the name aa of the function, and the leaf node corresponding to (i.e., pointing to) the param branch in the function syntax tree is used to represent the formal parameter x of the function; the function syntax tree also includes a child node if corresponding to the function body branch, which is used to represent that the function body of the function includes an if judgment; the leaf node corresponding to the if(x == 0) branch of the child node if is name, which is used to represent that when the value of x is 0, the output result is 'name'; the leaf node corresponding to the else branch of the child node if is age, which is used to represent that when the value of x is not 0, the output result is 'age'.

[0097] S330: The compiler saves the first function syntax tree in the function tree set of the first package.

[0098] The function tree set of the first package includes: a function syntax tree corresponding to each function in the first package.

[0099] Exemplarily, based on the example in S320 above, the generated first function syntax tree is saved in the function set of the first package (for example, the function set of the first package is a set named pak1_ftList).

[0100] After introducing the syntax definition rules of packages and functions into the compiler, the embodiment of the present disclosure parses the functions pre-defined by the user to generate a function syntax tree, and saves the function syntax tree so that the function syntax tree can be directly obtained during subsequent use without having to generate the function syntax tree of the function each time the function is called, thereby improving the execution efficiency of the code.

[0101] It should be noted that when the above-mentioned first function includes an SQL statement, the compiler in the above-mentioned S320, whether based on the function script syntax parser or the function parsing module inside the compiler, cannot recognize the SQL statement in the first function, and thus cannot parse the SQL statement.

[0102] Based on this, in one embodiment, when the first function includes a SQL statement, the S320 includes: S320A to S320D, as shown in FIG6 .

[0103] S320A: The compiler obtains a first function from a first package.

[0104] S320B: The compiler generates a second function syntax tree corresponding to the first function according to the first function.

[0105] The second function syntax tree includes a target function syntax node, which is used to represent the SQL statement in the first function.

[0106] For example, assume that the first function is as shown in the following code block 2. The first function is named bb and is used to indicate that when the value of x is 0, it returns 'name'; when the value of x is not 0, it returns the string corresponding to the SQL statement (referred to as SQL statement A) for querying all values ​​of the name field in the table_2 table. The second function syntax tree corresponding to the first function is shown in Figure 7. The leaf node corresponding to (i.e., pointing to) the name branch in the function syntax tree is used to represent the name bb of the function, and the leaf node corresponding to (i.e., pointing to) the param branch in the function syntax tree is used to represent the formal parameter x of the function; the function syntax tree also includes a child node if corresponding to the function body branch, which is used to represent that the function body includes an if judgment; the leaf node corresponding to the if(x == 0) branch of the child node if is name, which is used to represent that when the value of x is 0, the output result is 'name'; the leaf node corresponding to the else branch of the child node if is the target function syntax node, which is used to represent that when the value of x is not 0, the output result is the string corresponding to SQL statement A.

[0107] Code Block 2

[0108] Package Pak1{

[0109] function bb(x){if(x==0){return'name';}else{return'select name from table_2';}}

[0110] }

[0111] It should be noted that the description of generating the second function syntax tree is described in the relevant description of S320 above, which will not be repeated here.

[0112] S320C. The compiler generates a fourth SQL syntax tree corresponding to the SQL statement in the first function.

[0113] It should be noted that the above-mentioned fourth SQL syntax tree can be generated by the compiler based on the SQL syntax parser (for example: Calcite); the above-mentioned fourth SQL syntax tree can also be generated based on the parsing module inside the compiler. This disclosure does not limit the tool for generating the fourth SQL syntax tree.

[0114] For example; based on the example in S320B above, the SQL statement in the first function is: select name from table_2; the fourth SQL syntax tree corresponding to the SQL statement is shown in Figure 8, the leaf node corresponding to the select list branch of the SQL syntax tree is name, and the leaf node corresponding to the from branch of the SQL syntax tree is table_2.

[0115] S320D: The compiler mounts the fourth SQL syntax tree to the target function syntax node in the second function syntax tree to obtain the first function syntax tree.

[0116] Exemplarily, based on the examples in S320B and S320C above, the second function syntax tree is shown in Figure 7, and the fourth function syntax tree is shown in Figure 8. In the second function syntax tree, the fourth SQL syntax tree is mounted to the target function syntax node to obtain the first function syntax tree. The first function syntax tree is shown in Figure 9. The leaf node corresponding to the branch of if (x == 0) of the first function syntax tree is name, and the node corresponding to the else branch is the fourth SQL syntax tree.

[0117] In one embodiment, when the syntax definition rules of the SQL subquery are also introduced into the compiler, in conjunction with FIG4 , the above method further includes: S410 to S420 , as shown in FIG10 .

[0118] S410: The compiler generates a second SQL syntax tree according to the first SQL subquery.

[0119] The package where the first SQL subquery is located is the second package. The first package and the second package can be the same package or different packages, which is not limited in this embodiment of the present disclosure.

[0120] It should be noted that the embodiment of the present disclosure is described by taking the first package and the second package as different packages as an example, which will not be repeated herein.

[0121] For example, assume that the content of the second package is as shown in the following code block 3, which is used to indicate that the package named Pak2 (i.e., the second package) includes a SQL subquery aliased as subSelect, which is used to query all values ​​of the name field whose sex field value is 'female' from table_1.

[0122] Code Block 3

[0123] The second SQL syntax tree is a graphical representation of the syntax structure of the first SQL subquery, that is, the syntax tree corresponding to the first SQL subquery is the second SQL syntax tree.

[0124] It should be noted that the above-mentioned second SQL syntax tree can be generated by the compiler based on the SQL syntax parser (for example: Calcite); the second SQL syntax tree can also be generated based on the parsing module inside the compiler. This disclosure does not limit the tool for generating the second SQL syntax tree.

[0125] It should be understood that when the above-mentioned second SQL syntax tree is generated by the compiler based on the SQL syntax parser, it is necessary to add syntax definition rules of packages and SQL subqueries to the SQL syntax parser so that the SQL syntax parser can recognize the SQL subqueries defined in the package.

[0126] Exemplarily, based on the above code block 3, assuming that the SQL subquery with the alias subSelect in the Pak2 package is the first SQL subquery, the above second SQL syntax tree is shown in Figure 11. The root node of the SQL syntax tree is subSelect select, which is used to indicate that the alias of the SQL subquery is subSelect, and the SQL subquery is a query statement; the leaf node of the first branch select list of the syntax tree is name, which is used to indicate that the first SQL subquery is to query the data of the name column; the leaf node of the second branch from of the syntax tree is table_1, which is used to indicate querying data from the table_1 table; the leaf node of the third branch where sex of the syntax tree is 'female', which is used to indicate the query condition, and the query condition is that the value of the sex field is 'female'.

[0127] S420: The compiler saves the second SQL syntax tree in the SQL syntax tree set of the second package.

[0128] The SQL syntax tree set of the second package includes a SQL syntax tree corresponding to each SQL subquery in the second package.

[0129] It should be noted that, when the second package also includes a function, the function syntax tree corresponding to the function is stored in the function tree set of the second package. For details, please refer to the relevant description of S330 above, which will not be repeated here.

[0130] Exemplarily, based on the example in S410 above, the generated second SQL syntax tree is saved in the SQL syntax tree set of the second package (for example, the SQL syntax tree set of the second package is a set named pak2_stList).

[0131] In the embodiment of the present disclosure, the compiler parses a user-defined SQL subquery (such as the first SQL subquery) to generate a second SQL syntax tree, and saves the second SQL syntax tree so that the second SQL syntax tree can be directly obtained for subsequent use without having to generate the second SQL syntax tree each time the first SQL subquery is called, thereby improving the execution efficiency of the code.

[0132] Example 3

[0133] An embodiment of the present disclosure provides a database operation method, which is applied to a compiler 101 (compiler for short) in the data processing system shown in FIG1 . The method includes: S510 to S540 , as shown in FIG12 .

[0134] S510: The compiler obtains an operation request from a database.

[0135] The above operation request includes: a target SQL statement, which contains (ie includes) a call to a first function; the first function is a subroutine pre-edited to implement a sub-function of the business.

[0136] For example, assume that the target SQL statement is: select {{aa(1)}} from table_1; this target SQL statement is used to query all data in the target column of table_1; the target column is the return value when the actual parameter passed to function aa is 1; at this time, the first function is function aa, which is used to return at least one column name in table_1, and {{}} is used to indicate that function aa is a function defined in the package, that is, function aa is a module function.

[0137] It should be noted that the target SQL statement may be directly input into the compiler by the user, or may be obtained by the compiler from other devices. The embodiment of the present disclosure does not limit the implementation of S510.

[0138] S520: The compiler obtains the execution result of the first function when the first function is called in the target SQL statement.

[0139] It should be noted that when the target SQL statement calls the first function, actual parameters will be passed to the first function. For example, the example in S510 above passes actual parameter 1 (ie, aa(1)) to the function aa.

[0140] 12 , the method for obtaining the execution result of the first function includes S520 a to S520 b , as shown in FIG13 .

[0141] S520a: The compiler obtains a first function syntax tree.

[0142] The first function syntax tree is a graphical representation of the syntax structure of the first function in S520 (ie, the first function syntax tree is a function syntax tree corresponding to the first function).

[0143] Exemplarily, when the above-mentioned first function is the function aa in the above-mentioned code block 1, the syntax tree of the first function is shown in Figure 5; the leaf node corresponding to (i.e., points to) the name branch in the function syntax tree is used to represent the name aa of the function, and the leaf node corresponding to (i.e., points to) the param branch in the function syntax tree is used to represent the formal parameter x of the function; the function syntax tree also includes a child node if corresponding to the function body branch, which is used to represent that the function body of the function includes an if judgment; the leaf node corresponding to the if(x == 0) branch of the child node if is name, which is used to represent that when the value of x is 0, the output result is 'name'; the leaf node corresponding to the else branch of the child node if is age, which is used to represent that when the value of x is not 0, the output result is 'age'.

[0144] It should be noted that the above compiler is a compiler processed by the configuration method in the above embodiment 1, and the compiler can recognize the call of the first function in the target SQL statement.

[0145] The implementation of the above S520a includes the following contents.

[0146] When the first function and the target SQL statement are in the same location (eg, in the same package), the compiler directly obtains the first function syntax tree corresponding to the first function from the function set of the package where the target SQL statement is located.

[0147] If the first function and the target SQL statement are not in the same package, the database acquisition request in S510 further includes obtaining an identifier of the package in which the first function is located, indicating that the first package in which the first function is located is to be imported into the current package. In this case, the compiler obtains the syntax tree of the first function from the function tree set of the first package.

[0148] It should be noted that after the above-mentioned first function is parsed by the parsing method in the above-mentioned embodiment 2, a first function syntax tree corresponding to the first function is obtained, and the first function syntax tree is stored in the function tree set of the package where the first function is located. Therefore, the above-mentioned S520a can directly obtain the first function syntax tree from the function tree set of the package where the first function is located.

[0149] S520b: The compiler inputs the target actual parameter into the first function syntax tree to obtain the execution result of the first function.

[0150] It should be noted that when a function with formal parameters is called, actual parameters need to be passed to the called function. The target actual parameters are the actual parameters passed in when calling the first function in the target SQL statement.

[0151] For example, assuming that the syntax tree of the first function is as shown in Figure 5, when the target actual parameter is 1, the value of the formal parameter x in the function syntax tree is set to 1; then, it is determined whether the value of x is 0; at this time, the value of x is 1 and not 0; so the compiler executes the else side and determines age as the execution result of the first function.

[0152] S530: The compiler generates a target SQL syntax tree according to the target SQL statement and the execution result of the first function.

[0153] The above-mentioned target SQL syntax tree is a graphical representation of the syntax structure of the target SQL statement. The nodes in the target SQL syntax tree are SQL syntax nodes, and the target SQL syntax tree includes SQL syntax nodes corresponding to the execution results of the first function; that is, the target SQL syntax tree is a syntax tree that conforms to the SQL syntax.

[0154] In conjunction with FIG. 12 or FIG. 13 , the implementation of the above S530 includes: S530 a to S530 c , as shown in FIG. 14 .

[0155] S530a: The compiler generates a first SQL syntax tree according to the target SQL statement.

[0156] The first SQL syntax tree includes a first node, which is used to represent a first function called in the target SQL statement.

[0157] It should be noted that the above-mentioned first SQL syntax tree can be generated by the compiler based on the SQL syntax parser (such as: Calcite); the above-mentioned first SQL syntax tree can also be generated based on the parsing module inside the compiler. This disclosure does not limit the tool for generating the first SQL syntax tree.

[0158] It should be noted that the existing SQL syntax does not support the call of module functions (i.e., functions in user-defined packages). Therefore, when the first SQL syntax tree is generated based on the SQL syntax parser, the SQL syntax parser needs to add syntax definition rules for function calls so that the parser can recognize module function calls in SQL statements.

[0159] For example, assume that the target SQL statement is select {{aa(1)}} from table_1; a first SQL syntax tree is generated based on the target SQL statement, as shown in Figure 15. The root node of the syntax tree indicates that the target SQL statement is a query statement, and the first node of the syntax tree is used to indicate which column in table_1 is to be queried in the target SQL statement, which is determined by the return value of the first function; another leaf node in the syntax tree indicates that the target SQL statement queries data from table_1.

[0160] S530b: The compiler obtains the SQL syntax node corresponding to the execution result of the first function.

[0161] The implementation of the above S530b includes: the compiler determines whether the execution result of the first function complies with the SQL grammar rules according to the SQL grammar rules; when the execution result of the first function does not comply with the SQL grammar rules, the compiler converts the execution result of the first function into an SQL grammar node corresponding to the execution result of the first function according to the correspondence between the grammar rules of the execution result of the first function and the SQL grammar rules; when the execution result of the first function complies with the SQL grammar, the execution result of the first function is determined as the SQL grammar node.

[0162] S530c: The compiler replaces the first node in the first SQL syntax tree with the SQL syntax node corresponding to the execution result of the first function to obtain a target SQL syntax tree.

[0163] Exemplarily, based on the example in S530a; assuming that the sql syntax node corresponding to the execution result of the first function is age, the first sql syntax tree is shown in Figure 15. Use the sql syntax node corresponding to the execution result of the first function to replace the first node in the first sql syntax tree, so that the updated first sql syntax tree is shown in Figure 16, and the original first node is replaced with the age node. At this time, the sql statement corresponding to the updated first sql syntax tree is select age from table_1 (i.e., query all values ​​of the age field from the table_1 table). Then, the updated first sql syntax tree is determined as the above-mentioned target syntax tree.

[0164] S540: The compiler operates on the data in the target database based on the target SQL syntax tree.

[0165] It should be noted that the implementation of S540 can be that the compiler converts the target SQL syntax tree into a SQL statement corresponding to the target SQL syntax tree and executes the SQL statement in the target database, thereby implementing the action of operating the data in the target database. The implementation of S540 can also be that the compiler inputs the target SQL syntax tree into the target database, causing the target database to execute the logic in the target SQL syntax tree, thereby implementing the action of operating the data in the target database.

[0166] The disclosed embodiments provide a database operation method for use in a compiler. The method involves calling a first function within a target SQL statement; then, based on the target SQL statement and the execution result of the first function, generating a target SQL syntax tree; and finally, operating on data in a target database based on the target SQL syntax tree. This method reduces code redundancy by calling functions within SQL statements.

[0167] With the emergence of various databases, the SQL languages ​​used in different databases have adapted and expanded upon the SQL standard to a certain extent, resulting in a variety of distinct SQL languages. These structured languages, adapted and expanded from the SQL standard, are generally referred to as SQL dialects. For example, the SQL dialects used by Oracle and MySQL databases are not identical, and their support for standard SQL varies. This results in SQL statements not being universal across databases.

[0168] Based on this, when the target database in the above S540 cannot recognize the target SQL syntax tree, the above S540 includes: S540a-S540d, as shown in FIG17 .

[0169] S540a: The compiler obtains the SQL dialect conversion rules of the target database.

[0170] The above SQL dialect conversion rules are used to translate SQL grammar into SQL dialect grammar suitable for the target database.

[0171] It should be noted that, in the embodiment of the present disclosure, the target database is described by taking the MySQL database and the target SQL syntax tree as a syntax tree recognizable by the Oracle database as an example, which will not be repeated herein.

[0172] The above-mentioned SQL dialect conversion rules include: the correspondence between the grammatical rules of the target SQL syntax tree and the dialect grammatical rules of the target database, as shown in Table 1 below; including Oracle grammatical rules recognizable by the Oracle database and MySQL grammatical rules recognizable by the MySQL database; the function Sysdate used to obtain the current system time in the Oracle grammar rules corresponds to the Now() function in the MySQL grammar rules; the function where rownum used for paging in the Oracle grammar rules corresponds to the function limit in the MySQL grammar rules; the keyword Number used to represent the integer type in the Oracle grammar rules corresponds to the Int keyword in the MySQL grammar rules.

[0173] Table 1

[0174] It should be noted that the above S540a can be the compiler actively obtaining the SQL dialect conversion rules of the above target database from the local or other devices, or other devices actively sending the SQL dialect conversion rules of the above target database to the compiler. The embodiment of the present disclosure does not limit the implementation method of the above S540a.

[0175] S540b: The compiler updates the target SQL syntax tree according to the SQL dialect conversion rules to obtain the target SQL dialect syntax tree.

[0176] The nodes in the above target SQL dialect syntax tree are dialect syntax nodes, that is, the target SQL dialect syntax tree is a syntax tree recognizable by the target database.

[0177] The above S540b includes: the compiler traverses each node in the above target SQL syntax tree in turn, and for each node, determines whether the current node needs to be updated (that is, whether the SQL fragment corresponding to the current node has a corresponding SQL dialect); if the current node needs to be updated, the compiler updates the node according to the above SQL dialect conversion rules; if the current node does not need to be updated, the compiler determines whether the next node needs to be updated, and repeats this process until every node in the above target SQL syntax tree is traversed.

[0178] Exemplarily, assume that the above-mentioned target SQL syntax tree is as shown in Figure 18; the leaf node corresponding to the select list branch in the target SQL syntax tree is name, which is used to indicate that the query result in the SQL statement (abbreviated as: SQL statement) corresponding to the target SQL syntax tree is the data in the name column, and the leaf node corresponding to the from branch is table_1, which is used to indicate that the SQL statement is used to query the data in the table_1 table; the node corresponding to the where rownum branch is <=10, which is used to indicate that the query result is the first 10 records. After updating the above-mentioned target SQL syntax tree based on the SQL dialect conversion rules shown in Table 1, the updated target SQL syntax tree is obtained, as shown in Figure 19. The updated target SQL syntax tree no longer includes the where branch and the node corresponding to the where branch, but adds the limit branch and the node corresponding to the limit branch (that is, the node is 10). Finally, the updated target SQL syntax tree is determined as the target SQL dialect syntax tree.

[0179] S540c: The compiler determines the target SQL dialect statement according to the target SQL dialect syntax tree.

[0180] It should be noted that in the above S530a, the compiler parses the target SQL statement based on the SQL syntax parser or the local parsing module to obtain the first SQL syntax tree; therefore, the implementation process of the above S540c includes the compiler reversely parsing the above target SQL dialect statement based on the SQL syntax parser or the local parsing module to obtain the target SQL dialect statement.

[0181] For example, based on the above S540b, after reverse parsing the target SQL dialect grammar tree as shown in FIG19 , the target SQL dialect statement obtained is select name from table_1 limit 10.

[0182] S540d: The compiler operates on the data in the target database based on the target SQL dialect statement.

[0183] The above S540d includes: the compiler implements the operation action on the data in the target database by executing the above target SQL dialect statement in the target database.

[0184] In the above embodiment, when the target data cannot recognize the target SQL syntax tree, the target SQL syntax tree is updated according to the SQL dialect conversion rules of the target database to obtain a target SQL dialect syntax tree that can be recognized by the target database; then, based on the target SQL dialect syntax tree, the target SQL dialect statement represented by the target SQL dialect syntax tree is determined; finally, by executing the above target SQL dialect statement in the target database, the operation action on the data in the target database is realized, thereby solving the problem of needing to write different rule codes for different databases and further improving development efficiency.

[0185] It should be noted that when there are multiple SQL statements for multi-table join queries in an Internet project, there may be multiple SQL subqueries with the same function in the multiple SQL statements, resulting in a high code duplication rate in the project.

[0186] Based on this, in one embodiment, when the target SQL statement further includes a call to the first SQL subquery, the S530 further includes: S530A-S530C, as shown in FIG20 .

[0187] S530A: The compiler generates a third SQL syntax tree according to the target SQL statement.

[0188] The third SQL syntax tree includes the first node and the second node. The first node is used to represent calling the first function in the target SQL statement, and the second node is used to represent calling the first SQL subquery in the target SQL statement.

[0189] It should be noted that the third SQL syntax tree can be generated by the compiler based on a SQL syntax parser (eg, Calcite); or it can be generated based on a parsing module within the compiler. This disclosure does not limit the tool for generating the third SQL syntax tree.

[0190] It should be noted that existing SQL syntax does not support the calling of module functions (e.g., the first function mentioned above) and SQL subqueries. Therefore, when the third SQL syntax tree is generated based on a SQL syntax parser, the SQL syntax parser needs to add syntax definition rules for calling module functions and SQL subqueries so that the parser can recognize the calling of module functions and SQL subqueries in SQL statements. Similarly, when the third SQL syntax tree is generated by a compiler, the compiler needs to add syntax definition rules for calling module functions and SQL subqueries so that the compiler can recognize the calling of module functions and SQL subqueries in SQL statements.

[0191] For example, assume that the target SQL statement is select{{aa(1)}}from table_1 where name in{ref subSelect}; this target SQL statement is used to query the value of the name field from table_1 for all target columns within the result set of the subselect subquery. The target column is the return value of the function aa after passing 1. The third SQL syntax tree corresponding to the target SQL statement is shown in Figure 21. The root node of the syntax tree indicates that the target SQL statement is a query statement. The first node corresponding to the select list branch of the syntax tree is used to indicate which column in the table to be queried in the target SQL statement is determined by the return value of the first function; the leaf node corresponding to the from branch in the syntax tree is table_1, which is used to indicate that the table name of the queried table is table_1. The second node in the syntax tree is used to indicate that the query condition of the target SQL statement is that the value of the name field belongs to the execution result of the SQL subquery named subSelect.

[0192] S530B: The compiler obtains the SQL syntax node and the second SQL syntax tree corresponding to the first function execution result.

[0193] It should be noted that the implementation method of obtaining the SQL syntax node corresponding to the execution result of the first function is consistent with the implementation method of the above S530b. For the implementation method of obtaining the SQL syntax node corresponding to the execution result of the first function, please refer to the relevant description of the above S530b and will not be repeated here.

[0194] The second SQL syntax tree is a graphical representation of the syntax structure of the first SQL subquery. That is, the syntax tree corresponding to the first SQL subquery is the second SQL syntax tree.

[0195] It should be noted that, when the first SQL subquery is called in the above-mentioned target SQL statement, the database operation request in the above-mentioned S510 also includes the identifier of the second package where the first SQL subquery is located. The above-mentioned acquisition of the second SQL syntax tree is to obtain the second SQL syntax tree from the SQL syntax tree set of the second package, that is, the above-mentioned compiler obtains the second SQL syntax tree based on the identifier of the second package.

[0196] Exemplarily, based on the example in the above S530A, the subquery named subSelect is: select name from table_1 where sex = 'female'; this SQL subquery is used to query all values of the name field where the value of the sex field in the table_1 table is 'female'. The syntax tree corresponding to this subquery named subSelect is shown in Figure 11. The leaf node corresponding to the select list branch is name, the leaf node corresponding to the from branch is table_1, and the leaf node corresponding to the where sex branch is female.

[0197] S530C. In the third SQL syntax tree, the compiler uses the SQL syntax node corresponding to the execution result of the first function to replace the first node, and mounts the second SQL syntax tree to the second node to obtain the target SQL syntax tree.

[0198] The above target SQL syntax tree includes the SQL syntax node corresponding to the execution result of the first function and the second SQL syntax tree.

[0199] Exemplarily, assume that the SQL syntax node corresponding to the execution result of the first function is age. The third SQL syntax tree is shown in Figure 21, and the second SQL syntax tree is shown in Figure 11. Use the SQL syntax node corresponding to the execution result of the first function to replace the first node in the third SQL syntax tree, and mount the second SQL syntax tree to the second node. The obtained target SQL syntax tree (i.e., the updated third SQL syntax tree) is shown in Figure 22. In the updated third SQL syntax tree, the original first node is changed to an age leaf node, and the second node is changed to the second SQL syntax tree.

[0200] It should be noted that the above S530A - S530C are implementations for generating the target SQL syntax tree based on the target SQL statement, the execution result of the first function, and the second SQL syntax tree.

[0201] In the embodiments of the present disclosure, by encapsulating multiple SQL subqueries with the same function, when the SQL subquery needs to be used in the target SQL statement, the SQL subquery can be directly called in the target SQL statement, and there is no need to write the code of the SQL subquery again, thereby improving the code reuse rate and reducing the code duplication rate.

[0202] It is understandable that, in order to implement the above functions, the compiler includes hardware structures and / or software modules that perform the corresponding functions. Those skilled in the art should easily realize that, in combination with the algorithm steps of each example described in the embodiments of the present disclosure, the present disclosure can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present disclosure.

[0203] The embodiment of the present disclosure can divide the above-mentioned compiler into functional modules according to the above-mentioned method embodiment. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one functional module. The above-mentioned integrated module can be implemented in the form of hardware or software. It should be noted that the division of modules in the embodiment of the present disclosure is schematic and is only a logical function division. There may be other division methods in actual implementation. The following is an example of dividing each functional module corresponding to each function.

[0204] Figure 23 is a schematic diagram of the structure of a compiler according to some embodiments, which can execute the database operation method provided by the above method embodiment. As shown in Figure 23, the compiler includes: a transceiver module 2310 and a processing module 2320. In some embodiments, the compiler may also include a storage module 2330.

[0205] The transceiver module 2310 is used to obtain an operation request of the database, wherein the operation request includes: a target SQL statement, wherein the target SQL statement contains a call to a first function; the first function is a subroutine pre-edited to implement a sub-function of the business. The transceiver module 2310 is also used to obtain the execution result of the first function when the first function is called in the target SQL statement. The processing module 2320 is used to generate a target SQL syntax tree based on the target SQL statement and the execution result; the target SQL syntax tree is a graphical representation of the syntax structure of the target SQL statement, and the nodes in the target SQL syntax tree are SQL syntax nodes, and the target SQL syntax tree includes SQL syntax nodes corresponding to the execution result. The processing module 2320 is also used to operate on data in the target database based on the target SQL syntax tree.

[0206] In some embodiments, processing module 2320 is configured to generate a first SQL syntax tree based on the target SQL statement; the first SQL syntax tree includes a first node, the first node being used to represent the call of the first function in the target SQL statement. Transceiver module 2310 is configured to obtain the SQL syntax node corresponding to the execution result. Processing module 2320 is further configured to replace the first node in the first SQL syntax tree with the SQL syntax node corresponding to the execution result, thereby obtaining the target SQL syntax tree.

[0207] In some embodiments, the transceiver module 2310 is configured to obtain, based on the identifier of the first packet, an execution result of the first function when the first function is called in the target SQL statement.

[0208] In some embodiments, the processing module 2320 is used to generate the target SQL syntax tree based on the target SQL statement, the execution result and the second SQL syntax tree; the target SQL syntax tree also includes the second SQL syntax tree, which is a graphical representation of the syntax structure of the first SQL subquery.

[0209] In some embodiments, processing module 2320 is configured to generate a third SQL syntax tree based on the target SQL statement; the third SQL syntax tree includes a first node and a second node, wherein the first node is configured to represent a call to the first function in the target SQL statement; and the second node is configured to represent a call to the first SQL subquery in the target SQL statement. Transceiver module 2310 is configured to obtain the SQL syntax node and the second SQL syntax tree corresponding to the execution result. Processing module 2320 is further configured to replace the first node in the third SQL syntax tree with the SQL syntax node corresponding to the execution result, and to mount the second SQL syntax tree to the second node to obtain the target SQL syntax tree.

[0210] In some embodiments, the transceiver module 2310 is configured to obtain the second SQL syntax tree based on the identifier of the second packet.

[0211] In some embodiments, the transceiver module 2310 is configured to obtain a first function syntax tree corresponding to the first function. The processing module 2320 is configured to input a target parameter into the first function syntax tree to obtain the execution result; the target parameter is the parameter passed in when calling the first function in the target SQL statement.

[0212] In some embodiments, the transceiver module 2310 is used to obtain the SQL dialect conversion rules of the target database, wherein the SQL dialect conversion rules are used to translate SQL grammar into SQL dialect grammar applicable to the target database. The processing module 2320 is used to update the target SQL grammar tree according to the SQL dialect conversion rules to obtain a target SQL dialect grammar tree, wherein the nodes in the target SQL dialect grammar tree are dialect grammar nodes. The processing module 2320 is also used to determine the target SQL dialect statement based on the target SQL dialect grammar tree. The processing module 2320 is also used to operate on the data in the target database based on the target SQL dialect statement.

[0213] In some embodiments, the compiler further includes a storage module 2330; a transceiver module 2310 for obtaining package syntax definition rules, function syntax definition rules, and SQL subquery syntax definition rules; the package syntax definition rules include: package definition rules, package reference rules, and rules for importing external dependencies of the package; the function syntax definition rules include: function definition rules, function call rules, function parameter passing rules, and logical control rules; the SQL subquery syntax rules include: SQL subquery definition rules and SQL subquery call rules. Storage module 2330 is used to store the package syntax definition rules, function syntax definition rules, and SQL subquery syntax definition rules, so that the compiler can recognize and execute logical operations on packages, functions, and SQL subqueries.

[0214] In some embodiments, the transceiver module 2310 is used to obtain the first function from the first package. The processing module 2320 is used to generate a second function syntax tree corresponding to the first function based on the first function; the second function syntax tree includes a target function syntax node, and the target function syntax node is used to represent the SQL statement in the first function. The processing module 2320 is also used to generate a fourth SQL syntax tree corresponding to the SQL statement in the first function. The processing module 2320 is also used to mount the fourth SQL syntax tree to the target function syntax node in the second function syntax tree to obtain the first function syntax tree. The storage module 2330 is used to save the first function syntax tree in the function tree set of the first package.

[0215] For detailed description of the above optional methods, please refer to the aforementioned method embodiments, which will not be repeated herein. In addition, the explanation of any of the compilers provided above and the description of the beneficial effects can refer to the corresponding method embodiments, which will not be repeated herein.

[0216] In the case of implementing the functions of the aforementioned integrated modules in hardware, the present disclosure provides another possible architecture for the compiler involved in the aforementioned embodiments. As shown in Figure 24 , the compiler includes: a processor 2402 and a bus 2404. In some embodiments, the compiler may also include a memory 2401; in some embodiments, the compiler may also include a communication interface 2403.

[0217] Processor 2402 may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the embodiments of the present disclosure. Processor 2402 may be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field-programmable gate array, or other programmable logic device, a transistor logic device, a hardware component, or any combination thereof. Processor 2402 may implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the embodiments of the present disclosure. Processor 2402 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.

[0218] The communication interface 2403 is used to connect to other devices via a communication network, such as Ethernet, wireless access network, or wireless local area network (WLAN).

[0219] The memory 2401 may be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but this document is not limited thereto.

[0220] As an implementation, the memory 2401 can exist independently of the processor 2402. The memory 2401 can be connected to the processor 2402 via a bus 2404 to store instructions or program codes. When the processor 2402 calls and executes the instructions or program codes stored in the memory 2401, the database operation method provided in the embodiment of the present disclosure can be implemented.

[0221] In another implementation, the memory 2401 may also be integrated with the processor 2402 .

[0222] Bus 2404 can be an Extended Industry Standard Architecture (EISA) bus, etc. Bus 2404 can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, FIG24 shows only one thick line, but this does not mean that there is only one bus or only one type of bus.

[0223] Some embodiments of the present disclosure provide a computer-readable storage medium (e.g., a non-transitory computer-readable storage medium), which stores computer program instructions. When the computer program instructions are executed on a computer, the computer executes the database operation method described in any of the above embodiments.

[0224] For example, the computer-readable storage media may include, but are not limited to, magnetic storage devices (e.g., hard disks, floppy disks, or magnetic tapes), optical disks (e.g., compact disks (CDs), digital versatile disks (DVDs), etc.), smart cards, and flash memory devices (e.g., erasable programmable read-only memories (EPROMs), cards, sticks, or key drives, etc.). The various computer-readable storage media described in this disclosure may represent one or more devices and / or other machine-readable storage media for storing information. The term "machine-readable storage medium" may include, but is not limited to, wireless channels and various other media capable of storing, containing, and / or carrying instructions and / or data.

[0225] An embodiment of the present disclosure provides a computer program product comprising instructions. When the computer program product is run on a computer, the computer is enabled to execute the database operation method described in any one of the above embodiments.

[0226] The above is only a specific embodiment of the present disclosure, but the scope of protection of the present disclosure is not limited thereto. Any changes or replacements within the technical scope disclosed in the present disclosure should be included in the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure should be based on the scope of protection of the claims.< / dependency> < / dependency>

Claims

1. A database operation method, wherein: The method is applied in a compiler and comprises: Obtaining an operation request of a database, wherein the operation request includes: a target SQL statement, wherein the target SQL statement contains a call to a first function; the first function is a subroutine pre-edited to implement a sub-function of a business; Obtaining an execution result of the first function when the first function is called in the target SQL statement; Generate a target SQL syntax tree according to the target SQL statement and the execution result; the target SQL syntax tree is a graphical representation of the syntax structure of the target SQL statement, the nodes in the target SQL syntax tree are SQL syntax nodes, and the target SQL syntax tree includes the SQL syntax nodes corresponding to the execution result; The data in the target database is operated based on the target SQL syntax tree.

2. The method according to claim 1, wherein: The step of generating a target SQL syntax tree according to the target SQL statement and the execution result includes: Generate a first SQL syntax tree according to the target SQL statement; the first SQL syntax tree includes a first node, and the first node is used to represent calling the first function in the target SQL statement; Get the SQL syntax node corresponding to the execution result; In the first SQL syntax tree, the SQL syntax node corresponding to the execution result is used to replace the first node to obtain the target SQL syntax tree.

3. The method according to claim 1 or 2, wherein: In a case where the operation request further includes: an identifier of a first package where the first function is located, the obtaining of an execution result of the first function when the first function is called in the target SQL statement includes: Based on the identifier of the first package, an execution result of the first function when the first function is called in the target SQL statement is obtained.

4. The method according to claim 1 or 2, wherein: When there is a call to a first SQL subquery in the target SQL statement, and the first SQL subquery is a SQL query statement pre-edited to implement a sub-function of a business, generating a target SQL syntax tree according to the target SQL statement and the execution result includes: The target SQL syntax tree is generated according to the target SQL statement, the execution result and the second SQL syntax tree; the target SQL syntax tree also includes the second SQL syntax tree, which is a graphical representation of the syntax structure of the first SQL subquery.

5. The method according to claim 4, wherein: The generating the target SQL syntax tree according to the target SQL statement, the execution result and the second SQL syntax tree comprises: Generate a third SQL syntax tree according to the target SQL statement; the third SQL syntax tree includes a first node and a second node, the first node is used to represent the call of the first function in the target SQL statement; the second node is used to represent the call of the first SQL subquery in the target SQL statement; Obtain the SQL syntax node corresponding to the execution result and the second SQL syntax tree; In the third SQL syntax tree, the SQL syntax node corresponding to the execution result is used to replace the first node, and the second SQL syntax tree is mounted to the second node to obtain the target SQL syntax tree.

6. The method according to claim 5, wherein: When the operation request further includes: an identifier of a second package where the first SQL subquery is located, obtaining the second SQL syntax tree includes: Based on the identifier of the second package, obtain the second SQL syntax tree.

7. The method according to claim 1 or 2, wherein: The obtaining of the execution result of the first function when the first function is called in the target SQL statement includes: Obtain a first function syntax tree, where the first function syntax tree is a function syntax tree corresponding to the first function; Input the target actual parameter into the first function syntax tree to obtain the execution result; the target actual parameter is the actual parameter passed in when calling the first function in the target SQL statement.

8. The method according to claim 1 or 2, wherein: The operating the data in the target database based on the target SQL syntax tree includes: Acquire the sql dialect conversion rule of the target database, wherein the sql dialect conversion rule is used to translate sql grammar into sql dialect grammar applicable to the target database; Update the target SQL syntax tree according to the SQL dialect conversion rule to obtain a target SQL dialect syntax tree, wherein the nodes in the target SQL dialect syntax tree are dialect syntax nodes; Determine a target SQL dialect statement according to the target SQL dialect grammar tree; The data in the target database is operated based on the target SQL dialect statement.

9. The method according to claim 3, wherein: The target SQL statement also contains a call to a first SQL subquery, where the first SQL subquery is a SQL query statement pre-edited to implement a sub-function of a business. Before obtaining the database operation request, the method further includes: Acquire and save the syntax definition rules of the package, the syntax definition rules of the function and the syntax definition rules of the sql subquery, so that the compiler can recognize and execute the logical operations of the package, the function and the sql subquery; Among them, the grammatical definition rules of the package include: package definition rules, package reference rules and introduction rules of external dependencies of the package; the grammatical definition rules of the function include: function definition rules, function calling rules, function parameter passing rules, and logic control rules; the grammatical rules of the sql subquery include: sql subquery definition rules and sql subquery calling rules.

10. The method according to claim 9, wherein: When the first function includes a SQL statement, the method further includes: Obtaining the first function from the first package; According to the first function, a second function syntax tree corresponding to the first function is generated; the second function syntax tree includes a target function syntax node, and the target function syntax node is used to represent the SQL statement in the first function; Generate a fourth SQL syntax tree corresponding to the SQL statement in the first function; In the second function syntax tree, mount the fourth SQL syntax tree to the target function syntax node to obtain the first function syntax tree; The first function syntax tree is stored in a function tree set of the first package.

11. A compiler comprising: Processor and memory; The memory stores instructions executable by the processor; When the processor is configured to execute the instructions, the compiler is caused to implement the method according to any one of claims 1 to 10.

12. A computer-readable storage medium, wherein: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a compiler, the compiler is caused to execute the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Data consanguinity analysis method and device, electronic equipment and storage medium

    CN113032362A

  • SQL syntax tree analysis method based on Flex and Bison

    CN113032366A

  • Database table-dividing query method and equipment

    CN114281842A

  • Multilayer analysis method of structured query statement, computer equipment and storage medium

    CN114756569A

  • Systems and methods for identifying common components across SQL parser dialects

    US20210049167A1

Cited By

  • Construction method and device of netlist analyzer and storage medium

    CN120850894A