Sentence processing method and device, equipment cluster and storage medium
By adjusting the description information of the SQL statement, the number of UDF calculations is reduced, which solves the problems of long UDF calculation time and execution errors, and achieves more efficient and reliable SQL statement execution.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2024-12-31
- Publication Date
- 2026-06-30
AI Technical Summary
User-defined functions (UDFs) take a long time to compute when executing SQL statements, resulting in low SQL execution efficiency. This is especially true when UDFs require multiple calculations and have no deterministic results, which may lead to execution errors.
By adjusting the description information of the SQL statements, repeatedly calculated UDFs are replaced with function calculation result call information, ensuring the consistency of UDF results in different SQL operators, and optimizing the execution order of SQL statements to reduce the number of UDF calculations.
It improves the execution efficiency of SQL statements, avoids redundant calculations of UDFs, reduces calculation time, and improves the reliability and efficiency of execution.
Smart Images

Figure CN122309536A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to statement processing methods, apparatus, device clusters and storage media. Background Technology
[0002] In the field of computer technology, databases can be manipulated by executing Structured Query Language (SQL) statements. These databases are typically relational databases that organize data using a relational model. Operations include querying, updating, and managing statements. In some cases, user-defined functions (UDFs) are computed during SQL statement execution. Because UDFs are user-defined and possess complex computational logic, their computation time is long, leading to low SQL statement execution efficiency. Therefore, a statement processing method is urgently needed to improve the execution efficiency of SQL statements. Summary of the Invention
[0003] This application provides a statement processing method, apparatus, device cluster, and storage medium to improve the execution efficiency of SQL statements. The technical solution is as follows:
[0004] Firstly, a statement processing method is provided, comprising: obtaining first description information of an SQL statement, wherein the SQL statement is used to operate a database, and the first description information describes multiple SQL operators involved in operating the database based on the SQL statement, wherein at least two of the multiple SQL operators include a User-Defined Function (UDF); wherein, if at least two of the multiple SQL operators include the same first UDF, and the function calculation result of the first UDF in at least two of the first SQL operators should remain the same, adjusting the first description information to obtain second description information, wherein the second description information includes the first operator and the second SQL operator corresponding to the first SQL operator, wherein the first operator is used to calculate the first UDF, and the second SQL operator is used to call the function calculation result of the first operator, and the second SQL operator is obtained by adjusting the first SQL operator in the first description information that is different from the first operator, and the execution order of the first operator is before the execution order of the second SQL operator; and operating the database based on the second description information.
[0005] By adjusting the first description information to the second description information, in the subsequent process of executing SQL statements to operate the database, only the first UDF needs to be calculated based on the first operator. The other second SQL operators, including the first UDF, can directly call the function of the first operator to calculate the result, without having to calculate the first UDF again. By reducing the number of times the first UDF is calculated during the execution of SQL statements, the total time for calculating the first UDF during the execution of SQL statements is reduced, thereby improving the execution efficiency of SQL statements.
[0006] In one possible implementation, before adjusting the first description information to obtain the second description information, the method further includes: counting the number of various UDFs based on the first description information; and determining any UDF as the first UDF if the number of any UDF is greater than the first number and the function calculation result of any UDF should remain the same under different SQL operators. By counting and judging the number of various UDFs in the first description information, the first UDF can be determined from the UDFs included in each SQL operator in the first description information. The process of determining the first UDF is simple and has low operational complexity.
[0007] In one possible implementation, each UDF includes tagging information indicating that the function evaluation results of each UDF should remain the same across different SQL operators. This tagging information simplifies the process of determining whether the function evaluation results of any given UDF should remain identical, resulting in high efficiency.
[0008] In one possible implementation, the first operator differs from all the first SQL operators; the second SQL operator is obtained by replacing the first UDF of any first SQL operator with the function calculation result call information, which is used to call the function calculation result. The fact that the first operator differs from all the first SQL operators indicates that the first operator is a newly added operator. By adding the first operator to the first description information, even if there is no SQL operator in the first description information that can directly calculate the function calculation result of the first UDF, it can be guaranteed that the second SQL operator can successfully call the function calculation result.
[0009] In one possible implementation, the first description information includes a first SQL tree, which includes multiple nodes, with each node corresponding to an SQL operator; adjusting the first description information to obtain the second description information includes: adding the SQL operator corresponding to the child node of a third SQL operator to the child node of the first operator, wherein the third SQL operator is an operator whose child node's corresponding SQL operator does not include the first UDF; adding the first operator to the child node of the third SQL operator; and obtaining the second description information based on the first SQL tree after the addition.
[0010] In this SQL tree, the execution order of the SQL operator corresponding to any child node is before the execution order of the SQL operator corresponding to the parent node of any child node. The SQL operator corresponding to the child node of the third SQL operator does not include the first UDF, indicating that the third SQL operator is the first SQL operator in terms of execution order among the multiple first SQL operators including the first UDF. Adding the first operator to the child node of the third SQL operator, which has the highest execution order, ensures that the first operator's execution order is before that of all other first SQL operators including the first UDF. When any subsequent first SQL operator including the first UDF is executed, the first operator has already obtained the function calculation result, and any first SQL operator including the first UDF can directly call the already calculated function result.
[0011] In one possible implementation, the first operator is the operator that executes first among at least two first SQL operators; the second SQL operator is obtained by replacing the first UDF of the first SQL operator that does not execute first with the function calculation result call information, whereby the call information is used to call the function calculation result. The first operator is the original operator in the first description information. This application adjusts the first UDF included in the first SQL operator to call information, so that when the modified second SQL operator is executed subsequently, the function calculation result can be directly called based on the call information, without needing to recalculate the first UDF.
[0012] In one possible implementation, the call information includes the variable name of the function's evaluation result. Using the variable name to express the function's result helps in quickly understanding and locating the code's function, reducing errors.
[0013] In one possible implementation, the first operator includes a projection operator. The statement processing method provided in this application can be implemented using a general projection operator, without the need to redesign a new operator, resulting in low operational complexity.
[0014] In one possible implementation, the first UDF includes a random function. Since the result of the random function is different each time it is calculated, multiple executions of the first UDF can lead to inconsistent results. However, the result of the first UDF in different SQL operators should remain the same to ensure the normal execution of the SQL statement. This application addresses this by calling the result of the first operator's function calculation, ensuring consistency in the result of different SQL operators including the first UDF. This reduces the probability of SQL statement execution errors and improves execution reliability.
[0015] Secondly, a statement processing apparatus is provided, comprising: an acquisition module for acquiring first description information of an SQL statement, wherein the SQL statement is used to operate a database, and the first description information describes multiple SQL operators involved in operating the database based on the SQL statement, wherein at least two of the multiple SQL operators include a UDF; an adjustment module for adjusting the first description information to obtain second description information when at least two of the multiple SQL operators include the same first UDF, and the function calculation result of the first UDF in at least two of the first SQL operators should remain the same, wherein the second description information includes a first operator and a second SQL operator corresponding to the first SQL operator, wherein the first operator is used to calculate the first UDF, and the second SQL operator is used to call the function calculation result of the first operator, and the second SQL operator is obtained by adjusting the first SQL operator in the first description information that is different from the first operator; and an operation module for operating the database based on the second description information.
[0016] In one possible implementation, the adjustment module is also used to count the number of various UDFs based on the first description information; if the number of any UDF is greater than the first number, and the function calculation result of any UDF should remain the same under different SQL operators, then any UDF is determined as the first UDF.
[0017] In one possible implementation, any UDF includes tagging information that indicates that the function computation results of any UDF should remain the same across different SQL operators.
[0018] In one possible implementation, the first operator is different from each of the first SQL operators; the second SQL operator is obtained by replacing the first UDF of any first SQL operator with the calling information of the function computation result, which is used to call the function computation result.
[0019] In one possible implementation, the first description information includes a first SQL tree, which includes multiple nodes, with each node corresponding to an SQL operator; an adjustment module is used to add the SQL operator corresponding to the child node of a third SQL operator to the child node of the first operator, wherein the third SQL is an operator whose child node corresponding to at least two first SQL operators does not include the first UDF; the first operator is added to the child node of the third SQL operator; and the second description information is obtained based on the first SQL tree after the addition.
[0020] In one possible implementation, the first operator is the operator that executes first among at least two first SQL operators; the second SQL operator is obtained by replacing the first UDF of the first SQL operator that executes first with the calling information of the function calculation result, and the calling information is used to call the function calculation result.
[0021] In one possible implementation, the call information includes the variable name of the function's evaluation result.
[0022] In one possible implementation, the first operator includes the project operator.
[0023] In one possible implementation, the first UDF includes a random function.
[0024] Thirdly, a computing device cluster is provided, the computing device cluster including at least one computing device, each computing device including a processor and a memory; the processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster performs any of the statement processing methods of the first aspect described above.
[0025] Fourthly, a computer-readable storage medium is provided, the computer-readable storage medium including computer program instructions, which, when executed by a cluster of computing devices, perform any of the statement processing methods described in the first aspect above.
[0026] Fifthly, a computer program (product) containing instructions is provided, which, when executed by a cluster of computing devices, causes the cluster of computing devices to execute any of the statement processing methods described in the first aspect above.
[0027] A sixth aspect provides a communication device comprising: a transceiver, a memory, and a processor. The transceiver, the memory, and the processor communicate with each other via an internal connection path. The memory stores instructions, and the processor executes the instructions stored in the memory to control the transceiver to receive and transmit signals. When the processor executes the instructions stored in the memory, it causes the processor to perform the method of the first aspect or any possible implementation thereof.
[0028] Optionally, there may be one or more processors and one or more memories.
[0029] Alternatively, the memory can be integrated with the processor, or the memory can be set up separately from the processor.
[0030] In the specific implementation process, the memory can be a non-transitory memory, such as read-only memory (ROM), which can be integrated with the processor on the same chip or set on different chips. This application does not limit the type of memory or the way the memory and processor are set.
[0031] In a seventh aspect, a chip is provided, including a processor for retrieving and executing instructions stored in a memory, causing a communication device on which the chip is installed to perform the methods in the foregoing aspects.
[0032] Eighthly, another chip is provided, comprising: an input interface, an output interface, a processor, and a memory, wherein the input interface, the output interface, the processor, and the memory are connected via an internal connection path, and the processor is used to execute code in the memory. When the code is executed, the processor is used to execute the methods in the above aspects.
[0033] It should be understood that the apparatus mentioned in the second or sixth aspect above can be the chip mentioned in the seventh or eighth aspect, or it can be the device cluster of the third aspect. The beneficial effects achieved by the technical solutions and corresponding possible implementations of the second to eighth aspects of this application can be found in the above description of the technical effects of the first aspect and its corresponding possible implementations, and will not be repeated here. Attached Figure Description
[0034] Figure 1 A schematic diagram illustrating the execution process of an SQL statement provided in an embodiment of this application;
[0035] Figure 2 A schematic diagram of an implementation environment provided for an embodiment of this application;
[0036] Figure 3 A flowchart of a statement processing method provided in an embodiment of this application;
[0037] Figure 4 A schematic diagram illustrating a first descriptive information provided in an embodiment of this application;
[0038] Figure 5 This application provides a schematic diagram of a process for adding a first operator in an embodiment of the present application.
[0039] Figure 6 A schematic diagram illustrating a second descriptive information provided in an embodiment of this application;
[0040] Figure 7 This is a schematic diagram of the structure of a statement processing device provided in an embodiment of this application;
[0041] Figure 8 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application;
[0042] Figure 9 This is a schematic diagram of the connection of a computing device provided in an embodiment of this application. Detailed Implementation
[0043] The terminology used in the embodiments section of this application is only for explaining specific embodiments of this application and is not intended to limit this application. To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be further described in detail below with reference to the accompanying drawings.
[0044] In the field of computer technology, SQL statements are a programming language used to manipulate databases, such as relational databases. SQL statements can perform operations on the database, including data querying, data manipulation, data definition, and data control. Data querying retrieves data from the database; data manipulation adds, deletes, updates, and queries database records, and checks data integrity; data definition defines different database objects such as databases, tables, views, and indexes, including creating, deleting, and modifying the structure of databases and tables; and data control determines access permissions and security levels for databases, tables, fields, and users.
[0045] For example, the execution flow of SQL is as follows: Figure 1 As shown, the process includes parsing, validating, optimizing, and executing. The parsing phase converts the SQL statement into an internal representation that the database can understand. For example, it parses the SQL statement into lexical units, generates an abstract syntax tree (AST) based on the lexical units, and generates a logical plan based on the AST. The validating phase verifies the logical plan, such as verifying its structure and syntax correctness. The optimizing phase analyzes and optimizes the logical plan, generates multiple alternative physical execution plans, and selects the optimal one. The executing phase performs the relevant operations on the database based on the selected physical execution plan.
[0046] In some cases, the execution of the physical execution plan involves the computation of User-Defined Functions (UDFs). A UDF is a user-defined function written by the user to extend the functionality of the database and implement complex data processing logic. Users can be database developers or administrators, and UDFs can be used to perform data transformations, complex calculations, and encapsulate business logic. However, during the execution phase of the physical execution plan for SQL statements, the same UDF may be called multiple times and calculated repeatedly.
[0047] Taking the SQL statement "SELECT id, name, UDF(name) from table WHERE UDF(name) == 'Peng'" as an example, which searches for the name and its corresponding identity document (id) from the table, where the first character of the name is equal to 'Peng', the UDF(name) function will be called twice during the execution phase.
[0048] Because User-Defined Functions (UDFs) contain complex computational logic, repeatedly calling the same UDF during execution can affect the entire SQL execution process. Furthermore, if the UDF has a non-deterministic result, repeatedly calculating it will lead to execution errors. A non-deterministic UDF refers to a UDF that is calculated multiple times, but the results are different each time; for example, it might be a random function that outputs a random number each time. If the user requires determinism in the UDF during SQL statement execution, and the UDF's calculation result must remain consistent to ensure the SQL statement's correct execution, then repeatedly calculating a non-deterministic UDF may cause SQL execution errors. Therefore, a statement processing method is urgently needed to optimize repeatedly calculated UDFs in SQL statements.
[0049] In related technology one, for UDFs with deterministic requirements, the auxiliary system calculates the result value of the UDF and writes it into the context. Subsequently, when executing SQL statements that use the UDF, the result value can be directly retrieved from the context. The auxiliary system could be, for example, code generation (CodeGen). This method requires that the SQL engine / framework used to execute the SQL statements support the auxiliary system. Furthermore, because it modifies the auxiliary system's runtime logic—for example, adding a result value to the context involves rewriting the auxiliary system's code—it requires maintaining the auxiliary system's version, resulting in high maintenance costs.
[0050] In related technique two, SQL statements are rewritten. By rewriting the SQL statements, a single operation for calculating a UDF is modified into multiple operations such as querying and calling, thereby avoiding the repeated calculation of the same UDF. However, rewriting SQL is labor-intensive and carries high risks.
[0051] This application provides a statement processing method. Figure 2This is a schematic diagram of an implementation environment provided in an embodiment of this application. The implementation environment includes a processing device 01 and a database, and a communication connection is established between the processing device 01 and the database. For example, the database is configured in the processing device 01. The processing device 01 is used to execute the statement processing method provided in this embodiment of the application. After obtaining first description information of an SQL statement used to operate the database, it adjusts the first description information to obtain second description information, and uses the second description information to operate the connected database.
[0052] For example, the processing device 01 can be a server, such as a central server, an edge server, or a local server in a local data center. The server can be a physical server or a cloud server providing cloud computing services. In some embodiments, the processing device 01 can also be a terminal device such as a desktop computer, laptop computer, or smartphone involved in cloud services. Furthermore, the above method can be... Figure 2 The execution shown can be performed by one processing device 01, or by multiple processing devices 01. Multiple processing devices 01 may be referred to as a computing device cluster in some cases. Furthermore, the processing device 01 can be a standalone device, or a component within a device, such as a transceiver, processor, or chip. The database connected to the processing device 01 can be a local database configured on the processing device 01, or a cloud database; this embodiment does not limit the scope of the application.
[0053] This application provides a statement processing method that can be applied to the above-mentioned... Figure 2 The implementation environment shown indicates that this method can be executed by a processing device, and the flowchart of the method is as follows. Figure 3 As shown, it includes S301-S303.
[0054] S301, Obtain the first description information of the SQL statement. The SQL statement is used to operate the database. The first description information is used to describe multiple SQL operators involved in operating the database based on the SQL statement. At least two of the multiple SQL operators include UDFs.
[0055] In one possible implementation, the processing device acquires an SQL statement, parses and verifies the SQL statement, and obtains first descriptive information. The processing device may provide an information input control to receive SQL statements input by a user, which are used to perform operations on the database as desired by the user. For example, performing data queries, data manipulations, data definitions, or data control operations as described in the above embodiments. The process of parsing and verifying the SQL statement can be found in the descriptions of the parsing and verification phases in the above embodiments, and will not be repeated here. The first descriptive information may be referred to as a logical plan in some cases.
[0056] For example, the first description information includes multiple SQL operators. SQL operators are keywords or symbols used to perform operations. SQL operators include, but are not limited to, SELECT operators for selecting specific columns from a database to retrieve data, TableScan operators for specifying the name of the table to be queried, Filter operators for filtering data in a table or view based on certain conditions in an SQL statement, and Project operators for extracting specific attribute fields from tuples in a database. In some cases, SQL operators may include UDFs (User-Defined Functions); for example, a Filter operator performs filtering operations based on the function calculation results of a UDF.
[0057] The following example uses the SQL statement "select id, substring(comments, 0, 4) from source where substring(comments, 0, 4) = 'This'" to retrieve the first descriptive information from the table where the first four characters of the comments corresponding to the retrieved id are equal to 'This'. Here, 'comments' is a table field. The parsed logical plan for this SQL statement is as follows:
[0058] ==Parsed Logical Plan==
[0059] 'Project[id, unresolvedalias('substring('comments, 0, 4), None)]
[0060] +-'Filter('substring('comments, 0, 4) = This)
[0061] +-'UnresolvedRelation[source],[],false
[0062] Here, `Project[id, unresolvedalias('substring('comments, 0, 4), None)]` is the `Project` operator parsed from `substring(comments, 0, 4)`, and `Filter('substring('comments, 0, 4) = This)` is the `Filter` operator parsed from `substring(comments, 0, 4) = 'This'`. Regarding the source in the SQL statement, since the processing device cannot determine whether the source is a table or other structured data, the parsing result for the source is `UnresolvedRelation`.
[0063] After verification, the above analytical logic plan yields the Analyzed Logical Plan, which is the first descriptive information as follows:
[0064] ==Analyzed Logical Plan==
[0065] id: int, substring(comments, 0, 4): string
[0066] Project[id#0, substring(comments#4,0,4)AS substring(comments,0,4)#10]
[0067] +-Filter(substring(comments#4,0,4)=This)
[0068] +-SubqueryAlias source
[0069] +-View('source', [id#0, name#1, sex#2, age#3, comments#4])
[0070] +-Relation[id#0, name#1, sex#2, age#3, comments#4]
[0071] JDBCRelation(v2test, source005)[numPartitions=1]
[0072] During the verification phase, the processing device analyzes the source again, resolving UnresolvedRelation[source] into a subqueryAlias operator that depends on the alias. Here, the view and relation describe the table serving as the source, and id, name, sex, age, and comments are the columns in the table. In this Analyzed Logical Plan, Project[id#0, substring(comments#4, 0, 4) AS substring(comments, 0, 4)#10] is the Project operator, Filter(substring(comments#4, 0, 4) = This) is the Filter operator, Relation[id#0, name#1, sex#2, age#3, comments#4] is the Relation operator, and substring(comments#4, 0, 4) is a UDF.
[0073] Optionally, the first description information can also be an SQL tree structure. Taking the first description information including the first SQL tree as an example, the first SQL tree includes multiple nodes, and each node corresponds to an SQL operator. Figure 4 This is a schematic diagram of the structure of a first descriptive information provided in an embodiment of this application. Figure 4 The first description information includes three SQL operators: Project, Filter, and TableScan. Both the Project and Filter operators contain User-Defined Functions (UDFs). Figure 4 The arrows in the image are meant to illustrate the hierarchical structure of the SQL tree. The SQL operator connected to the head of the arrow is at the next level below the SQL operator connected to the tail of the arrow, and is a child node of the SQL operator connected to the tail of the arrow. In some cases, a child node can be called a "child". However, in actual execution, the execution order is the opposite of the hierarchical structure indicated by the arrows; the SQL operators closer to the bottom are executed earlier.
[0074] S302, where at least two first SQL operators among multiple SQL operators include the same first UDF, and the first UDF should have the same function calculation result of at least two first SQL operators, the first description information is adjusted to obtain second description information. The second description information includes the first operator and the second SQL operator corresponding to the first SQL operator. The first operator is used to calculate the first UDF, and the second SQL operator is used to call the function calculation result of the first operator. The second SQL operator is obtained by adjusting the first SQL operator in the first description information that is different from the first operator. The execution order of the first operator is before the execution order of the first SQL operator.
[0075] In one possible scenario, SQL statements may encounter the problem of duplicate UDF calculations, meaning the same UDF appears multiple times in the initial description information. Taking the Analyzed Logical Plan in the above embodiment as an example, both the Project and Filter operators include substring(comments#4, 0, 4). This UDF appears twice in the Analyzed Logical Plan, and will be calculated twice when the SQL statement is executed subsequently. Furthermore... Figure 4 Taking the first description information shown as an example, both the Project operator and the Filter operator include UDF(xxx). In this case, if directly based on... Figure 4 The first description shown indicates that executing the SQL statement will repeatedly calculate UDF(xxx) twice.
[0076] Calculating the same UDF multiple times is inefficient, and in some cases, if the repeatedly calculated UDF includes a random function, the result of each calculation may differ, potentially causing SQL execution errors. Therefore, the processing device optimizes the first description information to avoid repeatedly calculating the same UDF. Based on the above embodiment, the first description information is verified information, meaning it has passed the verification phase and is processed in the optimization phase. The process of obtaining the second description information from the first description information refers to adding an optimization rule during the optimization phase and using this rule to optimize the first description information. This added optimization rule can be called a reuse UDF optimization rule (RBO).
[0077] For example, the processing device may first identify reusable deterministic UDFs in the first description information as the first UDF to be optimized. Here, reusability means that multiple SQL operators include the UDF, and deterministic UDF means that the calculation results of the UDF should be consistent across multiple calculations. If the calculation results of the UDF differ across multiple calculations, it will lead to SQL execution errors.
[0078] In one possible scenario, the processing device can count the number of various UDFs based on the first description information. If the number of any UDF is greater than a first number, and the calculation result of any UDF should remain the same across different SQL operators, then that UDF is designated as the first UDF. The first number can be an integer set empirically, such as 1. The processing device can iterate through the first description information, counting each different UDF within it, and counting the number of identical UDFs. Identical UDFs refer to UDFs whose functions are the same and whose input parameters are identical. After counting each UDF, if the number of identical UDFs is greater than 1, it indicates that the UDF appears multiple times in the first description information. That is, during the execution of SQL statements based on the first description information, the same UDF will be calculated multiple times, and the processing device thus determines that the UDF is a reused UDF.
[0079] After identifying a reusable UDF, the processing device further determines whether the UDF is a deterministic UDF. In some cases, the execution of SQL statements may involve using the same UDF multiple times to obtain different results. For example, using the same UDF function to generate different random numbers multiple times and processing them. In this situation, multiple calls to the same UDF can yield different results. For non-deterministic UDFs, processing them with different SQL operators calling the same function could lead to SQL execution errors. Therefore, the processing device will also determine whether the UDF is a deterministic UDF.
[0080] For example, if any UDF includes tagging information indicating whether the function evaluation result of any UDF should remain the same in different SQL operators, the processing device can determine whether any UDF is a deterministic UDF whose function evaluation result should remain the same based on the tagging information. If the tagging information is a first value, the UDF is determined to be a deterministic UDF; if the tagging information is not a first value, the UDF is determined to be a non-deterministic UDF. The first value can be any numerical value set based on experience, for example, 0.
[0081] After determining the deterministic UDF that is repeatedly invoked, the processing device can use the UDF as the first UDF to be processed, use the SQL operator that includes the first UDF in the first description information as the first SQL operator, and adjust the first description information based on the first UDF and the first SQL operator to obtain the second description information. The first operator and the second SQL operator in the adjusted second description information include, but are not limited to, the following two cases.
[0082] Case 1: The first operator is different from all the first SQL operators; the second SQL operator is obtained by replacing the first UDF of any first SQL operator with the calling information of the function calculation result, and the calling information is used to call the function calculation result.
[0083] Optionally, the first operator differing from each of the first SQL operators indicates that the first operator is a newly added operator, such as the Project operator. During the process of adding a first operator to the first description information, since the first UDF appears in multiple first SQL operators, if the added first operator's hierarchy precedes that of a certain first SQL operator, it will cause the first SQL operator to be executed before it has produced a function calculation result, and thus the first SQL operator cannot call the ungenerated function calculation result.
[0084] Therefore, when adding a first operator to the first description information, the processing device adds the first operator at a level lower than each first SQL operator in the first description information. This ensures that during the execution of subsequent first SQL operators, the first operator has already been executed, and the first SQL operator can directly call the function calculation result obtained from the previously executed first operator. In one possible case, the processing device will first determine the lowest-level third SQL operator among the multiple first SQL operators including the first UDF, and add the first operator at the next level below the third SQL operator.
[0085] In a tree structure, the bottom-level third SQL operator can be understood as a first SQL operator whose child nodes do not contain a first SQL operator that includes the first UDF. For example, the third SQL operator has no child nodes, or the child nodes of the third SQL operator, and the child nodes of the child nodes, do not contain a first SQL operator that includes the first UDF.
[0086] Continue with Figure 4 Taking the first descriptive information shown as an example, Figure 4The child nodes of the Project operator correspond to the Filter operator. The Filter operator includes UDF(xxx) as the first UDF. Therefore, the Project operator is not the lowest-level third SQL operator. The child nodes of the Filter operator correspond to the TableScan operator. The TableScan operator does not include UDF(xxx) as the first UDF. That is, the Filter operator is the lowest-level third SQL operator.
[0087] For example, after determining the third SQL operator in the first SQL tree, the processing device can insert a first operator between the third SQL operator and the SQL operator corresponding to its child node. For instance, adding the SQL operator corresponding to the child node of the third SQL operator to the child node of the first operator, where the third SQL operator is an operator whose child node's corresponding SQL operator does not include the first UDF; adding the first operator to the child node of the third SQL operator. This process can be understood as setting the child node of the first operator to the SQL operator corresponding to the child node of the third SQL operator, and setting the SQL operator corresponding to the child node of the third SQL operator to the first operator.
[0088] Figure 5 This application provides a process for adding a first operator in an embodiment. Figure 5 The first operator added is the Project operator. The processing device inserts the Project operator between the Filter operator and the TableScan operator. See the second SQL tree for the result. Figure 6 . Figure 6 In the code, the SQL operator corresponding to the child node of the Filter operator is changed from the TableScan operator to the Project operator, and the SQL operator corresponding to the child node of the Project operator is set to the TableScan operator.
[0089] In one possible scenario, the processing device, in addition to adding a first operator to the first description information to obtain the added first description information, will also replace the first UDF in the added first description information with the function calculation result call information to obtain the second SQL operator corresponding to the first SQL operator. The call information is used to extract the function calculation result. The call information can be any information identifying the function calculation result. Optionally, the call information includes the variable name of the function calculation result. The variable name serves as an identifier for storing the function calculation result.
[0090] By replacing the first UDF in the original first SQL operator in the first description information with the function calculation result call information of the Project operator, subsequent first SQL operators do not need to execute the calculation operation of the first UDF; they can directly call the function calculation result of the Project operator based on the call information. For example, if the added call information is a variable name, see [link to example]. Figure 6 If the variable name of the function calculation result of the Project operator is yyy, then the UDF(xxx) in the Filter operator is adjusted to yyy, and the UDF(xxx) in the Project operator is also adjusted to yyy.
[0091] also, Figures 4-6 This is intended to illustrate the process of adding the first operator in the first description information, and is not intended to limit the operation of adding the first operator. If there is only one type of UDF that is repeatedly evaluated in the SQL statement, the processing device can, as follows: Figures 4-6 As shown, a first operator is added. If multiple UDFs are repeatedly evaluated in the SQL statement, the processing device can perform a similar operation, adding a corresponding first operator for each UDF. Furthermore, the first description information can be as follows: Figures 4-6 The diagram may include one branch or multiple branches; this application does not limit this in its embodiments.
[0092] Taking the Analyzed Logical Plan, which serves as the first descriptive information, as an example, the processing device, during execution S302, obtains the following optimized logical plan using the optimization rules of this application:
[0093] ==Optimized Logical Plan==
[0094] Project[id#0, xxx#10]
[0095] +-Filter(isnotnull(comments#4)AND xxx#10=This)
[0096] +-Project[id#0,substring(comments#4,0,4)AS xxx#10]
[0097] +-Relation[id#0, name#1, sex#2, age#3, comments#4]JDBCRelation(v2test, source005)[numPartitions=1]
[0098] In this context, the Optimized Logical Plan corresponds to the second description information in the above embodiment. The Project operator added to the Analyzed Logical Plan is Project[id#0, substring(comments#4, 0, 4)ASxxx#10], where xxx#10 indicates the function calculation result of the project operator and is the variable name of the function calculation result. By adding the Project operator to the Analyzed Logical Plan, when executing SQL statements using the Optimized Logical Plan, substring(comments#4, 0, 4) can be calculated only once, achieving the effect of UDF being calculated only once. Other SQL operators can directly call the function calculation result of the Project operator, improving the execution efficiency of SQL statements.
[0099] Case 2: The first operator is the one that executes first among at least two first SQL operators; the second SQL operator is obtained by replacing the first UDF of the first SQL operator that does not execute first with the function calculation result call information, which is used to call the function calculation result.
[0100] In one possible scenario, if the first SQL operator executed first among multiple first SQL operators, after calculating the function result of the first UDF, not only continues to execute related operations using the function result but also generates function calculation result call information, then subsequent first SQL operators can also directly call the function calculation result generated by the first executed first SQL operator through the call information. In this case, the first executed first SQL operator can be used as the first operator for calculating the first UDF, while first SQL operators different from the first executed first SQL operator, i.e., non-first executed first SQL operators, can be adjusted to become second SQL operators.
[0101] The process of adjusting the first UDF in the first SQL operator that is not executed for the first time to the call information is similar to the process of adjusting the first UDF in the first SQL operator to the call information in case one. The difference is that in case one, all first SQL operators can be adjusted to second SQL operators, while in case two, some first SQL operators can be adjusted to second SQL operators. For a detailed description, please refer to the relevant content, which will not be repeated here.
[0102] The processing device can select the corresponding situation from situation one and situation two based on the situation of the first SQL operator in the first description information, and perform the corresponding adjustment operation. By adjusting the first description information to the second description information, the first UDF can be executed once, and other second SQL operators can directly call the function calculation result. The function calculation result of the first UDF in different second SQL operators can be consistent. Even if the first UDF is a UDF with no deterministic result, such as a random function, the effect of unifying the function calculation result of the first UDF can be achieved, thereby avoiding errors in the execution of SQL statements caused by the first UDF being a deterministic UDF due to different function calculation results. The execution reliability of the adjusted second description information is high.
[0103] S303, operate the database based on the second description information.
[0104] In one possible scenario, the processing device can generate a physical execution plan based on the second description information, operate on the database based on the physical execution plan, and output the operation results. When SQL statements are used to query data, the operation result obtained from the database operation is the data retrieved from the query.
[0105] In summary, the statement processing method provided in this application, by adjusting the first description information to the second description information, only needs to calculate the UDF once based on the first operator during the subsequent execution of SQL statements to operate the database. The remaining SQL operators can directly call the function of the first operator to calculate the result, avoiding multiple calculations of the same UDF, resulting in low computational overhead and high execution efficiency. This application is applicable to various SQL engines / frameworks, including but not limited to big data frameworks such as Spark, Flink, and Calcite, demonstrating high versatility. Spark is a memory-based distributed computing engine, Flink is a stream-oriented distributed processing framework, and Calcite is an open-source framework that provides SQL parsing, validation, and optimization functions.
[0106] The above describes the statement processing method of the embodiments of this application. Corresponding to the above method, the embodiments of this application also provide a statement processing device. Figure 7 This is a schematic diagram of the structure of a statement processing device provided in an embodiment of this application. Based on Figure 7 The following modules are shown. Figure 7 The statement processing device shown is capable of performing the above. Figure 3 All or part of the operations shown. It should be understood that the device may include more additional modules than those shown, or may omit some of the modules shown; this application embodiment does not impose limitations in this regard. For example... Figure 7 As shown, the device includes:
[0107] The acquisition module 701 is used to acquire the first description information of an SQL statement. The SQL statement is used to operate the database. The first description information is used to describe multiple SQL operators involved in operating the database based on the SQL statement. At least two of the multiple SQL operators include UDFs.
[0108] The adjustment module 702 is used to adjust the first description information to obtain the second description information when at least two first SQL operators in a plurality of SQL operators include the same first UDF, and the function calculation result of the first UDF in at least two first SQL operators should remain the same. The second description information includes the first operator and the second SQL operator corresponding to the first SQL operator. The first operator is used to calculate the first UDF, and the second SQL operator is used to call the function calculation result of the first operator. The second SQL operator is obtained by adjusting the first SQL operator in the first description information that is different from the first operator. The execution order of the first operator is before the execution order of the second SQL operator.
[0109] Operation module 703 is used to operate the database based on the second description information.
[0110] In one possible implementation, the adjustment module 702 is further configured to count the number of various UDFs based on the first description information; if the number of any UDF is greater than the first number, and the function calculation result of any UDF in different SQL operators should remain the same, then any UDF is determined as the first UDF.
[0111] In one possible implementation, the first operator is different from each of the first SQL operators; the second SQL operator is obtained by replacing the first UDF of any first SQL operator with the calling information of the function computation result, which is used to call the function computation result.
[0112] In one possible implementation, the first description information includes a first SQL tree, which includes multiple nodes, each node corresponding to an SQL operator; the adjustment module 702 is used to add the SQL operator corresponding to the child node of the third SQL operator to the child node of the first operator, wherein the third SQL operator is an operator whose child node corresponding to the SQL operator does not include the first UDF among at least two first SQL operators; the first operator is added to the child node of the third SQL operator; and the second description information is obtained based on the first SQL tree after the addition.
[0113] In one possible implementation, the first operator is the operator that executes first among at least two first SQL operators; the second SQL operator is obtained by replacing the first UDF of the first SQL operator that does not execute first with the calling information of the function computation result, and the calling information is used to call the function computation result.
[0114] In one possible implementation, the call information includes the variable name of the function's evaluation result.
[0115] In one possible implementation, the first operator includes the project operator.
[0116] In one possible implementation, the first UDF includes a random function.
[0117] By adjusting the first description information to the second description information, in the subsequent process of executing SQL statements to operate the database, the first UDF only needs to be calculated once based on the first operator. The remaining second SQL operators, including the first UDF, can directly call the function of the first operator to calculate the result, without having to calculate the first UDF again. By reducing the number of times the first UDF is calculated during the execution of SQL statements, the total time for calculating the first UDF during the execution of SQL statements is reduced, thereby improving the execution efficiency of SQL statements.
[0118] The acquisition module 701, adjustment module 702, and operation module 703 can all be implemented in software or hardware. For example, the implementation of adjustment module 702 will be described below. Similarly, the implementation of acquisition module 701 and operation module 703 can refer to the implementation of adjustment module 702.
[0119] As an example of a software functional unit, the adjustment module 702 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, or a container. Further, the aforementioned computing instance may be one or more. For example, the adjustment module 702 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed within the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code may be distributed within the same availability zone (AZ) or in different AZs, each AZ including one or more geographically proximate data centers. Typically, a region may include multiple AZs.
[0120] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.
[0121] As an example of a hardware functional unit, the adjustment module 702 may include at least one computing device, such as a server. Alternatively, the adjustment module 702 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.
[0122] The multiple computing devices included in the adjustment module 702 can be distributed in the same region or in different regions. Similarly, the multiple computing devices included in the adjustment module 702 can be distributed in the same Availability Zone (AZ) or in different AZs. Likewise, the multiple computing devices included in the adjustment module 702 can be distributed in the same Virtual Private Cloud (VPC) or in multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0123] It should be noted that, in other embodiments, the acquisition module 701, adjustment module 702, and operation module 703 can be used to execute any step in the statement processing method. The steps implemented by the acquisition module 701, adjustment module 702, and operation module 703 can be specified as needed. By implementing different steps in the statement processing method through the acquisition module 701, adjustment module 702, and operation module 703, all functions of the statement processing device can be realized.
[0124] This application also provides a computing device 800. For example... Figure 8As shown, the computing device 800 includes a bus 802, a processor 804, a memory 806, and a communication interface 808. The processor 804, the memory 806, and the communication interface 808 communicate with each other via the bus 802. The computing device 800 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 800.
[0125] The 802 bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 8 The bus 802 may be represented by a single line, but this does not mean that there is only one bus or one type of bus. The bus 802 may include a path for transmitting information between various components of the computing device 800 (e.g., memory 806, processor 804, communication interface 808).
[0126] Processor 804 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0127] The memory 806 may include volatile memory, such as random access memory (RAM). The processor 804 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).
[0128] The memory 806 stores executable program code, and the processor 804 executes the executable program code to implement the functions of the aforementioned acquisition module, adjustment module, or operation module, thereby implementing the statement processing method. That is, the memory 806 stores instructions for executing the statement processing method.
[0129] The communication interface 808 uses transceiver modules such as, but not limited to, network interface cards and transceivers to enable communication between the computing device 800 and other devices or communication networks.
[0130] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0131] Optionally, the structure of at least one computing device included in the computing device cluster can be seen in [reference needed]. Figure 8 The computing device 800 is shown. The memory 806 of one or more computing devices 800 in a computing device cluster may store the same instructions for executing statement processing methods.
[0132] In some possible implementations, the memory 806 of one or more computing devices 800 in the computing device cluster may also store partial instructions for executing statement processing methods. In other words, a combination of one or more computing devices 800 can jointly execute instructions for executing statement processing methods.
[0133] It should be noted that the memories 806 in different computing devices 800 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the statement processing unit. That is, the instructions stored in the memories 806 of different computing devices 800 can implement the functions of one or more modules among the fetch module, adjustment module, or operation module.
[0134] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 9 One possible implementation is shown. For example... Figure 9 As shown, two computing devices 900A and 900B are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this type of possible implementation, computing devices 900A and 900B include a bus 902, a processor 904, a memory 906, and a communication interface 908. The memory 906 in computing device 900A stores instructions for executing the functions of the acquisition module. Meanwhile, the memory 906 in computing device 900B stores instructions for executing the functions of the adjustment module and the operation module.
[0135] Figure 9The connection method between the computing device clusters shown can be based on the fact that the operation module in the statement processing method provided in this application needs to rely on the second descriptive information operation database obtained by the adjustment module. Therefore, it is considered that the functions implemented by the adjustment module and the operation module are handed over to the computing device 900B for execution.
[0136] It should be understood that Figure 9 The functions of the computing device 900A shown can also be performed by multiple computing devices 900. Similarly, the functions of the computing device 900B can also be performed by multiple computing devices 900.
[0137] This application embodiment also provides a communication device, which includes a transceiver, a memory, and a processor. The transceiver, the memory, and the processor communicate with each other via an internal connection path. The memory stores instructions, and the processor executes the instructions stored in the memory to control the transceiver to receive and transmit signals. When the processor executes the instructions stored in the memory, it causes the processor to perform... Figure 3 The statement processing method shown.
[0138] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. General-purpose processors can be microprocessors or any conventional processor. It is worth noting that the processor can be a processor supporting the Advanced Reduced Instruction Set Computing (RISC) machine (ARM) architecture.
[0139] Furthermore, in an alternative embodiment, the memory described above may include read-only memory and random access memory, and provide instructions and data to the processor. The memory may also include non-volatile random access memory. For example, the memory may also store device type information.
[0140] The memory can be volatile or non-volatile, or may include both. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which serves as an external cache. Many forms of RAM are available by way of example, but not limitation. Examples include static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0141] This application also provides a computer program (product) containing instructions. The computer program (product) may be software or a program (product) containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program (product) is run on at least one computing device, it causes the at least one computing device to perform... Figure 3 The statement processing method shown.
[0142] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute... Figure 3 The statement processing method shown.
[0143] This application also provides a chip, including a processor, for calling and executing instructions stored in a memory, causing a communication device equipped with the chip to perform the above-mentioned operations. Figure 3 The statement processing method shown.
[0144] This application embodiment also provides another chip, including: an input interface, an output interface, a processor, and a memory. The input interface, the output interface, the processor, and the memory are connected via internal interconnection paths. The processor is used to execute code in the memory. When the code is executed, the processor is used to perform the above-mentioned actions. Figure 3 The statement processing method shown.
[0145] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive).
[0146] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the first descriptive information involved in this application was obtained with full authorization.
[0147] To clearly illustrate the interchangeability of hardware and software, the steps and components of each embodiment have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.
[0148] Computer program code used to implement the methods of the embodiments of this application may be written in one or more programming languages. This computer program code may be provided to the processor of a general-purpose computer, a special-purpose computer, or other programmable rule-finding device, such that when executed by the computer or other programmable rule-finding device, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a computer, partially on a computer, as a standalone software package, partially on a computer and partially on a remote computer, or entirely on a remote computer or server.
[0149] In the context of the embodiments of this application, computer program code or related data may be carried by any suitable carrier to enable a device, apparatus, or processor to perform the various processes and operations described above. Examples of carriers include signals, computer-readable media, etc. Examples of signals may include electrical, optical, radio, sound, or other forms of propagation signals, such as carrier waves, infrared signals, etc.
[0150] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and modules described above can be found in the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0151] In the embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through some interfaces, devices, or modules, or they may be electrical, mechanical, or other forms of connection.
[0152] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of the embodiments of this application, depending on actual needs.
[0153] Furthermore, the functional modules in the various embodiments of this application can be integrated into one module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module.
[0154] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the metadata involved in this application was obtained with full authorization.
[0155] In this application, the terms "first," "second," etc., are used to distinguish identical or similar items that have substantially the same function and purpose. It should be understood that there is no logical or temporal dependency between "first," "second," and "nth," nor does it limit the quantity or execution order. It should also be understood that although the following description uses the terms "first," "second," etc., to describe various elements, these elements should not be limited by the terms. These terms are merely used to distinguish one element from another. For example, without departing from the scope of the various examples described, a first link can be referred to as a second link, and similarly, a second link can be referred to as a first link.
[0156] It should also be understood that, in the various embodiments of this application, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0157] In this application, the term "at least one" means one or more, and the term "multiple" means two or more. For example, multiple second messages refer to two or more second messages. The terms "system" and "network" are often used interchangeably in this document.
[0158] It should be understood that the terminology used in the description of the various examples herein is for the purpose of describing particular examples only and is not intended to be limiting. As used in the description of the various examples and the appended claims, the singular forms “a” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise.
[0159] It should also be understood that the term “comprising” (also referred to as “includes”, “including”, “comprises” and / or “comprising”) as used in this specification specifies the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0160] It should also be understood that, depending on the context, the phrase “if it is determined that…” or “if [the stated condition or event] is detected” can be interpreted as “when it is determined that…” or “in response to determining that…” or “when [the stated condition or event] is detected” or “in response to detecting [the stated condition or event]”.
[0161] It should be understood that determining B based on A does not mean determining B solely based on A; B can also be determined based on A and / or other information.
[0162] It should also be understood that the phrases "an embodiment," "an embodiment," and "a possible implementation" used throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment or implementation is included in at least one embodiment of this application. Therefore, the phrases "in an embodiment," "an embodiment," or "a possible implementation" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments.
[0163] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of this application.
Claims
1. A statement processing method, characterized in that, The method includes: Obtain first description information of a Structured Query Language (SQL) statement, the SQL statement being used to operate a database, the first description information being used to describe multiple SQL operators involved in operating the database based on the SQL statement, at least two of the multiple SQL operators including user-defined functions (UDFs); If at least two of the plurality of SQL operators include the same first UDF, and the function calculation result of the first UDF in the at least two first SQL operators should remain the same, the first description information is adjusted to obtain second description information. The second description information includes the first operator and the second SQL operator corresponding to the first SQL operator. The first operator is used to calculate the first UDF, and the second SQL operator is used to call the function calculation result of the first operator. The second SQL operator is obtained by adjusting the first SQL operator in the first description information that is different from the first operator. The execution order of the first operator is before the execution order of the second SQL operator. The database is operated based on the second description information.
2. The method according to claim 1, characterized in that, Before adjusting the first description information to obtain the second description information, the method further includes: The number of various UDFs is counted based on the first descriptive information; If the number of any type of UDF is greater than the first number, and the function calculation results of any type of UDF should remain the same under different SQL operators, then any type of UDF shall be determined as the first UDF.
3. The method according to claim 1 or 2, characterized in that, The first operator is different from each of the first SQL operators; The second SQL operator is obtained by replacing the first UDF of any first SQL operator with the calling information of the function calculation result, and the calling information is used to call the function calculation result.
4. The method according to claim 3, characterized in that, The first description information includes a first SQL tree, which includes multiple nodes, and each node corresponds to a SQL operator. The step of adjusting the first descriptive information to obtain the second descriptive information includes: Add the SQL operator corresponding to the child node of the third SQL operator to the child node of the first operator, wherein the third SQL operator is the SQL operator corresponding to the child node of the at least two first SQL operators that does not include the first UDF; Add the first operator to the child node of the third SQL operator; The second description information is obtained based on the first SQL tree after the addition.
5. The method according to claim 1 or 2, characterized in that, The first operator is the operator that is executed first among the at least two first SQL operators; The second SQL operator is obtained by replacing the first UDF of the first SQL operator, which is not executed first, with the calling information of the function calculation result. The calling information is used to call the function calculation result.
6. The method according to any one of claims 3-5, characterized in that, The call information includes the variable name of the function's calculation result.
7. The method according to any one of claims 1-6, characterized in that, The first operator includes the projection operator.
8. A statement processing device, characterized in that, The device includes: The acquisition module is used to acquire first description information of a Structured Query Language (SQL) statement, the SQL statement being used to operate a database, and the first description information being used to describe multiple SQL operators involved in operating the database based on the SQL statement, wherein at least two of the multiple SQL operators include user-defined functions (UDFs). An adjustment module is used to adjust the first description information to obtain second description information when at least two first SQL operators in the plurality of SQL operators include the same first UDF, and the function calculation result of the first UDF in the at least two first SQL operators should remain the same. The second description information includes a first operator and a second SQL operator corresponding to the first SQL operator. The first operator is used to calculate the first UDF, and the second SQL operator is used to call the function calculation result of the first operator. The second SQL operator is obtained by adjusting the first SQL operator in the first description information that is different from the first operator. The execution order of the first operator is before the execution order of the second SQL operator. An operation module is used to operate the database based on the second description information.
9. The apparatus according to claim 8, characterized in that, The adjustment module is further configured to count the number of various UDFs based on the first description information; if the number of any UDF is greater than the first number, and the function calculation result of any UDF should remain the same under different SQL operators, then the any UDF is determined as the first UDF.
10. The apparatus according to claim 8 or 9, characterized in that, The first operator is different from each of the first SQL operators; the second SQL operator is obtained by replacing the first UDF of any first SQL operator with the calling information of the function calculation result, and the calling information is used to call the function calculation result.
11. The apparatus according to claim 10, characterized in that, The first description information includes a first SQL tree, which includes multiple nodes, each node corresponding to an SQL operator; the adjustment module is used to add the SQL operator corresponding to the child node of a third SQL operator to the child node of the first operator, wherein the third SQL operator is the SQL operator whose child node does not include the first UDF among the at least two first SQL operators; add the first operator to the child node of the third SQL operator; and obtain the second description information based on the first SQL tree after the addition.
12. The apparatus according to claim 8 or 9, characterized in that, The first operator is the operator that is executed first among the at least two first SQL operators; the second SQL operator is obtained by replacing the first UDF of the first SQL operator that is not executed first with the calling information of the function calculation result, and the calling information is used to call the function calculation result.
13. The apparatus according to any one of claims 10-12, characterized in that, The call information includes the variable name of the function's calculation result.
14. The apparatus according to any one of claims 8-13, characterized in that, The first operator includes the projection operator.
15. A computing device cluster, characterized in that, The computing device cluster includes at least one computing device, and each computing device includes a processor and memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, such that the cluster of computing devices performs the statement processing method as described in any one of claims 1-7.
16. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer program instructions that, when executed by a cluster of computing devices, perform the statement processing method according to any one of claims 1-7.
17. A chip, characterized in that, The chip includes a processor for running program instructions or code that cause a device containing the chip to perform the statement processing method as described in any one of claims 1-7.
18. A computer program product, characterized in that, The computer program product includes a computer program / instruction that is executed by a processor to cause a computer to perform the statement processing method as described in any one of claims 1-7.