Method and apparatus for optimizing user-defined function, and computer device and medium
By obtaining and analyzing custom function data and database statistical information, performing optimization processing and mapping table construction, the problem of low custom function execution efficiency is solved and more efficient database optimization is achieved.
Patent Information
- Application Number
- PCT/CN2023/085169
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-23
- Filing Date
- 2023-03-30
- Publication Date
- 2024-09-26
AI Technical Summary
In the existing technology, the unpredictability of custom functions makes it difficult for traditional databases to automatically optimize, resulting in low execution efficiency.
By obtaining the initial custom function data and statistical information of the database optimizer, determine the optimization information and perform optimization processing, generate optimization data and compilation feature information to match the execution results, and build an input-output mapping table to improve the execution of the custom function efficiency.
It improves the execution efficiency of custom functions, reduces redundant execution, improves running speed, and solves the problem of difficulty in optimizing custom functions in traditional databases.
Smart Images

Figure CN2023085169_26092024_PF_FP
Abstract
Description
A custom function optimization method, device, computer equipment and medium Technical Field
[0001] The present application relates to the field of computers, and in particular to a method, apparatus, computer equipment, and medium for optimizing user-defined functions. Background Art
[0002] PL is a procedural programming language (PL). It's an extension of SQL (Structured Query Language). Building on the foundation of standard SQL statements, it adds programming language features, organizing data operations and query statements within the procedural nature of PL code. It implements complex functions through logical reasoning, loops, and other operations. PL enables the development of programs with many advanced features, encapsulating business logic within the database, providing greater abstraction and security. It also reduces network interactions, speeds up calls, and improves overall performance.
[0003] A User Defined Function (UDF) is a programmable, extensible database object that extends the capabilities of database functions, allowing you to customize function implementation based on business application logic. The internal implementation language of a UDF can be based on a procedural programming language or a more general high-level language.
[0004] A UDF is a routine that receives parameters, performs an action, and returns the result of that action.
[0005] In existing technical solutions, users usually create custom functions based on PL to achieve business customization capabilities. Due to the unpredictability of user function implementation, it is difficult for traditional databases in existing technologies to automatically optimize custom functions.
[0006] Summary of the Invention
[0007] In view of the above problems, the present application is proposed to provide a custom function optimization method, apparatus, computer device, and medium that overcome the above problems or at least partially solve the above problems, including:
[0008] A user-defined function optimization method, comprising:
[0009] Get the initial custom function data and the statistics loaded by the optimizer of the preset database;
[0010] determining optimization information based on the initial custom function data and the statistical information;
[0011] Optimizing the initial user-defined function data according to the optimization information to obtain optimized data; the optimized data includes target user-defined function data and compilation feature information;
[0012] An execution result matching the target user-defined function data is output based on the compilation feature information.
[0013] Furthermore, the method further comprises:
[0014] In a case where the compilation feature information has a fixed output feature, determining fixed output information of the target custom function data;
[0015] The fixed output information is cached.
[0016] Furthermore, the method further comprises:
[0017] In the case that the compilation feature information has a mapping feature, a mapping information table is constructed; the mapping information table is used to record the input-output mapping relationship of the target user-defined function data.
[0018] Furthermore, outputting an execution result matching the target custom function data based on the compilation feature information includes:
[0019] When the compilation feature information has a fixed output feature and the first input information is received, the fixed output information is determined as the execution result of the target custom function data.
[0020] Furthermore, outputting an execution result matching the target custom function data based on the compilation feature information includes:
[0021] When a mapping feature exists in the compilation feature information and second input information is received, determining whether target output information corresponding to the second output information exists in the mapping information table;
[0022] If target output information corresponding to the second output information exists in the mapping information table, the target output information is determined to be the execution result of the target custom function data.
[0023] Furthermore, the outputting of the execution result matching the target custom function data further includes:
[0024] If the second output information does not exist in the mapping information table, executing the instruction included in the target custom function data to obtain the target output information;
[0025] storing a mapping relationship between the second output information and the target output information in the mapping information table;
[0026] The target output information is determined to be an execution result of the target custom function data.
[0027] Furthermore, the statistical information includes data characteristics and server hardware information used to deploy the database;
[0028] The optimization process includes: reducing computational complexity, code filling, result pre-computation, redundancy removal, constant optimization, and expression optimization.
[0029] A user-defined function optimization device, comprising:
[0030] The acquisition module is used to obtain the initial custom function data and the statistics loaded by the optimizer of the preset database;
[0031] an optimization information determination module, configured to determine optimization information based on the initial custom function data and the statistical information;
[0032] an optimization processing module, configured to optimize the initial user-defined function data according to the optimization information to obtain optimized data; the optimized data includes target user-defined function data and compilation feature information;
[0033] An execution result output module is used to output an execution result matching the target custom function data based on the compilation feature information.
[0034] A computer device comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the steps of the above-mentioned custom function optimization method when executed by the processor.
[0035] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the user-defined function optimization method described above.
[0036] This application has the following advantages:
[0037] In an embodiment of the present application, in response to the problem in the prior art that it is difficult for traditional databases to automatically optimize custom functions due to the unpredictability of user function implementation, the present application provides a solution for optimizing custom function data in combination with a database optimizer, specifically: obtaining initial custom function data and statistical information loaded by the optimizer of a preset database; determining optimization information based on the initial custom function data and the statistical information; optimizing the initial custom function data according to the optimization information to obtain optimized data; the optimized data includes target custom function data and compilation feature information; and outputting an execution result that matches the target custom function data based on the compilation feature information. By optimizing the initial custom function data in combination with the statistical information loaded by the optimizer of the database, the optimized target custom function data and its compilation feature information are obtained, and the execution result that matches the target custom function is output based on the compilation feature information, the problem in the prior art that it is difficult to optimize custom functions in traditional databases is solved, and the optimization of the custom function data in combination with the optimizer of the database is achieved, the execution efficiency of the custom function data is improved, and the running speed of the custom function data is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for the description of the present application. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0039] FIG1 is a flowchart of a method for optimizing a user-defined function according to an embodiment of the present invention;
[0040] FIG2 is an example flow chart of a custom function optimization method provided by an embodiment of the present application;
[0041] FIG3 is a flowchart of another method for optimizing a user-defined function according to an embodiment of the present application;
[0042] FIG4 is an example flow chart of another method for optimizing a user-defined function according to an embodiment of the present application;
[0043] FIG5 is a structural block diagram of a user-defined function optimization device provided in one embodiment of the present application;
[0044] FIG6 is a schematic structural diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0045] To make the objectives, features, and advantages of this application more readily apparent, the present application is further described below in conjunction with the accompanying drawings and specific embodiments. It is apparent that the embodiments described are only a portion of the embodiments of this application, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments in this application without inventive effort are also within the scope of protection of this application.
[0046] The inventors have found through analysis of existing technologies that code optimization is an important part of computer software development. The main existing code optimization methods include the following three:
[0047] (1) C++ compilation optimization: The " / O" option can set a combination of optimization items to optimize the code to achieve maximum speed, control the expansion of inline functions, create a frame pointer on the stack, etc.
[0048] (2) JAVA compilation optimization: The just-in-time compiler can perform a series of optimizations on the running service, such as analysis during bytecode parsing, local optimization of the intermediate form of the code during the compilation process, and global optimization based on the program dependency graph, and finally generate machine code.
[0049] (3) ORACLE: The ORACLE database provides the PLSQL_OPTIMIZE_LEVEL parameter to determine the optimization level during PL compilation. This parameter removes unnecessary calculations and exception modules, and also performs row pre-reading. There are three optimization levels. The higher the optimization level, the better the execution performance, but the longer the compilation time. ORACLE's optimization method is rule-based. That is, once the optimization level is set, the PL will be optimized according to all optimization rules at that level, even if there is a negative optimization.
[0050] Because high-level languages are optimized during compilation, the user-entered code and the optimized, executed code may differ. Existing database technologies don't perform the same code optimization for stored procedures as high-level languages. In other words, user-entered code is translated into machine language without modification, leading to redundant execution in many scenarios. Even some stored procedure code-level optimizations (such as those implemented in Oracle) only optimize the code within the program logic (PL). The custom function itself still requires hardware resources to execute. Due to the unpredictability of custom functions, the aforementioned optimization methods cannot automatically optimize them.
[0051] It should be noted that, in any embodiment of the present invention, the optimization is specifically targeted at custom functions implemented based on PL, and more specifically, the optimization is targeted at PL / SQL that calls the custom function. The called custom function specifically refers to the initial custom function data and target custom function data mentioned below.
[0052] 1 , a flowchart of a method for optimizing a user-defined function according to an embodiment of the present invention is shown. The method includes:
[0053] S101. Obtaining initial custom function data and statistics loaded by the optimizer of the preset database;
[0054] S102: Determine optimization information based on the initial custom function data and the statistical information;
[0055] S103, optimizing the initial user-defined function data according to the optimization information to obtain optimized data; the optimized data includes target user-defined function data and compilation feature information;
[0056] S104: Outputting an execution result that matches the target custom function data based on the compilation feature information.
[0057] In an embodiment of the present application, in response to the problem in the prior art that it is difficult for traditional databases to automatically optimize custom functions due to the unpredictability of user function implementation, the present application provides a solution for optimizing custom function data in combination with a database optimizer, specifically: obtaining initial custom function data and statistical information loaded by the optimizer of a preset database; determining optimization information based on the initial custom function data and the statistical information; optimizing the initial custom function data according to the optimization information to obtain optimized data; the optimized data includes target custom function data and compilation feature information; and outputting an execution result that matches the target custom function data based on the compilation feature information. By optimizing the initial custom function data in combination with the statistical information loaded by the optimizer of the database, the optimized target custom function data and its compilation feature information are obtained, and the execution result that matches the target custom function is output based on the compilation feature information, the problem in the prior art that it is difficult to optimize custom functions in traditional databases is solved, and the optimization of the custom function data in combination with the optimizer of the database is achieved, the execution efficiency of the custom function data is improved, and the running speed of the custom function data is improved.
[0058] Next, a user-defined function optimization in this exemplary embodiment will be further described.
[0059] As described in step S101, the initial user-defined function data and the statistical information loaded by the optimizer of the preset database are obtained.
[0060] In one embodiment of the present invention, the specific process of "obtaining initial user-defined function data and statistical information loaded by the optimizer of the preset database" in step S101 can be further explained in combination with the following description.
[0061] Initial custom function data is the custom function data to be optimized. It can be obtained by initial user input or read from a specified storage space. The initial custom function data can include an SQL code portion and a custom function code portion.
[0062] The database associated with the initial custom function data is determined, and the optimizer statistics pre-configured for the database are loaded. It is understood that a database generally does not reside on one or more servers. The optimizer statistics include, but are not limited to, database data characteristics and hardware information of the server used to deploy the database. For example, data characteristics may include the size of the data in the database, data distribution, and parameters included (e.g., NULL values (invalid values)). Hardware information may include server load information, capacity information, computing resources, etc.
[0063] In an embodiment of the present invention, the specific process of "determining optimization information based on the initial custom function data and the statistical information" in step S102 can be further explained in combination with the following description.
[0064] The optimizer identifies the initial custom function data and then determines optimization information for it based on statistical information. This optimization information includes the optimization method, the code to be optimized, and the target code. The target code is the code that has been optimized according to the optimization method. The database optimizer participates in the selection of the optimization method and the rewriting and optimization of the initial custom function data, enabling the dynamic selection of the optimal optimization method based on the hardware and software environment of the target server (the server executing the initial custom function data).
[0065] In one example, it can be determined based on statistical information that the code to be optimized is the SQL part, and the optimization method is to preferentially select an index to rewrite the code to be optimized to obtain the target code.
[0066] In one example, when the initial custom function data contains a query predicate query condition that determines whether there are NULL values in the data set, if it is determined based on statistical information that there are NULL values in the data set, it can be determined that there is no need to retrieve the data in the data set, and the optimization method is determined to directly return TRUE / FALSE, and the initial custom function data is optimized in accordance with the method of directly returning TRUE / FALSE.
[0067] In one example, based on statistical information, an optimization method is determined to be to expand a new predicate condition for the custom function code portion, thereby reducing the number of executions by lowering the selectivity.
[0068] In one example, based on statistical information, the amount of computation of different codes in the initial custom function can be determined, and some expressions can be moved to locations with less computation.
[0069] In a specific implementation, the PL optimization as described above may be performed on the initial user-defined function data before executing step S102 .
[0070] In one embodiment of the present invention, the specific process of step S103 of "optimizing the initial custom function data according to the optimization information to obtain optimized data; the optimized data includes target custom function data and compilation feature information" can be further explained in combination with the following description.
[0071] In one embodiment of the present invention, the optimization process may include but is not limited to at least one of reducing computational complexity, code filling, result pre-computation, redundancy removal, constant optimization, and expression optimization.
[0072] Reducing computational complexity may involve rewriting the SQL code portion, for example, reducing the amount of query computation in the SQL code portion.
[0073] Code filling can include, but is not limited to, constructing predicate conditions, expanding query conditions, and reducing computational complexity. PL code logic can be rigorously demonstrated mathematically. Therefore, in the database field, code logic can be transformed by sorting out logical relationships and performing equivalent transformations based on relational algebra. For example, if the initial custom function data contains the logical relationships A>B and B>C, the logical relationship A>C can be inferred based on these two logical relationships. Adding the logical relationship A>C to the code increases the number of logical relationships A>C that can be selected during execution. In some scenarios, directly using the logical relationship A>C can improve operational efficiency.
[0074] Pre-calculation of results can be used to predetermine the query results for DML (Data Manipulation Language) statements with fixed query results. For example, the initial custom function data contains the SQL statement: select count(*) from table_name where column_name is null. This code calculates the number of NULL entries in the column named column_name in the table table_name. If the statistics indicate that column_name cannot be NULL, the result of this SQL statement will always be 0. This avoids the need to search the table table_name data every time the initial custom function is executed, and each time the number of non-null entries is found, which would result in unnecessary queries.
[0075] Redundancy removal can refer to deleting invalid code that does not need to be executed. For example, the initial custom function data is:
[0076] Among them, "select count(*)into a from table_name" is used to scan the table_name table and obtain all the data. However, the subsequent code does not use the variable a, so this query is meaningless. Even though it complies with the grammatical rules, it is redundant code. Therefore, this type of grammatically redundant code is deleted to improve execution performance.
[0077] Constant optimization can be used for expressions with fixed results, pre-calculating the results and rewriting the initial custom function data according to the results.
[0078] Expression optimization can mean moving the expression to a location in the initial custom function data where the computational complexity is likely to be smaller. For example, the initial custom function data is:
[0079] In the initial custom function data, "a=select count(*)from table_name;" will be executed once every time at the beginning, but the result will be returned only when col1 is not 1. If the code "a=select count(*)from table_name;" is moved to the else branch, and the "a=select count(*)from table_name;" operation is performed when col1 is not 1, the execution efficiency will be greatly improved when the col1 value is 1. Therefore, the optimization method at this time is to move the code "a=select count(*)from table_name;" to the else branch.
[0080] In an embodiment of the present invention, the specific process of "outputting an execution result matching the target user-defined function data based on the compilation feature information" in step S103 may be further explained in conjunction with the following description.
[0081] The compilation feature information may refer to the function features of the initial user-defined function during the compilation phase, such as outputting a fixed value or different output values corresponding to different inputs.
[0082] By outputting the execution results of the optimized custom function data matching based on the compilation feature information, the compilation features of the target custom function data can be identified in advance, so that when the target custom function data is called, the execution of the code in the target custom function data can be reduced. Even for the target custom function data with fixed output values, the execution results can be directly output, avoiding the problem in the prior art that each time the target custom function data is called, the code contained in it needs to be executed, resulting in a decrease in operating efficiency.
[0083] The following example further illustrates the above embodiment. Referring to FIG2 , there is shown an example flow chart of a custom function optimization method provided by an embodiment of the present application. In this example, the initial custom function data includes the SQL code portion (SQL statement): "select udf(col1,1)+2from t1;"
[0084] And the custom function code:
[0085] Perform PL optimization on the function udf(col1,1). This identifies that when col2 == 1, the if branch and the else branch are equivalent. Therefore, the entire udf code can be optimized to a constant 1. The optimizer is called to perform an equivalent rewrite, rewriting the SQL code to "select 1+2 from t1;." The equivalent transformation is then performed, ultimately reducing the SQL code to select 3 from t1.
[0086] In traditional databases, for the initial custom function data in this example, each call executes the operation udf(col1,1)+2. This embodiment of the present invention optimizes the code in advance. In actual execution, each execution uses constant projection, eliminating the need to load the UDF, execute the UDF, and calculate its results, thereby improving performance.
[0087] It should be noted that after the UDF object is optimized, changes to the UDF may not be perceived. Therefore, the SQL statement still depends on the UDF in terms of object execution. Therefore, it is sufficient to check the validity of the UDF function once before execution.
[0088] Furthermore, a custom function code optimization method provided by an embodiment of the present invention can further process the initial custom function data in this example. During UDF compilation, it can be determined that the output is a constant under the input conditions. This allows the optimizer to directly rewrite the UDF as a constant, effectively performing constant optimization. Compared to the projection calculation of udf(col1,1)+2, the constant projection of 3 directly reduces three execution steps (1. Load the UDF; 2. The UDF calculates the output based on the input; 3. The UDF output is used in the projection calculation). This reduces a significant number of operations when calling SQL statements, thereby improving execution speed. It should be noted that while optimization of the initial custom function data may disrupt the original semantics, it does not change the execution results. The code optimization process includes but is not limited to the compilation and optimization stages.
[0089] 3 , a flowchart of another method for optimizing a custom function according to an embodiment of the present application is shown; the method includes:
[0090] S301, obtaining initial custom function data and statistics loaded by the optimizer of the preset database;
[0091] S302: Determine optimization information based on the initial custom function data and the statistical information;
[0092] S303: Optimize the initial user-defined function data according to the optimization information to obtain optimized data; the optimized data includes target user-defined function data and compilation feature information;
[0093] S304: If the compilation feature information has a fixed output feature, determine the fixed output information of the target custom function data;
[0094] The fixed output feature is that the output information of the target custom function data is a fixed value and does not change with the input information. In this case, the fixed value can be determined as the fixed output information of the target custom function data.
[0095] S305, caching the fixed output information;
[0096] Static optimization is performed on fixed output information, and the fixed output information is cached.
[0097] S306: When the compilation feature information has a fixed output feature and first input information is received, determining the fixed output information as an execution result of the target custom function data;
[0098] The compilation feature information of the target user-defined function data may be identified, and when it is a fixed output feature or a mapping feature, the execution result of the target user-defined function data may be output in different ways.
[0099] When the compilation feature information is a fixed output feature, the target custom function data can be executed once and its fixed output information can be determined. When the target custom function data is called, the fixed output information is directly output as the execution result, thereby avoiding the need to execute the instructions contained in the target custom function data each time it is called. When the execution result of the target custom function data can be accurately obtained, the number of times the target custom function data is executed is effectively reduced, thereby improving operating efficiency.
[0100] S307: If the compilation feature information contains a mapping feature, construct a mapping information table; the mapping information table is used to record the input-output mapping relationship of the target custom function data;
[0101] The mapping feature is that the output information of the target custom function data changes with the input information, and different input information can have a certain input-output mapping relationship with its corresponding output information, that is, the output information mapped to the received input information can be determined through the input-output mapping relationship.
[0102] S308: When a mapping feature exists in the compilation feature information and second input information is received, determining whether target output information corresponding to the second output information exists in the mapping information table;
[0103] S309: If target output information corresponding to the second output information exists in the mapping information table, determining that the target output information is the execution result of the target custom function data;
[0104] S310: If the second output information does not exist in the mapping information table, execute the instruction included in the target custom function data to obtain the target output information;
[0105] S311: storing a mapping relationship between the second output information and the target output information in the mapping information table;
[0106] S312: Determine that the target output information is the execution result of the target custom function data.
[0107] When the compiled feature information is a mapping feature, if the mapping information table contains second output information corresponding to the second input information currently received, there is no need to execute the instructions in the target custom function data, and the second output information corresponding to the second input information is directly output. If the mapping information table does not contain second output information corresponding to the second input information currently received, it is necessary to execute the instructions in the target custom function data to obtain the second output information, and use the second output information as the execution result. After determining the second output information, the mapping information is updated by storing the mapping relationship between the second input information and the second output information in the mapping information table, so that the next time the target custom function data is called to process the second input information, the second output information can be determined through the updated mapping information table, and the instructions in the target custom function data can be repeatedly executed indefinitely, which can reduce the number of times the target custom function data is executed to a certain extent and improve operating efficiency.
[0108] The first input information and the second input information are used to indicate that different compilation feature information is processed differently. The embodiment of the present invention does not limit the first input information and the second input information. The first input information and the second input information can be different values or the same value.
[0109] The following is an example to further illustrate the embodiment of the present invention. Referring to FIG4 , there is shown an example flow chart of another method for optimizing a custom function provided by an embodiment of the present application, which includes the following steps:
[0110] S401. Input an SQL statement with UDF.
[0111] S402: Identify the user-defined function (UDF) and optimize it using the optimizer according to established optimization rules. This involves working with the database optimizer, which loads statistical information, determines and selects optimization rules, and optimizes the UDF code. After optimization, the compiler obtains UDF compilation characteristics, such as whether the function has fixed outputs and whether there are specific input-output mappings. For UDFs with fixed outputs, static optimization is performed and the output results are cached.
[0112] S403. Execute the UDF. This includes: for statically optimized UDFs, directly returning the result; for UDFs with fixed input and output results, obtaining the output result by inputting parameters in the "input-output mapping information table" and then returning the result; for UDFs with fixed input and output results, if the result cannot be found in the mapping information table, executing all instructions in the UDF function at once, caching the execution result in the mapping information table for use in the next call, and returning the result;
[0113] S404, output the result.
[0114] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0115] 5 , a user-defined function optimization device provided by an embodiment of the present application is shown; specifically, it includes:
[0116] The acquisition module 401 is used to obtain the initial custom function data and the statistical information loaded by the optimizer of the preset database;
[0117] An optimization information determination module 402 is configured to determine optimization information based on the initial user-defined function data and the statistical information;
[0118] An optimization processing module 403 is configured to optimize the initial user-defined function data according to the optimization information to obtain optimized data; the optimized data includes target user-defined function data and compilation feature information;
[0119] The execution result output module 404 is configured to output an execution result that matches the target user-defined function data based on the compilation feature information.
[0120] In one embodiment of the present invention, the apparatus further comprises:
[0121] a fixed output information determining module, configured to determine the fixed output information of the target custom function data if the compiled feature information has a fixed output feature;
[0122] The fixed output information cache module is used to cache the fixed output information.
[0123] In one embodiment of the present invention, the apparatus further comprises:
[0124] A mapping information table construction module is used to construct a mapping information table when the compilation feature information has a mapping feature; the mapping information table is used to record the input-output mapping relationship of the target custom function data.
[0125] In one embodiment of the present invention, the execution result output module 404 includes:
[0126] The first output submodule is configured to, when the compiled feature information has a fixed output feature and first input information is received, determine the fixed output information as an execution result of the target custom function data.
[0127] In one embodiment of the present invention, the execution result output module 404 includes:
[0128] an output query submodule, configured to, when a mapping feature exists in the compiled feature information and second input information is received, determine whether target output information corresponding to the second output information exists in the mapping information table;
[0129] The second output submodule is configured to determine that the target output information is an execution result of the target custom function data if target output information corresponding to the second output information exists in the mapping information table.
[0130] In one embodiment of the present invention, the execution result output module 404 further includes:
[0131] an execution submodule, configured to execute the instructions included in the target custom function data to obtain the target output information if the second output information does not exist in the mapping information table;
[0132] a mapping relationship storage submodule, configured to store a mapping relationship between the second output information and the target output information in the mapping information table;
[0133] The third output submodule is used to determine that the target output information is the execution result of the target custom function data.
[0134] In one embodiment of the present invention, the statistical information includes data characteristics and server hardware information used to deploy the database;
[0135] The optimization process includes: reducing computational complexity, code filling, result pre-computation, redundancy removal, constant optimization, and expression optimization.
[0136] 6 , a computer device for a user-defined function optimization method of the present invention is shown, which may specifically include the following:
[0137] The computer device 12 is a general-purpose computing device. The components of the computer device 12 may include but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0138] The bus 18 represents one or more of several types of bus 18 structures, including a memory bus 18 or memory controller, a peripheral bus 18, an accelerated graphics port, a processor, or a local bus 18 that utilizes any of a variety of bus 18 architectures. Examples of such architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus 18, a Micro Channel Architecture (MAC) bus 18, an Enhanced ISA bus 18, an Audio Video Electronics Standards Association (VESA) local bus 18, and a Peripheral Component Interconnect (PCI) bus 18.
[0139] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0140] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be configured to read and write to non-removable, non-volatile magnetic media (commonly referred to as a "hard drive"). Although not shown in FIG. 6 , a magnetic disk drive may be provided for reading and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), as well as an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media). In these cases, each drive may be connected to bus 18 via one or more data media interfaces. The memory may include at least one program product having a set (e.g., at least one) of program modules 42 configured to perform the functions of various embodiments of the present invention.
[0141] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in a memory. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules 42, and program data, each of which, or some combination thereof, may include an implementation of a network environment. The program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0142] The computer device 12 can also communicate with one or more external devices 14 (e.g., a keyboard, pointing device, display 24, camera, etc.), one or more devices that enable a user to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication can occur via an input / output (I / O) interface 22. Furthermore, the computer device 12 can communicate with one or more networks (e.g., a local area network (LAN)), a wide area network (WAN), and / or a public network (e.g., the Internet) via a network adapter 20. As shown, the network adapter 20 communicates with the other modules of the computer device 12 via a bus 18. It should be understood that, although not shown in FIG. 6 , other hardware and / or software modules can be used in conjunction with the computer device 12, including but not limited to microcode, device drivers, redundant processing units 16, external disk drive arrays, RAID systems, tape drives, and data backup storage systems 34.
[0143] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing a user-defined function optimization method provided by an embodiment of the present invention.
[0144] That is, when the processing unit 16 executes the program, it implements: obtaining initial custom function data and statistical information loaded by the optimizer of the preset database; determining optimization information based on the initial custom function data and the statistical information; optimizing the initial custom function data according to the optimization information to obtain optimized data; the optimized data includes target custom function data and compilation feature information; and outputting an execution result that matches the target custom function data based on the compilation feature information.
[0145] In an embodiment of the present invention, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a custom function optimization method as provided in all embodiments of the present application:
[0146] That is, when the program is executed by the processor, it is implemented as follows: obtaining initial custom function data and statistical information loaded by the optimizer of the preset database; determining optimization information based on the initial custom function data and the statistical information; optimizing the initial custom function data according to the optimization information to obtain optimized data; the optimized data includes target custom function data and compilation feature information; and outputting an execution result that matches the target custom function data based on the compilation feature information.
[0147] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0148] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0149] The computer program code for performing the operations of the present invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to connect through the Internet). The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referenced to each other.
[0150] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0151] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.
[0152] The above is a detailed introduction to the........ provided by this application. Specific examples are used in this article to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method of this application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on this application.
Claims
1. A custom function optimization method, It is characterized in that include: Get the initial custom function data and the statistics loaded by the optimizer of the preset database; Determining optimization information based on the initial custom function data and the statistical information; Optimizing the initial user-defined function data according to the optimization information to obtain optimized data; the optimized data includes target user-defined function data and compilation feature information; An execution result matching the target user-defined function data is output based on the compilation feature information.
2. The method according to claim 1, It is characterized in that The method further comprises: In a case where the compilation feature information has a fixed output feature, determining fixed output information of the target user-defined function data; The fixed output information is cached.
3. The method according to claim 1 or 2, It is characterized in that The method further comprises: In the case where the compilation feature information has a mapping feature, a mapping information table is constructed; the mapping information table is used to record the input-output mapping relationship of the target user-defined function data.
4. The method according to claim 2, It is characterized in that The outputting of the execution result matching the target custom function data based on the compilation feature information includes: When the compilation feature information has a fixed output feature and the first input information is received, the fixed output information is determined as an execution result of the target custom function data.
5. The method according to claim 3, It is characterized in that The outputting of the execution result matching the target user-defined function data based on the compilation feature information includes: When the compilation feature information has a mapping feature and the second input information is received, determining whether the mapping information table has target output information corresponding to the second output information; If the mapping information table contains target output information corresponding to the second output information, the target output information is determined to be the execution result of the target custom function data.
6. The method according to claim 5, It is characterized in that The output is an execution result that matches the target custom function data, and further includes: If the second output information does not exist in the mapping information table, executing the instruction included in the target custom function data to obtain the target output information; storing a mapping relationship between the second output information and the target output information in the mapping information table; The target output information is determined to be an execution result of the target custom function data.
7. The method according to claim 1, It is characterized in that The statistical information includes data characteristics and server hardware information used to deploy the database; The optimization process includes: reducing computational complexity, code filling, result pre-computation, redundancy deletion, constant optimization, and expression optimization.
8. A custom function optimization device, It is characterized in that include: The acquisition module is used to obtain the initial custom function data and the statistics loaded by the optimizer of the preset database; An optimization information determination module, used to determine optimization information based on the initial custom function data and the statistical information; An optimization processing module, used for optimizing the initial user-defined function data according to the optimization information to obtain optimized data; the optimized data includes target user-defined function data and compilation feature information; An execution result output module is used to output an execution result matching the target user-defined function data based on the compilation feature information.
9. A computer device, It is characterized in that The method comprises a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the method according to any one of claims 1 to 7 when executed by the processor.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Code optimization method and device based on artificial intelligence, equipment and storage medium
CN113821251A
User defined functions for database query languages based on call-back functions
US11216454B1
User defined functions for data loading
US20120239612A1
Optimization of parallelization of user-defined functions with flexible partitioning
US20150379077A1
Pragma facility and SQL3 extension for optimal parallel UDF execution
US6067542A
