Database Routine Overloading Resolution Method, Apparatus, Electronic Device, and Storage Medium
By obtaining and preprocessing the information of database calling routines and iteratively matching with routine weight algorithms, the existing database Gbase 8s single support problem for traditional position expressions when function overloading resolutions is solved, and the adaptation to multiple parameter expressions and the stability improvement of routine overloading is achieved.
Patent Information
- Application Number
- CN202510260116.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-06
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2045-03-06
AI Technical Summary
The existing database gbase 8s only handles traditional position expressions when function overload resolutions, and cannot adapt to other expressions, resulting in reduced stability of routine overloading and cannot meet the call matching requirements of multiple parameter expressions.
By obtaining the calling routine information, including parameter type, number, expression method, etc., preprocessing is performed to initialize the priority list of the parameter, search for routines with the same name, and iteratively match through routine weighting algorithms, and determine the unique target routine to execute the call.
It realizes support for multiple parameter expression methods, calls different routines according to different incoming parameters, improves the readability and reusability of the code and enhances the stability of routine overloading.
Smart Images

Figure CN119759460B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of databases, and particularly relates to a method, device, electronic device, and storage medium for database routine overloading resolution. Background Art
[0002] Routine overloading in a database means defining routines with the same name but different parameter lists within the same scope. In this way, when calling this routine, the corresponding routine will be automatically matched and executed according to the type and number of input parameters. By using routine overloading, different operations can be performed according to different input parameter types, making the code more flexible and easier to understand.
[0003] Complex data types in a database cannot be matched with a single type like simple data types. Especially for complex types that can have an inheritance relationship, special processing is required in the type matching step during function overloading resolution, otherwise the credibility of routine overloading will be reduced; currently, the gbase 8s database function overloading only processes the case where the input parameters are in the traditional positional notation, and is not applicable to other notations. Introducing other notations will lead to a decrease in the stability of routine overloading and cannot meet the routine call matching. Summary of the Invention
[0004] In view of this, this application aims to propose a method, device, electronic device, and storage medium for database routine overloading resolution to solve the above deficiencies.
[0005] To achieve the above object, the technical solution of this application is realized as follows:
[0006] In a first aspect, this application provides a method for database routine overloading resolution, which is characterized by including:
[0007] Obtain call routine information, where the routine information at least includes parameter passing type, number of parameter passes, expression method of parameter passes, routine name, routine parameter type, and number of routine parameters;
[0008] Preprocess the routine information to initialize the priority list of each parameter pass;
[0009] Search for all routines with the same name according to the routine name, and perform iterative matching on all the searched routines with the same name through a routine weight algorithm to determine a unique target routine, and execute the call according to the target routine.
[0010] In a second aspect, based on the same inventive concept, this application also provides a device for database routine overloading resolution, including:
[0011] An information acquisition module, configured to acquire call routine information, where the routine information at least includes argument passing types, the number of arguments, the expression methods of arguments, routine names, routine parameter types, and the number of routine parameters;
[0012] A preprocessing module, configured to preprocess the routine information to initialize the priority list of each argument;
[0013] A routine call module, configured to search for all routines with the same name according to the routine name, and perform iterative matching on all the searched routines with the same name through a routine weight algorithm to determine a unique target routine, and execute the call according to the target routine.
[0014] In a third aspect, based on the same inventive concept, the present application further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the method described in the first aspect is implemented.
[0015] In a fourth aspect, based on the same inventive concept, the present application further provides a non-transitory computer-readable storage medium, where the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to cause the computer to execute the method described in the first aspect.
[0016] Compared with the prior art, the database routine overloading resolution method, device, electronic device, and storage medium described in the present application have the following beneficial effects:
[0017] The database routine overloading resolution method, device, electronic device, and storage medium described in the present application are applicable to multiple argument expression methods, can call different routines according to different incoming parameters, and effectively improve the readability and reusability of the code through routine overloading. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:
[0019] Figure 1 It is a flowchart of a database routine overloading resolution method according to an embodiment of the present application;
[0020] Figure 2 It is a schematic structural diagram of a database routine overloading resolution device according to an embodiment of the present application;
[0021] Figure 3 It is a schematic hardware structure diagram of the electronic device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0022] To make the objectives, technical solutions, and advantages of this application more clear and understandable, the following further elaborates on this application in detail with reference to specific embodiments and the accompanying drawings.
[0023] It should be noted that unless otherwise defined, the technical terms or scientific terms used in the embodiments of this application should have the ordinary meanings understood by those with ordinary skills in the field to which this application belongs. The "first", "second", and similar terms used in the embodiments of this application do not denote any order, quantity, or importance, but are only used to distinguish different components. Words such as "including" or "comprising" mean that the elements or objects appearing before this word cover the elements or objects listed after this word and their equivalents, without excluding other elements or objects. Words such as "connected" or "linked" are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Upper", "lower", "left", "right", etc. are only used to represent relative position relationships, and when the absolute position of the object being described changes, the relative position relationship may also change accordingly.
[0024] The embodiments of this application are described in detail below with reference to the accompanying drawings.
[0025] Please refer to Figure 1 As shown, this embodiment provides a method for database routine overload resolution, which is characterized by specifically including the following steps:
[0026] Step S101: Obtain call routine information, where the routine information at least includes parameter passing types, the number of parameter passes, the expression methods of parameter passes, routine names, routine parameter types, and the number of routine parameters.
[0027] Specifically, in this embodiment, when a routine is called and there are multiple candidate routines with the same name, routine resolution is required at this time to obtain the final routine.
[0028] When a routine is called, call routine information is collected, that is, the parameter passing (input parameter) structure, including parameter passing types (recording the data types of each parameter during the call), the number of parameter passes (the actual number of parameter passes during the call), the expression methods of parameter passes (including named expression method, positional expression method, and mixed expression method), routine names (recording the names of the target routines called), routine parameter types (recording the parameter types declared in the routine definition), and the number of routine parameters (the actual number of routine parameters during the call), etc.
[0029] Furthermore, there are three ways to represent input parameters when a routine is called: named representation method, positional representation method, and mixed representation method. Specifically as follows:
[0030] Positional expression method: The parameters must be listed in the order in which they are declared;
[0031] Named notation: If parameters are specified using named notation, the order of the parameters does not matter;
[0032] Mixed notation: That is, a mixture of named notation and positional notation;
[0033] Named markers and positional markers (traditional call mode) allow mixed use, but after the first named marker parameter, positional notation is not allowed.
[0034] Example: procedure pr1(c1 int, c2 varchar2, c3 int);
[0035] Positional notation: pr1(1, 'a', 2);
[0036] Named notation: pr1(c2 => 'a', c3 => 2, c1 => 1);
[0037] Mixed notation: pr1(1, c3 => 2, c2 => 'a').
[0038] Step S102: Preprocess the routine information to initialize the priority list of each passed parameter.
[0039] Specifically, in this embodiment, the collected call routine information is preprocessed, mainly for some complex data types, to initialize a priority list, and for the case containing named notation, reorder the passed parameters.
[0040] Specifically, if the passed parameter type is a subtype of the routine parameter type (this will occur when the passed parameter is a row type), its matching implementation method: add the supertype of the passed parameter type to its priority list, and then check whether the routine parameter type is in the passed parameter extension list during subsequent iterations to achieve this.
[0041] If the passed parameter type is a distinct type of the routine parameter type, its matching implementation method: add the source type of the passed parameter type to its priority list, and then check whether the routine parameter type is in the extension list to achieve this.
[0042] Illustrative example:
[0043] create distinct type ty1 as int;
[0044] create distinct type ty2 as ty1;
[0045] create distinct type ty3 as ty2;
[0046] / Three routines are overloaded, only the parameter types are different /
[0047] create or replace package pkg2 as
[0048] procedure f1(a in ty1);
[0049] procedure f1(a in ty2);
[0050] procedure f1(a in int );
[0051] end;
[0052] /
[0053] create or replace package body pkg2 as
[0054] procedure f1(a in ty1)
[0055] as
[0056] begin
[0057] Execute block 1;
[0058] end;
[0059] procedure f1(a in ty2)
[0060] as
[0061] begin
[0062] Execute block 2;
[0063] end;
[0064] procedure f1(a in int)
[0065] as
[0066] begin
[0067] Execute block 3;
[0068] end;
[0069] end;
[0070] /
[0071] Declare
[0072] var ty3;
[0073] begin
[0074] pkg2.f1(var);
[0075] end;
[0076] /
[0077] In the priority list of the passed parameter var, the types are ty2, ty1, int, and the type weights (distances) are 1, 2, 3 respectively. Therefore, ty2 will be preferentially matched, and finally the second routine will be selected to execute execution block 2.
[0078] Step S103: Search for all routines with the same name according to the routine name, and perform iterative matching on all the searched routines with the same name through the routine weight algorithm to determine the unique target routine, and execute the call according to the target routine.
[0079] Specifically, in this embodiment, search for all routines with the same name according to the routine name, and perform iterative matching on all the searched routines by means of weight calculation to obtain the final routine. After matching the unique final routine, the routine can be executed according to the passed parameter.
[0080] To further explain, the iterative processing of all the searched routines with the same name specifically includes the following steps:
[0081] S301: First, check the basic information:
[0082] Match the routine type, whether it is procedure or function;
[0083] Match the routine name;
[0084] The number of passed parameters cannot be greater than the number of routine parameters;
[0085] The number of passed parameters + the number of default values cannot be less than the number of routine parameters;
[0086] If any of the checks fails, the current routine is eliminated, and then the next routine is checked.
[0087] S302: After the basic information check passes, perform special checks on the cases with named notation.
[0088] Check the routine parameter names and the passed parameter names, and eliminate the routines with extra parameters and missing parameters.
[0089] Then perform a reordering of the passed parameters (only for the cases with named notation), so that the passed parameters correspond to the corresponding routine parameters one by one.
[0090] S303. After all the above checks pass, then calculate the weights of all routines that meet the above conditions according to the following rules, and select the final routine.
[0091] The weight of a single parameter is defined as the "distance" between the passed parameter type and the routine parameter type.
[0092] In the simplest case, if the types match exactly, that is, the passed parameter type is the same as the corresponding routine parameter type, then the distance is zero, that is, the weight is set to 0.
[0093] If null is passed in the parameter, then it is defined to match any type in the parameter, and the weight is set to 1.
[0094] If the types do not match exactly, check whether the routine parameter type is in the passed parameter priority list and calculate the distance from the passed parameter type, and obtain the weight according to the distance.
[0095] If it is not matched in the priority list either, then the passed parameter matching fails, and the current routine is eliminated.
[0096] The calculation process is as follows:
[0097] If routines can be found where all passed parameter types match the corresponding routine parameter types (that is, belonging to one of the above three cases a, b, c), then select the best routine by calculating the weights.
[0098] The weight of each passed parameter is w[0] w[1] w[n], where w[0] is the weight of the first parameter and w[n] is the weight of the last specified parameter. It should be noted that: The weight can only be calculated after two types match, and the weight refers to the distance between the passed parameter type and the corresponding routine parameter type.
[0099] Suppose best_w[] represents the routine with the minimum total weight, and w[] represents the weights of all other routines with matching types but not the minimum total weight. best_w[] must meet the following conditions:
[0100] For each non-minimum weight routine, there are some values k, where k <= n - 1;
[0101] such that for i = 0 to k, best_w[i] <= w[i], and best_w[k + 1] < w[k + 1].
[0102] For easy understanding, the following example is given:
[0103] Match the first routine r1;
[0104] w[0] <= best_w[0], w[1] <= best_w[1], w[2] > best_w[2]. At this time, the above conditions are not met, and r1 is eliminated.
[0105] Start matching the second routine r2;
[0106] w[0] <= best_w[0], w[1] <= best_w[1], w[2] < best_w[2]. At this time, reassign the value to best_w, the current best routine is r2, and start matching the next routine.
[0107] Match the second routine r3;
[0108] w[0] = best_w[0], w[1] = best_w[1], w[2] = best_w[2]. At this time, record the conflict. If there is a routine that can satisfy w[0] <= best_w[0], w[1] <= best_w[1], w[2] < best_w[2] later, then clear the conflict record and update the best routine; if it is already the last routine, then report a conflict error.
[0109] The method described in this embodiment is applicable to various parameter passing expression methods, and different routines can be called according to different input parameters. Through routine overloading resolution, the readability and reusability of the code are effectively improved.
[0110] It should be noted that some embodiments of the present application are described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the above embodiments and still achieve the desired result. Additionally, the processes depicted in the figures do not necessarily require the particular order or sequential order shown to achieve the desired result. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0111] Based on the same inventive concept, corresponding to the method of any of the above embodiments, an embodiment of the present application further provides a database routine overloading resolution device.
[0112] As Figure 2 shown, the database routine overloading resolution device includes:
[0113] An information acquisition module 11, configured to acquire call routine information, where the routine information at least includes parameter passing type, number of parameters passed, expression method of the passed parameters, routine name, routine parameter type, and number of routine parameters;
[0114] The preprocessing module 12 is configured to preprocess the routine information to initialize the priority list of each passed parameter;
[0115] The routine call module 13 is configured to search for all routines with the same name according to the routine name, and perform iterative matching on all the searched routines with the same name through the routine weight algorithm to determine the unique target routine, and execute the call according to the target routine.
[0116] For the convenience of description, when describing the above device, it is described by function as various modules respectively. Of course, when implementing the embodiments of the present application, the functions of each module can be implemented in the same or multiple software and / or hardware.
[0117] The device of the above embodiment is used to implement the corresponding method in any of the foregoing embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be described in detail here.
[0118] Based on the same inventive concept, corresponding to the method of any of the above embodiments, an embodiment of the present application further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the method described in any of the above embodiments.
[0119] Figure 3 FIG. shows a more specific schematic diagram of the hardware structure of the electronic device provided in this embodiment. The device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. Among them, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are communicatively connected to each other inside the device through the bus 1050.
[0120] The processor 1010 may be implemented in a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, etc., and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0121] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage devices, dynamic storage devices, etc. The memory 1020 can store an operating system and other application programs. When implementing the technical solutions provided in the embodiments of this specification through software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.
[0122] The input / output interface 1030 is used to connect to the input / output module to achieve information input and output. The input / output module can be configured as a component in the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Among them, the input device can include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device can include a display, a speaker, a vibrator, an indicator light, etc.
[0123] The communication interface 1040 is used to connect to a communication module (not shown in the figure) to achieve communication interaction between this device and other devices. Among them, the communication module can achieve communication through a wired method (such as USB, network cable, etc.) or through a wireless method (such as a mobile network, WIFI, Bluetooth, etc.).
[0124] The bus 1050 includes a path for transmitting information between various components of the device (such as the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).
[0125] It should be noted that although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040, and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, those skilled in the art can understand that the above device may also only include the components necessary to implement the solutions of the embodiments of this specification and do not necessarily include all the components shown in the figure.
[0126] The electronic device in the above embodiment is used to implement the corresponding method in any of the foregoing embodiments and has the beneficial effects of the corresponding method embodiments, which will not be elaborated here.
[0127] Based on the same inventive concept, corresponding to the method in any of the above embodiments, the present application also provides a non-transitory computer-readable storage medium storing computer instructions for causing the computer to execute the method described in any of the above embodiments.
[0128] The computer-readable media of this embodiment include both permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information that can be accessed by a computing device.
[0129] The computer instructions stored in the storage medium of the above embodiment are used to cause the computer to execute the method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be elaborated here.
[0130] Those of ordinary skill in the art should understand that: the discussion of any of the above embodiments is only exemplary and is not intended to imply that the scope of the present application (including the claims) is limited to these examples; under the concept of the present application, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations in different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of brevity.
[0131] In addition, for the sake of simplicity of description and discussion, and in order not to make the embodiments of the present application difficult to understand, the well-known power / ground connections to integrated circuit (IC) chips and other components may or may not be shown in the provided drawings. Moreover, the devices can be shown in block diagram form to avoid making the embodiments of the present application difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform on which the embodiments of the present application will be implemented (i.e., these details should be fully within the understanding of those skilled in the art). In the case where specific details (such as circuits) are set forth to describe the exemplary embodiments of the present application, it will be apparent to those skilled in the art that the embodiments of the present application can be implemented without these specific details or with variations of these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.
[0132] Although the present application has been described in connection with specific embodiments thereof, many alternatives, modifications, and variations of these embodiments will be apparent to those of ordinary skill in the art in light of the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may be used with the embodiments discussed.
[0133] Embodiments of the present application are intended to cover all such alternatives, modifications, and variations that fall within the broad scope of the appended claims. Accordingly, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the embodiments of the present application shall be included within the protection scope of the present application.
Claims
1. A database routine overload resolution method, characterized in that: include: Obtaining calling routine information, wherein the routine information at least includes parameter type, number of parameters, expression of parameter, routine name, routine parameter type, and number of routine parameters; Preprocessing the routine information to initialize a priority list for each parameter passed; Searching for all routines with the same name according to the routine name, and iteratively matching all the searched routines with the same name through a routine weight algorithm to determine a unique target routine, and executing a call according to the target routine; The preprocessing of the routine information includes: In response to the parameter type being a subtype of the routine parameter type, adding all supertypes of the parameter type to its priority list; In response to the parameter type being one of the distinct types of the routine parameter type, adding all source types of the parameter type to its priority list; The step of searching for all routines with the same name according to the routine name, iteratively matching all the searched routines with the same name by using a routine weight algorithm to determine a unique target routine, and executing a call according to the target routine includes: Performing basic information check on all searched routines with the same name, wherein the check includes routine parameter type matching, routine name matching, and comparison of the number of passed parameters with the number of routine parameters; The weight calculation is performed on each parameter passed through the check according to the preset weight rules, wherein the weight rules include: If the parameter type matches the routine parameter type completely, the definition weight is zero; In response to passing null in the routine parameter, the weight is defined as 1; In response to the parameter type not completely matching the routine parameter type, checking whether the routine parameter type is in a parameter priority list, and calculating the distance to the parameter type to obtain a corresponding weight; The routine with the best weight is selected as the final matching target routine to perform the routine call.
2. The method according to claim 1, characterized in that: The expression methods of parameter passing include named expression, positional expression and mixed expression.
3. The method according to claim 1, characterized in that The comparison between the number of passed parameters and the number of routine parameters includes: The number of passed parameters is less than or equal to the number of routine parameters; The number of passed parameters + the number of default values is greater than or equal to the number of routine parameters.
4. The method according to claim 1, characterized in that: It also includes special checks on parameters passed with named expressions after the basic information check has passed: Check the names of routine parameters and passed parameters, eliminate routines with redundant parameters and missing parameters, and reorder the passed parameters so that the passed parameters correspond to the corresponding routine parameters one by one.
5. The method according to claim 1, characterized in that: In response to the routine parameter type not being in the parameter passing priority list, the parameter passing match fails and the current routine is eliminated.
6. A database routine overload resolution device, characterized in that: include: An information acquisition module is configured to acquire calling routine information, wherein the routine information at least includes a parameter type, a number of parameters, a parameter expression method, a routine name, a routine parameter type, and a number of routine parameters; A preprocessing module, configured to preprocess the routine information to initialize a priority list of each parameter; A routine calling module is configured to search for all routines with the same name according to the routine name, and iteratively match all the searched routines with the same name through a routine weight algorithm to determine a unique target routine, and execute the call according to the target routine; The preprocessing of the routine information includes: In response to the parameter type being a subtype of the routine parameter type, adding all supertypes of the parameter type to its priority list; In response to the parameter type being one of the distinct types of the routine parameter type, adding all source types of the parameter type to its priority list; The step of searching for all routines with the same name according to the routine name, iteratively matching all the searched routines with the same name by using a routine weight algorithm to determine a unique target routine, and executing a call according to the target routine includes: Performing basic information check on all searched routines with the same name, wherein the check includes routine parameter type matching, routine name matching, and comparison of the number of passed parameters with the number of routine parameters; The weight calculation is performed on each parameter passed through the check according to the preset weight rules, wherein the weight rules include: If the parameter type matches the routine parameter type completely, the definition weight is zero; In response to passing null in the routine parameter, the weight is defined as 1; In response to the parameter type not completely matching the routine parameter type, checking whether the routine parameter type is in a parameter priority list, and calculating the distance to the parameter type to obtain a corresponding weight; The routine with the best weight is selected as the final matching target routine to perform the routine call.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 5 is implemented.
8. A non-transitory computer-readable storage medium, characterized in that: in, The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to cause a computer to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Distributed system generating rule compiler engine apparatuses, methods, systems and media
CN113574517A
Object reloading method, device and equipment and storage medium
CN113703879A