Database statement analysis method and device, equipment, medium and product
By constructing a syntax tree and creating auxiliary parsing nodes for each expression node, the function OID is resolved according to the call parameters or parent node type, the problem of inaccurate function name resolution in the database system is solved, ensuring the readability and security of the statement.
Patent Information
- Application Number
- CN202510346610.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-07-11
AI Technical Summary
In the database system, when there are many different parameter types, the prior art cannot accurately resolve the function name as function OID, which affects the subsequent execution of the statement.
By constructing a syntax tree and creating auxiliary parsing nodes for each expression node, traversing the syntax tree to determine the function calling node, parsing the OID of the function based on the type of the call parameter or the parameter type of the parent node, avoiding explicit casting.
It realizes accurate parsing of function names under multiple parameter types, ensuring the readability, maintainability and type safety of statements.
Smart Images

Figure CN120296028A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and particularly to a method, apparatus, device, medium and product for parsing statements of a database. Background Art
[0002] In a database system, when the database receives a statement to be processed, and when the statement includes a function call, the database needs to parse the function call for subsequent processing. Specifically, the database resolves the function name to obtain the object identifier (Object Identifier, abbreviated as: OID) of the function according to the mapping relationship, and when executing the statement subsequently, calls the corresponding function according to the OID of the function.
[0003] In the prior art, some databases can be used to process data of multiple different parameter types. In this case, due to the existence of multiple different parameter types, each parameter type corresponds to a different OID. This causes the database to be unable to determine which function OID the function name needs to be resolved to when parsing the statement, thus affecting the subsequent execution of the statement.
[0004] Therefore, in the case where the database can be used to process data of at least two different parameter types, how to more accurately resolve the function name in the statement to the function OID is a technical problem to be solved in this field. Summary of the Invention
[0005] This application provides a method, apparatus, device, medium and product for parsing statements of a database to resolve the function name in the statement to the function OID in the case where the database processes data of at least two different parameter types.
[0006] The first aspect of this application provides a method for parsing statements of a database, including: parsing the statement to be processed to obtain the syntax tree of the statement; constructing a corresponding auxiliary parsing node for each expression node in the syntax tree; traversing each expression node of the syntax tree to determine the function call node in the syntax tree; when the function called by the function call node includes call parameters, resolving the function name according to the parameter type of the call parameters to obtain the OID of the function; when the function called by the function call node does not include call parameters, resolving the function name according to the parameter type of the parent node of the auxiliary parsing node corresponding to the function call node to obtain the OID of the function.
[0007] In an embodiment of the first aspect of the present application, parsing the name of the function to obtain the OID of the function according to the parameter type of the call parameter includes: when the call parameter includes a typed parameter, determining the parameter type of the expression node that has the same parent node as the expression node of the call parameter in the syntax tree; wherein, the typed parameter does not include a constant and / or a bound parameter; determining a target mapping relationship from multiple mapping relationships between function names and OIDs according to the parameter type of the expression node; and parsing the name of the function to obtain the OID of the function according to the target mapping relationship.
[0008] In an embodiment of the first aspect of the present application, parsing the name of the function to obtain the OID of the function according to the parameter type of the call parameter includes: when the call parameter only includes untyped parameters, determining at least one candidate function according to the name of the function and the number of call parameters; when the namespaces of the at least one candidate function are the same, determining the type of the untyped parameter as the type corresponding to the namespace, and determining the parameter type of the expression node that has the same parent node as the expression node of the call parameter in the syntax tree, determining a target mapping relationship from multiple mapping relationships between function names and OIDs according to the parameter type of the expression node, and parsing the name of the function to obtain the OID of the function according to the target mapping relationship; when the namespaces of the at least one candidate function are not completely the same, determining a preset mapping relationship from multiple mapping relationships between function names and OIDs, and parsing the name of the function to obtain the OID of the function according to the preset mapping relationship.
[0009] In an embodiment of the first aspect of the present application, parsing the name of the function to obtain the OID of the function according to the parameter type of the parent node of the auxiliary parsing node corresponding to the function call node includes: determining the parameter type of the parent node of the auxiliary parsing node of the function call node from the linked list of auxiliary parsing nodes; wherein, the auxiliary parsing node includes: a first pointer of the current auxiliary parsing node, a second pointer of the parent node of the current auxiliary parsing node, the parameter type of the current auxiliary parsing node, and the parameter type confirmation method indication information of the current auxiliary parsing node, and the second pointer of each auxiliary parsing node points to the parent node of the auxiliary parsing node, forming a linked list of auxiliary parsing nodes; determining the parameter type of the function call node according to the parameter type of the parent node; determining a target mapping relationship from multiple mapping relationships between function names and OIDs according to the parameter type of the function call node; and parsing the name of the function to obtain the OID of the function according to the target mapping relationship.
[0010] In an embodiment of the first aspect of the present application, determining the parameter type of the function call node according to the parameter type of the parent node includes: determining the parent node of the auxiliary parsing node of the function call node from the linked list of auxiliary parsing nodes; determining the parameter type of the parent node according to the auxiliary parsing node of the parent node; determining the namespace of the function call node according to the parameter type of the parent node; and determining the parameter type of the function call node according to the namespace.
[0011] In an embodiment of the first aspect of the present application, traversing each expression node of the syntax tree includes: when traversing each expression node, replacing the pointer of the auxiliary parsing node in the semantic analysis context with the pointer of the auxiliary parsing node of the current expression node to process the current expression node; and after processing the current expression node, restoring the pointer of the auxiliary parsing node in the semantic analysis context to the pointer of the parent node of the auxiliary parsing node of the current expression node.
[0012] The second aspect of the present application provides a statement parsing device for a database. The database supports processing data of at least two different parameter types, including: a parsing module for parsing a statement to be processed to obtain the syntax tree of the statement; a construction module for constructing a corresponding auxiliary parsing node for each expression node in the syntax tree; a processing module for traversing each expression node of the syntax tree to determine the function call nodes in the syntax tree; when the function called by the function call node includes call parameters, parsing the name of the function to obtain the OID of the function according to the parameter type of the call parameters; and when the function called by the function call node does not include call parameters, parsing the name of the function to obtain the OID of the function according to the parameter type of the parent node of the auxiliary parsing node corresponding to the function call node.
[0013] The third aspect of the present application provides an electronic device, including: a memory and a processor; the memory stores computer-executable instructions; and the processor executes the computer-executable instructions stored in the memory, so that the processor executes the method according to any one of the first aspect of the present application.
[0014] The fourth aspect of the present application provides a computer-readable storage medium storing computer-executable instructions, and when the computer-executable instructions are executed, the method according to any one of the first aspect of the present application is implemented.
[0015] The fifth aspect of the present application provides a computer program product including a computer program, and when the computer program is executed, the method according to any one of the first aspect of the present application is implemented.
[0016] In summary, the present application provides a method, apparatus, device, medium, and product for parsing statements of a database. Specifically, the database parses a statement to be processed to obtain a syntax tree, constructs an auxiliary parsing node for each expression node in the syntax tree, then traverses each expression node to determine function call nodes, and finally, when the function called by a function call node includes call parameters, the OID of the function is parsed according to the parameter types of the call parameters; when the function called by a function call node does not include call parameters, the OID of the function is parsed according to the parameter types of the parent node of the auxiliary parsing node corresponding to the function call node. The statement parsing method provided in this embodiment can parse the function name in a statement into a function OID when the database is used to process data of at least two different parameter types, ensuring the accuracy and effectiveness of parsing the function OID, and also avoiding explicit type casting of function parameters, thus ensuring the readability, maintainability, and type safety of the statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following briefly introduces the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present application, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts.
[0018] Figure 1 Schematic flowchart of an embodiment of the method for parsing statements of a database provided by the present application;
[0019] Figure 2 Schematic diagram of an embodiment of the syntax tree of a statement provided by the present application;
[0020] Figure 3 Schematic flowchart of an embodiment of the method for parsing statements of a database provided by the present application;
[0021] Figure 4 Schematic flowchart of an embodiment of the method for parsing statements of a database provided by the present application;
[0022] Figure 5 Schematic flowchart of an embodiment of the method for parsing statements of a database provided by the present application;
[0023] Figure 6 Schematic diagram of the structure of an apparatus for parsing statements of a database provided by the present application;
[0024] Figure 7 Schematic diagram of the structure of an electronic device provided by the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0025] The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts shall fall within the protection scope of the present application.
[0026] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned accompanying drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such used data can be interchanged under appropriate circumstances so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.
[0027] Before formally introducing the embodiments of the present application, some technical terms involved will be explained first.
[0028] Single-type database system: In this type of database system, there is only one set of data type definitions, and there are no different data types with the same name in such a system.
[0029] Dual-type database system: In this type of database system, there are two sets of data type definitions, and a schema (namespace) is used to isolate between the two sets of data types. Since there are different data types with the same name among the two sets of data types, implicit type conversion rules are usually not allowed between different sets of data types, that is, implicit type conversion in any direction is not supported.
[0030] Multi-type database system: On the basis of a dual-type database system, one or more additional sets of type definitions are added, and the type isolation method and the conversion rules between different sets of types are similar to those of a dual-type database system.
[0031] Expression: It is a meaningful permutation and combination composed of elements such as numbers, operators, parentheses, free variables, and bound variables for calculating numerical values.
[0032] Typed parameter: An expression with a definite data type. For example, in "SELECT id, name FROM books WHERE gt(price, 50.00) AND lt(store, $1)", the parameter "price" of function "gt" and the parameter "store" of function "lt", both being columns of table "books", have definite types.
[0033] Untyped parameter: An expression consisting only of constants or bound parameters, without a definite data type in a binary type database system, and the actual data type needs to be inferred from the context. For example, in "SELECT id, name FROM books WHERE gt(price, 50.00) AND lt(store, $1)", the parameter "50.00" of function "gt" and the parameter "$1" of function "lt" are a constant and a bound parameter respectively.
[0034] This application is specifically applied in a database system. For different data in the statements processed by the database, corresponding parameter types are defined, such as numeric type, character type, date and time type, etc. For example, in a relational database system, the Structured Query Language (SQL for short) can define a set of data type systems.
[0035] When the database receives a statement to be processed, when the statement includes a function call, the database needs to parse the function call for subsequent processing. For the function call in the statement, the SQL language analyzer realizes function parsing by comparing function signatures. Specifically, the database resolves the function name to obtain the object identifier (OID for short) of the function according to the mapping relationship, and when executing the statement subsequently, calls the corresponding function according to the OID of the function. Among them, the function signature includes the following elements: function name, parameter type, parameter order, and number of parameters.
[0036] In different databases, the behaviors of data types with the same name are often different. In some technologies, some databases can be used to process data of multiple different parameter types. For example, in a database supporting a binary type system, there are two sets of data types, and the two sets of data types are isolated by different schemas, resulting in the possibility of having functions with the same name but different numbers, types, or orders of parameters in a database system supporting polymorphic functions.
[0037] In this case, due to the existence of multiple different parameter types, each corresponding to a different OID. When the database parses a statement, in cases where there are constants or bound parameters in the function call parameters of the statement, it is impossible to determine which function OID the function name needs to be parsed into, thus affecting the subsequent execution of the statement.
[0038] Therefore, in the case where the database can be used to process data of at least two different parameter types, how to more accurately parse the function name in the statement into a function OID while avoiding the application from using explicit type coercion for function parameters is a technical problem that needs to be solved in this field.
[0039] Based on this, the present application provides a method, apparatus, device, medium and product for parsing statements in a database to parse the function name in the statement into a function OID when the database processes data of at least two different parameter types. The technical solution of the present application will be described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0040] Figure 1 It is a flowchart of an embodiment of the method for parsing statements in a database provided by the present application. As Figure 1 shown, the method is applied to a database that supports processing data of at least two different parameter types and is specifically executed by the database. Specifically, as Figure 1 shown, the method for parsing statements in a database includes:
[0041] S10: Parse the statement to be processed to obtain the syntax tree of the statement.
[0042] Specifically, after the database obtains the statement to be processed, it can perform syntax parsing on the statement and construct an abstract syntax tree (AST) corresponding to the statement.
[0043] Figure 2 It is a schematic diagram of an embodiment of the syntax tree of the statement provided by the present application. Among them, taking the statement in the embodiment of the present application as a SQL statement as an example, for the SQL statement: SELECT id, name FROM books WHERE gt(price, 50.00) AND lt(store, $1); after the database performs syntax parsing and processing, the syntax tree of the statement as shown in Figure 2 can be obtained.
[0044] S20: Construct a corresponding auxiliary parsing node for each expression node in the syntax tree constructed in S10.
[0045] Specifically, the database can perform semantic analysis on the SQL syntax tree, traverse the syntax tree in a depth-first manner, and construct auxiliary parsing nodes for each expression node. Among them, the auxiliary parsing nodes can be used for subsequent analysis of the data types of the expression nodes.
[0046] As Figure 2 shown, in an embodiment of the present application, the auxiliary parsing node includes: a first pointer (E) of the current auxiliary parsing node, a second pointer (P) of the parent node of the current auxiliary parsing node, a parameter type (T) of the current parsing node, and a parameter type confirmation method indication information (C) of the current auxiliary parsing node. Among them, the second pointer (P) of each auxiliary parsing node points to the first pointer (E) of the parent node of the auxiliary parsing node, forming a linked list of auxiliary parsing nodes.
[0047] Taking Figure 2 as an example, the expression node "WHERE" constructs an auxiliary parsing node N1, the expression node "AND" constructs an auxiliary parsing node N2, the expression node "gt" constructs an auxiliary parsing node N3, the expression node "50.00" constructs an auxiliary parsing node N4, the expression node "lt" constructs an auxiliary parsing node N5, and the expression node "$1" constructs an auxiliary parsing node N6. For example, in the auxiliary parsing node N1 corresponding to the expression node "WHERE", the first pointer (E) is cond, the second pointer (P) is NULL, the parameter type (T) of the current parsing node is bool, and the parameter type confirmation method indication information (C) of the current auxiliary parsing node is false; in the auxiliary parsing node N2 corresponding to the expression node "AND", the first pointer (E) is AND, the second pointer (P) is cond, the parameter type (T) of the current parsing node is bool, and the parameter type confirmation method indication information (C) of the current auxiliary parsing node is false, and so on. N1 - N6 form a linked list of auxiliary parsing nodes.
[0048] S30: Traverse each expression node of the syntax tree to determine the function call nodes in the syntax tree.
[0049] In an embodiment, when the database traverses each expression node of the syntax tree, it replaces the pointer of the auxiliary parsing node in the semantic analysis context with the pointer of the auxiliary parsing node of the current expression node to process the current expression node. After processing the current expression node, it also restores the pointer of the auxiliary parsing node in the semantic analysis context to the pointer of the parent node of the auxiliary parsing node of the current expression node for recursive processing of other expression nodes.
[0050] Subsequently, the database further parses each function call node determined in S30, determines the parameter types of the parameters called by the function call node, and then parses the name of the called function to obtain the OID of the function.
[0051] In the embodiment of the present application, for whether the function call node includes call parameters and whether the call parameters are typed parameters, there are corresponding different processing logics, which will be described separately below.
[0052] S41: When the function called by the function call node includes call parameters, the name of the function is parsed according to the parameter types of the call parameters to obtain the OID of the function.
[0053] In a specific case S51, when the function called by the function call node includes call parameters and the called parameters include typed parameters, the database can infer the target type through other non-typed parameters, determine the exact function signature according to the determined parameter types, and then complete the parsing from the function name to the function object OID. Among them, the typed parameters do not include constants and / or bound parameters;
[0054] In one embodiment, the database determines the parameter type of the expression node 1 that has the same parent node f as the expression node a of the call parameter in the syntax tree through S61. For example, assume there is a function f(a, 1), and assume that the types of a and 1 belong to the same namespace. Then, for the typed parameter a, it is a table column or variable with a clear type. Thus, the parameter type of the expression node a is determined according to the namespace of the expression node a, and then the parameter type of the expression node 1 is inferred. Finally, the target mapping relationship is determined from the mapping relationships between multiple function names and OIDs, and according to the determined target mapping relationship, the name of the function is parsed to obtain the OID of the function.
[0055] In another specific case S52, when the function called by the function call node includes call parameters and the called parameters only include non-typed parameters, it is necessary to further find all candidate functions only according to the function name and the number of parameters. If all candidate functions belong to the same pattern, the non-typed parameters are mapped to the actual types in this pattern to complete the typing of the parameters in the function call.
[0056] In one embodiment, the database can specifically determine at least one candidate function according to the name of the function and the number of call parameters through S52. Subsequently, when the namespaces of the at least one candidate function determined by the database through S53 are the same and belong to the same schema, the parameter type of the expression node that has the same parent node as the expression node of the call parameter in the syntax tree is determined through S62. Then, based on the parameter type of the expression node with the same parent node, it is inferred that the parameter type of the typed parameter expression node is the same as the parameter type of the expression node. Furthermore, the target mapping relationship is determined from multiple function name and OID mapping relationships. Finally, based on the determined target mapping relationship, the name of the function is parsed to obtain the OID of the function.
[0057] When the namespaces of the at least one candidate function are not completely the same, a preset mapping relationship is determined from multiple function name and OID mapping relationships, and based on the preset mapping relationship, the name of the function is parsed to obtain the OID of the function. In this case, even if the parameter type cannot be determined, the parsing of the function can still be achieved through the preset mapping relationship, improving the completeness of the overall process.
[0058] S42: When the function called by the function call node does not include call parameters, the name of the function is parsed to obtain the OID of the function according to the parameter type of the parent node of the auxiliary parsing node corresponding to the function call node.
[0059] In a specific implementation, since the function does not call any parameters, for example, f(), it is necessary to continue to determine the reference type recorded on the upper-level auxiliary parsing node of the function call, and then obtain the schema to which this type belongs. Based on the schema to which the reference type belongs, it is inferred which function object OID in which schema the function name is mapped to.
[0060] In one embodiment, when analyzing the function call node, the database determines the parameter type of the parent node of the auxiliary parsing node of the function call node from the linked list of auxiliary parsing nodes. Subsequently, based on the determined parameter type of the parent node, the parameter type of the current function call node is determined. Then, based on the parameter type of the current function call node, the target mapping relationship is determined from multiple function name and OID mapping relationships. Finally, based on the target mapping relationship, the name of the function is parsed to obtain the OID of the function.
[0061] In one embodiment, according to the parameter type of the parent node, the parameter type of the function call node is determined, which specifically includes: according to the second pointer (P) of the function call node, the parent node of the auxiliary parsing node of the function call node is determined from the auxiliary parsing node linked list, and then according to the parameter type (T) in the auxiliary parsing node of the parent node, the parameter type of the parent node is determined. Thus, according to the parameter type of the parent node, the namespace of the function call node is determined, and finally, according to the namespace, the parameter type of the function call node is determined.
[0062] In summary, in the statement parsing method of the database provided in this embodiment, the database parses the statement to be processed to obtain a syntax tree, constructs an auxiliary parsing node for each expression node in the syntax tree, then traverses each expression node to determine the function call node. Finally, when the function called by the function call node includes call parameters, the OID of the function is parsed according to the parameter type of the call parameters. When the function called by the function call node does not include call parameters, the OID of the function is parsed according to the parameter type of the parent node of the auxiliary parsing node corresponding to the function call node. The statement parsing method provided in this embodiment can parse the function name in the statement into the function OID when the database is used to process data of at least two different parameter types, ensuring the accuracy and effectiveness of parsing the function OID, and also avoiding explicit type casting of function parameters, which can ensure the readability, maintainability and type safety of the statement.
[0063] In one embodiment, when the database analyzes and processes each expression node, it also specifically determines how to convert the parameter type of the target expression node according to the parameter type confirmation method indication information (C) in the auxiliary parsing node corresponding to each expression node. Among them, when the parameter type confirmation method indication information (C) of the auxiliary parsing node of the target expression node is the first preset value (false), the parameter type of the target expression node is converted according to the parameter type of the parent node of the auxiliary parsing node corresponding to the target expression node. When the parameter type confirmation method indication information (C) of the auxiliary parsing node of the target expression node is the second preset value (True), the parameter type of the target expression node is converted according to the specified parameter type of the target expression node directly, realizing explicit type casting. In this embodiment, different methods for determining the parameter type can be adjusted through the indication information in the auxiliary parsing node, improving the flexibility when determining the parameter type, and being more conducive to the application and promotion of the embodiments of the present application.
[0064] Figure 3 This is a flowchart of an embodiment of the statement parsing method of the database provided by the present application, as Figure 3 shown in the embodiment provides Figure 1A specific implementation of the method shown, such as Figure 6 The method for parsing statements of the database shown includes:
[0065] S101, perform syntax parsing on the input SQL statement to construct an SQL abstract syntax tree (AST).
[0066] S102, perform semantic analysis on the SQL syntax tree and traverse the AST in a depth-first manner.
[0067] S103, analyze and process each SQL expression node on the AST one by one and then return.
[0068] S104, complete the analysis and processing of all nodes on the AST to generate a query tree (Query).
[0069] Figure 4 This is a flowchart of an embodiment of the method for parsing statements of the database provided by this application. As Figure 4 shown Figure 3 The method for analyzing and processing expression nodes in a statement shown in Figure 4 includes:
[0070] Step S201, for each SQL expression node, construct an auxiliary parsing node for it on the stack for type inference of its constant sub-nodes. Connect the auxiliary parsing nodes of the sub-SQL expression nodes with the auxiliary parsing nodes of the parent SQL expression node to form a linked list of auxiliary parsing nodes.
[0071] Step S202, replace the pointer of the auxiliary parsing node in the semantic analysis context with the pointer of the auxiliary parsing node of the current SQL expression node.
[0072] Step S203, determine whether each parameter of the SQL expression node is a typed expression node, that is, in the lower-level nodes of the expression parameter, each level of sub-expression cannot be all constants or bound parameters or a combination of both.
[0073] Step S204, obtain the return type of the first typed parameter (expression with a clear data type) of the SQL expression node, record it on the corresponding auxiliary parsing node as the reference type of the non-typed parameter (expression composed only of constants or bound parameters) in the function call.
[0074] Step S205, determine whether the SQL expression node is a function call node.
[0075] Step S206, based on Step S205, if the SQL expression node is not a function call node, execute S201, perform general recursive processing on the node parameters and then return.
[0076] Step S207, based on Step S205 where the SQL expression node is a function call node, process the node and then return.
[0077] Step S208, based on Steps S206 and S207, restore the auxiliary parsing node pointer in the semantic analysis context to the auxiliary parsing node pointer of the parent SQL expression node.
[0078] Figure 5 It is a flowchart of an embodiment of the method for parsing statements in the database provided by this application, as Figure 5 shown Figure 4 the method for analyzing and processing the function call node in the statement, as Figure 5 shown, the method includes:
[0079] Step S301, for each untyped function parameter, through the auxiliary parsing node, find the parent auxiliary parsing node.
[0080] Step S302, for each untyped function parameter, according to the untyped parameter reference type recorded on the parent auxiliary parsing node, obtain the schema (Schema, namespace) to which this type belongs.
[0081] Step S303, if the function has typed parameters, then the target types of other untyped parameters can also be inferred. According to the determined parameter types, the exact function signature can be determined, and further, the parsing from the function name to the function object OID can be completed.
[0082] Step S304, if the function has no parameters, it is necessary to continue to judge the reference type recorded on the upper-level auxiliary parsing node of the function call, and then obtain the schema to which this type belongs. According to the schema to which the reference type belongs, infer which schema's function object OID the function name is mapped to.
[0083] Step S305, if the function has untyped parameters, it is necessary to further find all candidate functions only based on the function name and the number of parameters. If all candidate functions belong to the same schema, map the untyped parameters to the actual types in this schema, complete the typing of the parameters in the function call, and then transfer to S303 for further processing.
[0084] This solution invents a method for parsing polymorphic functions in SQL language in a relational database. In a binary or multi-data type system, according to the semantic context of the function call, the constant or bound parameter type can be automatically inferred as the data type in a certain schema, and based on this, the exact function signature can be determined, and further, the parsing from the function name to the function object OID can be completed, so as to avoid the application using explicit type coercion for function parameters to meet this requirement.
[0085] In the foregoing embodiments of the present application, the method for parsing statements of the database provided by the embodiments of the present application has been introduced. In order to implement each function in the method for parsing statements of the database provided by the embodiments of the present application, the database as the execution subject can be implemented through a hardware structure and / or software module. For example, the above functions can be implemented in the form of a hardware structure, a software module, or a combination of a hardware structure and a software module. Whether a certain function among the above functions is executed in the form of a hardware structure, a software module, or a combination of a hardware structure and a software module depends on the specific application and design constraints of the technical solution.
[0086] For example, Figure 6 is a schematic structural diagram of a device for parsing statements of a database provided by the present application. As Figure 6 shown, the device can be used to execute the method for parsing statements of the database provided in any embodiment of the present application. In one embodiment, as Figure 6 shown, the device 1000 for parsing statements of the database includes: a parsing module 1001, a construction module 1002, and a processing module 1003. Among them, the parsing module 1001 is used to parse the statement to be processed to obtain the syntax tree of the statement; the construction module 1002 is used to construct a corresponding auxiliary parsing node for each expression node in the syntax tree; the processing module 1003 is used to traverse each expression node of the syntax tree to determine the function call nodes in the syntax tree; when the function called by the function call node includes call parameters, the name of the function is parsed according to the parameter type of the call parameters to obtain the OID of the function; when the function called by the function call node does not include call parameters, the name of the function is parsed according to the parameter type of the parent node of the auxiliary parsing node corresponding to the function call node to obtain the OID of the function.
[0087] The specific implementation manner and principle of the above device for parsing statements of the database refer to the description in the foregoing method for parsing statements of the database, and will not be elaborated here.
[0088] It should be noted that the division of each module of the above device is only a division of logical functions. In actual implementation, it can be fully or partially integrated into a physical entity, or physically separated. And these modules can all be implemented in the form of software called by a processing element; they can also all be implemented in the form of hardware; or some modules can be implemented in the form of software called by a processing element, and some modules can be implemented in the form of hardware. For example, the processing module can be a separately established processing element, or it can be integrated in a certain chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and the function of the above determined module can be called and executed by a certain processing element of the above device. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together or can be independently implemented. The processing element mentioned here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed by the integrated logic circuit in the processor element or the instruction in the form of software.
[0089] For example, the above modules can be one or more integrated circuits configured to implement the above method, such as: one or more application specific integrated circuits (ASICs), or, one or more digital signal processors (DSPs), or, one or more field programmable gate arrays (FPGAs), etc. Again, when a certain module above is implemented in the form of a processing element scheduling program code, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processors that can call program code. Again, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0090] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of 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, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. 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 by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that the computer can access or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.
[0091] For example, Figure 7 is a schematic structural diagram of an electronic device provided by the present application. As Figure 7 shown, the device can be used to execute the statement parsing method of the database provided in any embodiment of the present application. In one embodiment, as Figure 7 shown, the electronic device 2000 includes one or more processors 2001 and a memory 2002; wherein, the memory 2002 is used to store computer-executable instructions, and the processor 2001 can execute the computer-executable instructions stored in the memory 2002. When the computer-executable instructions are executed by the processor 2001, the processor 2001 is caused to implement the statement parsing method of any database in the foregoing embodiments of the present application. In one embodiment, as Figure 7 shown, the electronic device 2000 further includes a communication interface 2003. Among them, the processor 2001 can communicate with other devices through the communication interface 2003, such as obtaining a statement to be processed.
[0092] The present application also provides a computer-readable storage medium. The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed, they can be used to implement the statement parsing method of any database in the foregoing embodiments of the present application.
[0093] An embodiment of the present application further provides a chip for executing instructions, and the chip is used to execute the statement parsing method of any of the foregoing databases of the present application.
[0094] An embodiment of the present application further provides a computer program product, including a computer program, which when executed implements the statement parsing method of any of the foregoing databases of the present application.
[0095] Those of ordinary skill in the art can understand that all or part of the steps of implementing the foregoing method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the foregoing method embodiments; and the foregoing storage medium includes: various media such as ROM, RAM, magnetic disk, or optical disc that can store program codes.
[0096] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for parsing statements of a database, characterized in that, The database supports processing data of at least two different parameter types, and the method includes: Parsing a statement to be processed to obtain a syntax tree of the statement; Constructing a corresponding auxiliary parsing node for each expression node in the syntax tree; Traversing each expression node of the syntax tree to determine function call nodes in the syntax tree; When the function called by the function call node includes call parameters, parsing the name of the function according to the parameter types of the call parameters to obtain the OID of the function; When the function called by the function call node does not include call parameters, parsing the name of the function according to the parameter types of the parent nodes of the auxiliary parsing nodes corresponding to the function call nodes to obtain the OID of the function.
2. The method according to claim 1, characterized in that, The parsing the name of the function according to the parameter types of the call parameters to obtain the OID of the function includes: When the call parameters include typed parameters, determining the parameter types of the expression nodes in the syntax tree that have the same parent node as the expression node of the call parameter; wherein, the typed parameters do not include constants and / or bound parameters; Determining a target mapping relationship from multiple mapping relationships between function names and OIDs according to the parameter types of the expression nodes; Parsing the name of the function according to the target mapping relationship to obtain the OID of the function.
3. The method according to claim 1, characterized in that The parsing the name of the function according to the parameter types of the call parameters to obtain the OID of the function includes: When the call parameters only include untyped parameters, determining at least one candidate function according to the name of the function and the number of call parameters; When the namespaces of the at least one candidate function are the same, determining the type of the untyped parameter as the type corresponding to the namespace, and determining the parameter types of the expression nodes in the syntax tree that have the same parent node as the expression node of the call parameter, determining a target mapping relationship from multiple mapping relationships between function names and OIDs according to the parameter types of the expression nodes, and parsing the name of the function according to the target mapping relationship to obtain the OID of the function; When the namespaces of the at least one candidate function are not completely the same, determining a preset mapping relationship from multiple mapping relationships between function names and OIDs, and parsing the name of the function according to the preset mapping relationship to obtain the OID of the function.
4. The method according to any one of claims 1 to 3, characterized in that The parsing the name of the function according to the parameter types of the parent nodes of the auxiliary parsing nodes corresponding to the function call nodes to obtain the OID of the function includes: Determining the parameter types of the parent nodes of the auxiliary parsing nodes of the function call node from the linked list of auxiliary parsing nodes; wherein, the auxiliary parsing node includes: a first pointer of the current auxiliary parsing node, a second pointer of the parent node of the current auxiliary parsing node, the parameter type of the current auxiliary parsing node, and the parameter type confirmation method indication information of the current auxiliary parsing node, and the second pointer of each auxiliary parsing node points to the parent node of the auxiliary parsing node, forming a linked list of auxiliary parsing nodes; Determining the parameter types of the function call node according to the parameter types of the parent nodes; Determine a target mapping relationship from multiple mapping relationships between function names and OIDs according to the parameter type of the function call node; Parse the name of the function according to the target mapping relationship to obtain the OID of the function.
5. The method according to claim 4, wherein The determining the parameter type of the function call node according to the parameter type of the parent node includes: Determine the parent node of the auxiliary parsing node of the function call node from the linked list of auxiliary parsing nodes; Determine the parameter type of the parent node according to the auxiliary parsing node of the parent node; Determine the namespace of the function call node according to the parameter type of the parent node; Determine the parameter type of the function call node according to the namespace.
6. The method according to claim 1, characterized in that, The traversing each expression node of the syntax tree includes: When traversing each expression node, replace the pointer of the auxiliary parsing node in the semantic analysis context with the pointer of the auxiliary parsing node of the current expression node to process the current expression node; After processing the current expression node, restore the pointer of the auxiliary parsing node in the semantic analysis context to the pointer of the parent node of the auxiliary parsing node of the current expression node.
7. A statement parsing device for a database, characterized in that, The database supports processing data of at least two different parameter types, including: A parsing module for parsing a statement to be processed to obtain the syntax tree of the statement; A construction module for constructing a corresponding auxiliary parsing node for each expression node in the syntax tree; A processing module for traversing each expression node of the syntax tree to determine the function call nodes in the syntax tree; when the function called by the function call node includes call parameters, parse the name of the function to obtain the OID of the function according to the parameter type of the call parameters; when the function called by the function call node does not include call parameters, parse the name of the function to obtain the OID of the function according to the parameter type of the parent node of the auxiliary parsing node corresponding to the function call node.
8. An electronic device, characterized in that, including: A memory and a processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, causing the processor to execute the method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, Stores computer-executable instructions, and when the computer-executable instructions are executed, the method according to any one of claims 1-6 is implemented.
10. A computer program product, characterized in that, Includes a computer program, and when the computer program is executed, the method according to any one of claims 1-6 is implemented.