Database operation method, compiler and computer readable storage medium

By calling pre-edited functions in SQL statements and generating SQL syntax trees, the code redundancy problem caused by the increase in database business requirements is solved, and efficient code reuse and adaptability is achieved.

CN118916032APending Publication Date: 2024-11-08ZTE CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310517571.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-08
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

As the demand for database business in Internet projects increases, developers need to frequently write SQL code with the same or similar functions, resulting in code redundancy.

Method used

By calling pre-edited functions in SQL statements and generating an SQL syntax tree, operating the database based on this syntax tree to reduce code duplication.

Benefits of technology

Reduces code redundancy, improves code execution efficiency and reuse rate, and adapts to the SQL dialect conversion requirements of different databases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916032A_ABST
    Figure CN118916032A_ABST
Patent Text Reader

Abstract

The invention discloses a database operation method, a compiler and a computer readable storage medium, relates to the technical field of databases, and is used for reducing code redundancy. The method is applied to a compiler and comprises the steps that an operation request of a database is obtained, the operation request comprises a target sql statement, and calling of a first function exists in the target sql statement; the first function is a subprogram pre-edited for realizing a subfunction of the service; obtaining 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 an execution result of the first function; the target sql syntax tree is a graphical representation of a syntax structure of a target sql statement, nodes in the target sql syntax tree are sql syntax nodes, and the target sql syntax tree comprises the sql syntax nodes corresponding to an execution result of the first function; and operating data in a target database based on the target sql syntax tree.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application 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

[0002] 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.

[0003] However, with the increasing business demands for databases in Internet projects, developers need to write SQL language codes (referred to as: SQL code) to implement the business needs of each database (referred to as: business needs); among them, the two SQL codes corresponding to the two business needs may contain subroutines with similar logical controls or the same functions, thus causing code redundancy in the project. Summary of the invention

[0004] Embodiments of the present application provide a database operation method, a compiler, and a computer-readable storage medium for reducing code redundancy.

[0005] On the one hand, a database operation method is provided, which is applied to a compiler, and the method includes: obtaining an operation request of a database, the operation request including: a target SQL statement, the target SQL statement containing a call to a first function; the first function is a subroutine pre-edited for implementing 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; generating a target SQL syntax tree according to 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; and operating on data in a target database based on the target SQL syntax tree.

[0006] In another aspect, a compiler is provided, comprising:

[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; and the first function is a subroutine pre-edited to implement a sub-function of a business.

[0008] The transceiver unit is also used to obtain the 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 according to 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 also used to operate the data in the target database based on the target SQL syntax tree.

[0011] On the other hand, a compiler is provided, 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 embodiments when executing the computer program.

[0012] On the other hand, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the database operation method described in any of the above embodiments is implemented.

[0013] On the other hand, a computer program product is provided, which includes computer program instructions, and when the computer program instructions are executed by a processor, the database operation method described in any of the above embodiments is implemented.

[0014] The embodiment of the present application provides a database operation method, which is used 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, a target SQL syntax tree is generated, and finally, the data in the target database is operated based on the target SQL syntax tree. It can be seen that the above method reduces the redundancy of the code by calling a function in a SQL statement. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solution in the present application, the drawings required for use in some embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only drawings of some embodiments of the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0016] Figure 1 A schematic diagram of a data processing system provided for some embodiments of the present application;

[0017] Figure 2 A flowchart of a compiler configuration method provided in some embodiments of the present application;

[0018] Figure 3A flowchart of a compiler configuration method provided in some embodiments of the present application;

[0019] Figure 4 A schematic diagram of a method for parsing a packet provided in some embodiments of the present application;

[0020] Figure 5 A schematic diagram of a function syntax tree provided for some embodiments of the present application;

[0021] Figure 6 A flowchart of a method for generating a function syntax tree provided in some embodiments of the present application;

[0022] Figure 7 A schematic diagram of a function syntax tree provided for some embodiments of the present application;

[0023] Figure 8 A schematic diagram of a SQL syntax tree provided for some embodiments of the present application;

[0024] Fig. 9 A schematic diagram of a function syntax tree provided for some embodiments of the present application;

[0025] Fig.10 A schematic diagram of a method for parsing a packet provided in some embodiments of the present application;

[0026] Fig.11 A schematic diagram of a SQL syntax tree provided for some embodiments of the present application;

[0027] Fig.12 A flowchart of a database operation method provided in some embodiments of the present application;

[0028] Fig.13 A schematic diagram of a database operation method flow chart provided in some embodiments of the present application;

[0029] Fig.14 A schematic diagram of a database operation method flow chart provided in some embodiments of the present application;

[0030] Fig.15 A schematic diagram of a SQL syntax tree provided for some embodiments of the present application;

[0031] Fig.16 A schematic diagram of a SQL syntax tree provided for some embodiments of the present application;

[0032] Fig.17 A flowchart of a method for converting a SQL statement provided in some embodiments of the present application;

[0033] Fig.18 A schematic diagram of a SQL syntax tree provided for some embodiments of the present application;

[0034] Fig.19 A schematic diagram of a SQL syntax tree provided for some embodiments of the present application;

[0035] Fig. 20 A flowchart of a method for generating a SQL syntax tree provided in some embodiments of the present application;

[0036] Fig.21 A schematic diagram of a SQL syntax tree provided for some embodiments of the present application;

[0037] Fig. 22 A schematic diagram of a SQL syntax tree provided for some embodiments of the present application;

[0038] Fig.23 A schematic diagram of the structure of a compiler provided in some embodiments of the present application;

[0039] Fig.24 A schematic diagram of the hardware structure of a compiler provided for some embodiments of the present application. DETAILED DESCRIPTION

[0040] The following will be combined with the drawings in this application to clearly and completely describe the technical solutions in this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0041] It should be noted that, in this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in this application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0042] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.

[0043] In the description of this application, unless otherwise specified, " / " means "or", for example, A / B can mean A or B. "And / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, "at least one" means one or more, and "multiple" means two or more.

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

[0045] However, as the business requirements for databases in Internet projects continue to increase, developers need to write SQL codes to implement each additional database business requirement. Among them, the two SQL codes corresponding to the two business requirements may contain subroutines with similar logical controls or the same functions, resulting in code redundancy in the project.

[0046] Based on this, an embodiment of the present application provides a database operation method, which is used 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, a target SQL syntax tree is generated, and finally, the data in the target database is operated based on the target SQL syntax tree. It can be seen that the above method reduces the redundancy of the code by calling a function in a SQL statement.

[0047] The above method is applied to Figure 1 The data processing system shown includes a compiler 101 and a database 102 .

[0048] 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 target SQL statement is parsed, and the parsed target SQL statement is sent 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.

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

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

[0051] 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 specific embodiment of the present application does not limit the specific type of the above-mentioned database 102.

[0052] For ease of understanding, the present application is described in detail through Examples 1 to 3; Examples 1 to 2 are preparations made by the compiler 101 (referred to as the compiler) to execute the database operation method provided in the present application. Example 3 is a detailed description of the database operation method provided in the present application.

[0053] Example 1

[0054] The present application embodiment provides a configuration method of a compiler, such as Figure 2 As shown, the method includes: S110-S120.

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

[0056] It should be noted that the above package includes at least one function, that is, the package is a container of functions. The above function is a pre-edited subroutine for realizing a sub-function of a service.

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

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

[0059] 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; "{}" 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"; "[]" is the package body; the specific embodiment of the present application does not limit the specific expression form of the grammatical rules of the above package.

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

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

[0062] 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 of the above-mentioned introduction of external dependency can also be: dependency:'the absolute address of the package to be introduced'. Specifically, the embodiment of the present application does not limit the specific expression form of the syntax format of the above-mentioned introduction of external dependency.

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

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

[0065] 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.

[0066] 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, which will not be repeated hereafter.

[0067] It should be noted that the above explanation of the grammar definition rules is only an example and does not limit the grammar definition rules in the embodiments of the present application.

[0068] 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.

[0069] It should be noted that the grammatical definition rules of the above-mentioned package and the grammatical definition rules of the function can be stored in the compiler or in the memory of the computing device specified by the compiler, which is not limited to the specific embodiments of the present application.

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

[0071] The embodiment of the present application introduces the concepts of package and function in the compiler, wherein a package is a container for functions, and there are no two functions in a package that have exactly the same function name, function return type, and function parameters (referred to as: duplicated function), thereby avoiding the problem of function name conflict when duplicated functions are called.

[0072] Optional, combined Figure 2 ,like Figure 3 As shown, the above method also includes: S210-S220.

[0073] S210. The compiler obtains the syntax definition rules of the sql subquery.

[0074] It should be noted that the above package includes at least one sql subquery. That is to say, the package is also a container for sql subqueries. The above sql subquery is an sql query statement pre-edited to implement the sub-function of the service.

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

[0076] The definition rule of the above sql subquery can be: alias as + sql query statement (e.g., query statement A); where this definition rule gives an alias (e.g., 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.

[0077] 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'; where {ref subSelect} is an identifier used to represent calling the sql query statement with the alias subSelect.

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

[0079] 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.

[0080] 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. Specifically, the embodiments of the present application do not make a limitation.

[0081] It should be understood that the above compiler can identify and execute the logical operation of the SQL subquery according to the syntax definition rules of the SQL subquery; the specific method of identifying and executing the logical operation of the SQL subquery is referred to the prior art and will not be repeated here.

[0082] The embodiment of the present application introduces the concept of SQL subquery in the compiler, wherein no two SQL subqueries with the same alias (referred to as: SQL subqueries with the same name) exist in one package; thereby avoiding the problem of alias conflict of SQL subqueries when the SQL subqueries with the same name are called.

[0083] Example 2

[0084] The present application embodiment provides a method for parsing a packet. Figure 4 Shown include: S310-S330.

[0085] S310: The compiler obtains a locally predefined package.

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

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

[0088] Exemplarily, assume that the specific content of the first package is as shown in the following code block 1, which is used to indicate that the package named Pak1 (ie, the first package) includes a function named aa (ie, the first function), and the running logic of the function includes: when the value of x is 0, return 'name' otherwise return 'age'.

[0089] Code Block 1

[0090] Package Pak1{

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

[0092] }

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

[0094] The first function syntax tree is a graphical representation of the syntax structure of the first function, that is, the first function syntax tree is a function syntax tree corresponding to the first function, wherein the function syntax tree is a derivation result of the function, which helps to understand the hierarchy of the function syntax structure. In other words, the function syntax tree is a tree-structured derivation diagram formed when the function is deduced according to the syntax rules.

[0095] It should be noted that the above-mentioned first function syntax tree can be generated by the compiler based on a function script syntax parser (such as Jinjava); it can also be generated based on the function parsing module inside the compiler. Specifically, this application does not limit the specific tool for generating the first function syntax tree.

[0096] 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.

[0097] Exemplarily, based on the code shown in the above code block 1, it is assumed that the first function is function aa in the Pak1 package. At this time, the syntax tree of the first function is as follows Figure 5 As shown; 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'.

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

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

[0100] Exemplarily, based on the example in S320 above, the generated first function syntax tree is saved in a function set of a first package, such as a function set of the first package named pak1_ftList.

[0101] After the embodiment of the present application introduces the syntax definition rules of packages and functions to the compiler, the compiler parses the functions pre-defined by the user, generates a function syntax tree, and saves the function syntax tree so that the function syntax tree can be directly obtained for subsequent use, without having to generate the function syntax tree of the function every time the function is called, thereby improving the execution efficiency of the code.

[0102] It should be noted that when the above-mentioned first function includes SQL statements, 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 statements in the first function, and thus cannot parse the SQL statements.

[0103] Based on this, in one embodiment, when the first function includes a SQL statement, such as Figure 6 As shown, the above S320 is specifically implemented including: S320A-S320D.

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

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

[0106] 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.

[0107] For example, assume that the first function is as shown in the following code block 2. The first function name is bb, which 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 (SQL statement A for short) for querying all values ​​of the name field in the table_2 table. The second function syntax tree corresponding to the first function is as follows: Figure 7 As shown, 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 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 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 the sql statement A.

[0108] Code Block 2

[0109] Package Pak1{

[0110] function bb(x){if(x==0){return'name';}else{return'select name fromtable_2';}}

[0111] }

[0112] It should be noted that, for the specific description of generating the second function syntax tree, please refer to the relevant description of S320 above, which will not be repeated here.

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

[0114] It should be noted that the fourth SQL syntax tree can be generated by the compiler based on a SQL syntax parser (such as Calcite); it can also be generated based on the parsing module inside the compiler. Specifically, this application does not limit the specific tool for generating the fourth SQL syntax tree.

[0115] Exemplarily, 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 as follows: Figure 8 As shown, 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 is table_2.

[0116] 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.

[0117] Exemplarily, based on the examples in S320B and S320C above, the second function syntax tree is as follows: Figure 7 As shown, the syntax tree of the fourth function is as follows Figure 8 As shown, 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, which is as shown in Fig. 9 As shown, 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.

[0118] In one embodiment, when the syntax definition rules of the SQL subquery are also introduced into the compiler, based on Figure 4 ,like Fig.10 As shown, the above method also includes: S410-S420.

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

[0120] The package where the above-mentioned first SQL subquery is located is the second package. The above-mentioned first package and the second package can be the same package or different packages, which is not limited in the specific embodiment of the present application.

[0121] It should be noted that the embodiment of the present application is described using the first package and the second package as different package examples, which will not be repeated later.

[0122] For example, assume that the specific content of the second package is as shown in the following code block 3, which is used to indicate that the package named Pak2 (ie: the second package) includes a sql subquery with an alias of subSelect, which is used to query all values ​​of the name field whose sex field value is 'female' from table_1.

[0123] Code Block 3

[0124]

[0125]

[0126] 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.

[0127] It should be noted that the above-mentioned second SQL syntax tree can be generated by the compiler based on a SQL syntax parser (such as Calcite); it can also be generated based on the parsing module inside the compiler. Specifically, this application does not limit the specific tool for generating the second SQL syntax tree.

[0128] 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 packages.

[0129] For example, 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 as follows: Fig.11 As shown, the root node of the SQL syntax tree is subSelect. The select is used to represent the alias of the SQL subquery as subSelect, and this SQL subquery is a query statement. The leaf node of the first branch select list of this syntax tree is name, which is used to represent that this first SQL subquery is to query the data of the name column. The leaf node of the second branch from is table_1, which is used to represent querying data from the table_1 table. The leaf node of the third branch where sex is 'female', which is used to represent the query condition, and this query condition is that the value of the sex field is 'female'.

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

[0131] The set of SQL syntax trees of the above-mentioned second package includes the SQL syntax trees corresponding to each SQL subquery in the second package.

[0132] It should be noted that when the above-mentioned second package also includes functions, the function syntax tree corresponding to the function is saved in the set of function trees of the second package. For specific reference, see the relevant description of S330 above, and details will not be repeated here.

[0133] Exemplarily, based on the example in the above S410, the generated second SQL syntax tree is saved in the set of SQL syntax trees of the second package. For example, the set of SQL syntax trees of the second package is a set named pak2_stList.

[0134] In the embodiment of the present application, the compiler parses a user-predefined SQL subquery (such as the first SQL subquery), generates a second SQL syntax tree, and saves the second SQL syntax tree, so that the second SQL syntax tree can be directly obtained during subsequent use, instead of generating the second SQL syntax tree every time the first SQL subquery is called, thereby improving the execution efficiency of the code.

[0135] Embodiment 3

[0136] The embodiment of the present application provides a database operation method, which is applied to the compiler 101 (abbreviation: compiler) in the data processing system as Figure 1 shown, and as Fig.12 shown, this method includes: S510 - S540.

[0137] S510. The compiler obtains an operation request for the database.

[0138] The above operation request includes: a target SQL statement, where there is (i.e., includes) a call to a first function in the target SQL statement; the first function is a subroutine pre-edited to implement a sub-function of the business.

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

[0140] It should be noted that the above target SQL statement can be directly input into the compiler by the user, or obtained by the compiler from other devices. The specific implementation method of the above S510 is not limited in the embodiment of the present application.

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

[0142] It should be noted that when the target SQL statement calls the first function, it will pass actual parameters to the first function, such as passing actual parameter 1 to function aa in the example of S510, that is, aa(1).

[0143] Combination Fig.12 ,like Fig.13 As shown, the specific method for obtaining the execution result of the first function includes S520a-S520b.

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

[0145] The first function syntax tree is a graphical representation of the syntax structure of the first function in S520, that is, the first function syntax tree is a function syntax tree corresponding to the first function.

[0146] Exemplarily, when the first function is the function aa in the code block 1, the syntax tree of the first function is as follows: Figure 5 As shown; 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'.

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

[0148] The specific implementation of the above S520a includes the following:

[0149] 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.

[0150] When the first function and the target SQL statement are not in the same package, the database operation request in S510 further includes: an identifier of the package where the first function is located, which is used to indicate that the first package where the first function is located is introduced into the current package. At this time, the compiler obtains the syntax tree of the first function from the function tree set of the first package.

[0151] It should be noted that after the first function is parsed by the parsing method in the above-mentioned embodiment 2, the 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.

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

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

[0154] Exemplarily, assuming that the first function syntax tree is as follows Figure 5 As shown, when the target actual parameter is 1, the value of the 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.

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

[0156] 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.

[0157] Combination Fig.12 or Fig.13 ,like Fig.14 As shown, the specific implementation of the above S530 includes: S530a-S530c.

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

[0159] The first SQL syntax tree includes a first node, and the first node is used to represent calling a first function in a target SQL statement.

[0160] It should be noted that the above-mentioned first SQL syntax tree can be generated by the compiler based on a SQL syntax parser (such as: Calcite); it can also be generated based on the parsing module inside the compiler. Specifically, this application does not limit the specific tool for generating the first SQL syntax tree.

[0161] It should be noted that the existing SQL syntax does not support the call of module functions (i.e., functions in user-defined packages), so 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.

[0162] For example, assume that the target SQL statement is select{{aa(1)}}from table_1; the first SQL syntax tree generated according to the target SQL statement is as follows: Fig.15 The root node of the syntax tree indicates that the target SQL statement is a query statement, the first node of the syntax tree is used to indicate which column in the table_1 table 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 the table_1 table.

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

[0164] The specific 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 a 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.

[0165] S530c: The compiler uses the SQL syntax node corresponding to the execution result of the first function in the first SQL syntax tree to replace the first node to obtain a target SQL syntax tree.

[0166] 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 as follows Fig.15 As shown; then, 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 as follows Fig.16 As shown, the original first node is replaced by the age node. At this time, the SQL statement corresponding to the updated first SQL syntax tree is select age from table_1, that is, query all values ​​of the age field from table_1. Then, the updated first SQL syntax tree is determined as the above target syntax tree.

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

[0168] It should be noted that the specific implementation of the above S540 may be that the compiler converts the target SQL syntax tree into the SQL statement corresponding to the target SQL syntax tree, and executes the SQL statement in the target database, thereby realizing the action of operating the data in the target database. Alternatively, the compiler inputs the target SQL syntax tree into the target database, so that the target database executes the logic in the target SQL syntax tree, thereby realizing the action of operating the data in the target database.

[0169] The embodiment of the present application provides a database operation method, which is used 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, a target SQL syntax tree is generated, and finally, the data in the target database is operated based on the target SQL syntax tree. It can be seen that the above method reduces the redundancy of the code by calling a function in a SQL statement.

[0170] With the emergence of various databases, the SQL language used in different databases has adapted and expanded the SQL specification to a certain extent, forming a variety of different SQL languages. Generally, the structured language adapted and expanded from the SQL specification is called SQL dialect. For example, the SQL dialects used by Oracle database and MySQL database are not exactly the same, and the degree of support for standard SQL is also different, which makes SQL statements between different databases not universal.

[0171] Based on this, when the target database in the above S540 cannot recognize the target SQL syntax tree, such as Fig.17 The specific implementation of the above S540 includes: S540a-S540d.

[0172] S540a, the compiler obtains the SQL dialect conversion rules of the target database.

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

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

[0175] The above dialect conversion rules include: the correspondence between the grammatical rules of the target SQL grammar tree and the dialect grammatical rules of the target database, as shown in Table 1 below; including the Oracle grammar rules recognizable by the Oracle database and the MySQL grammar rules recognizable by the MySQL database; among them, 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 whererownum 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.

[0176] Table 1

[0177]

[0178] 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 can actively send the SQL dialect conversion rules of the above target database to the compiler. The embodiment of the present application does not limit the specific implementation method of the above S540a.

[0179] S540b. The compiler updates the target SQL syntax tree according to the SQL dialect conversion rule to obtain the target SQL dialect syntax tree.

[0180] 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.

[0181] The specific implementation of 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 in sequence until each node in the above target SQL syntax tree is traversed.

[0182] For example, assuming that the target SQL syntax tree is as follows Fig.18 As shown; 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, 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 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 Fig.19 As shown, 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 (ie, the node is 10). Finally, the updated target SQL syntax tree is determined as the target SQL dialect syntax tree.

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

[0184] 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; so 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.

[0185] Exemplarily, based on the example in S540b above, Fig.19 After reverse parsing the target SQL dialect syntax tree, the target SQL dialect statement obtained is select name from table_1 limit 10.

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

[0187] The specific implementation of 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.

[0188] 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, according to 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 implemented, thereby solving the problem of needing to write different rule codes for different databases and further improving development efficiency.

[0189] 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 functions in the multiple SQL statements, resulting in a high code duplication rate in the project.

[0190] Based on this, in one embodiment, when the target SQL statement further includes a call to the first SQL subquery, the specific implementation of S530 is as follows: Fig. 20 As shown, it also includes: S530A-S530C.

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

[0192] The third SQL syntax tree includes the first node and the second node, wherein 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.

[0193] It should be noted that the above-mentioned third SQL syntax tree can be generated by the compiler based on a SQL syntax parser (such as Calcite); it can also be generated based on the parsing module inside the compiler. Specifically, this application does not limit the specific tool for generating the third SQL syntax tree.

[0194] It should be noted that the existing SQL syntax does not support the calling of module functions (such as the first function mentioned above) and SQL subqueries, so when the third SQL syntax tree is generated based on the 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.

[0195] For example, assume that the target SQL statement is select{{aa(1)}}from table_1where name in{ref subSelect}; this target SQL statement is used to query the value of the name field in the table_1 table for all target columns in the result set of the subselect subselect. The target column is the return value of the function aa after passing 1. The third SQL syntax tree corresponding to this target SQL statement is as follows: Fig.21 As shown, 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.

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

[0197] 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 S530b. For the specific implementation method of obtaining the SQL syntax node corresponding to the execution result of the first function, please refer to the relevant description of S530b above, which will not be repeated here.

[0198] 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.

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

[0200] Exemplarily, based on the example in S530A above, 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 as Fig.11 shown. The leaf node corresponding to the selectlist 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.

[0201] S530C. The compiler uses 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 mounts the second SQL syntax tree to the second node to obtain the target SQL syntax tree.

[0202] 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.

[0203] Exemplarily, assume that the SQL syntax node corresponding to the execution result of the first function is age, the third SQL syntax tree is as Fig.21 shown, the second SQL syntax tree is as Fig.11 shown. 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 as Fig. 22 shown. In the updated third SQL syntax tree, the original first node becomes the age leaf node, and the second node becomes the second SQL syntax tree.

[0204] It should be noted that the above S530A - S530C are the specific implementations of 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.

[0205] The embodiment of the present application encapsulates multiple SQL subqueries with the same function. When the SQL subquery needs to be used in a target SQL statement, the SQL subquery can be directly called in the target SQL statement without having to rewrite the code of the SQL subquery, thereby improving the code reuse rate and reducing the code duplication rate.

[0206] It is understandable that, in order to realize the above functions, the compiler includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should be easily aware that, in conjunction with the algorithm steps of each example described in the embodiment of the present application, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain 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 this implementation should not be considered to exceed the scope of the present application.

[0207] The embodiment of the present application can divide the functional modules of the above compiler according to the above 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 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 application 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.

[0208] Fig.23 is a schematic diagram of the structure of a compiler provided in an embodiment of the present application, and the compiler can execute the database operation method provided in the above method embodiment. Fig.23 As shown, the compiler includes: a transceiver module 2310 and a processing module 2320. In some embodiments, the compiler may further include a storage module 2330.

[0209] The transceiver module 2310 is used to obtain an operation request of a database, wherein the operation request includes: a target SQL statement, wherein a call to a first function exists in the target SQL statement; the first function is a subroutine pre-edited to implement a sub-function of a 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 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, 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.

[0210] In some embodiments, the processing module 2320 is used to 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 the call of the first function in the target SQL statement. The transceiver module 2310 is used to obtain the SQL syntax node corresponding to the execution result. The processing module 2320 is also used to replace the first node in the first SQL syntax tree with the SQL syntax node corresponding to the execution result to obtain the target SQL syntax tree.

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

[0212] 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.

[0213] In some embodiments, the processing module 2320 is used to 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; the transceiver module 2310 is used to obtain the SQL syntax node and the second SQL syntax tree corresponding to the execution result. The processing module 2320 is also used to replace the first node in the third SQL syntax tree with the SQL syntax node corresponding to the execution result, and mount the second SQL syntax tree to the second node to obtain the target SQL syntax tree.

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

[0215] In some embodiments, the transceiver module 2310 is used to obtain a first function syntax tree, where the first function syntax tree is a function syntax tree corresponding to the first function. The processing module 2320 is used to input a 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.

[0216] In some embodiments, the transceiver module 2310 is used to obtain the SQL dialect conversion rules of the target database, and 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 syntax tree according to the SQL dialect conversion rules to obtain a target SQL dialect grammar tree, and 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 according to 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.

[0217] In some embodiments, the compiler further includes a storage module 2330; a transceiver module 2310, which is used to obtain the syntax definition rules of the package, the syntax definition rules of the function, and the syntax definition rules of the sql subquery; wherein the syntax definition rules of the package include: the definition rules of the package, the reference rules of the package, and the introduction rules of the external dependencies of the package; the syntax definition rules of the function include: the definition rules of the function, the function call rules, the function parameter passing rules, and the logic control rules; the syntax rules of the sql subquery include: the definition rules of the sql subquery and the call rules of the sql subquery. The storage module 2330 is used to 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, function, and sql subquery.

[0218] 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.

[0219] For the specific description of the above optional methods, please refer to the above method embodiments, which will not be repeated here. In addition, the explanation of any compiler provided above and the description of the beneficial effects can refer to the above corresponding method embodiments, which will not be repeated here.

[0220] In the case of implementing the functions of the above integrated modules in the form of hardware, the embodiment of the present application provides another possible structure of the compiler involved in the above embodiment. Fig.24 As shown, the compiler includes: a processor 2402 and a bus 2404. Optionally, the compiler may also include a memory 2401; optionally, the compiler may also include a communication interface 2403.

[0221] Processor 2402 may be a processor that implements or executes various exemplary logic blocks, modules, and circuits described in conjunction with the embodiments of the present application. The 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 devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the embodiments of the present application. The 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.

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

[0223] The memory 2401 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or 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 is not limited thereto.

[0224] As a possible implementation, the memory 2401 may exist independently of the processor 2402, and the memory 2401 may 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 application can be implemented.

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

[0226] The bus 2404 may be an extended industry standard architecture (EISA) bus, etc. The bus 2404 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.24 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0227] Some embodiments of the present application 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.

[0228] Exemplarily, the above-mentioned computer-readable storage media may include, but are not limited to: magnetic storage devices (e.g., hard disks, floppy disks or magnetic tapes, etc.), optical disks (e.g., compact disks (CD), digital versatile disks (DVD), etc.), smart cards and flash memory devices (e.g., erasable programmable read-only memory (EPROM), cards, sticks or key drives, etc.). The various computer-readable storage media described in this application 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.

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

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

Claims

1. A database operation method, characterized in that: The method is applied in a compiler, and the method 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, characterized in that Generating a target SQL syntax tree according to the target SQL statement and the execution result specifically 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, characterized in that: 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, characterized in that: 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, characterized in that 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, characterized in that 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, characterized in that: The obtaining, when the first function is called in the target SQL statement, an execution result of the first function 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, characterized in that: 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, characterized in that: 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, characterized in that 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, characterized in that include: 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, characterized in that: 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.